Fix undefined behavior flagged by UBSAN
[alexxy/gromacs.git] / src / gromacs / mdrun / minimize.cpp
index c67ff09cc27e580a5f39da5d5f009f9b4bc64143..c96ef39acd12aa0c80e94a612e5d1b26d77fc633 100644 (file)
@@ -389,7 +389,9 @@ static void init_em(FILE*                fplog,
     {
         state_global->ngtc = 0;
     }
-    initialize_lambdas(fplog, *ir, MASTER(cr), &(state_global->fep_state), state_global->lambda, nullptr);
+    int*                fep_state = MASTER(cr) ? &state_global->fep_state : nullptr;
+    gmx::ArrayRef<real> lambda    = MASTER(cr) ? state_global->lambda : gmx::ArrayRef<real>();
+    initialize_lambdas(fplog, *ir, MASTER(cr), fep_state, lambda, nullptr);
 
     if (ir->eI == eiNM)
     {
@@ -2543,7 +2545,7 @@ void LegacySimulator::do_steep()
         }
 
         /* Send IMD energies and positions, if bIMD is TRUE. */
-        if (imdSession->run(count, TRUE, state_global->box,
+        if (imdSession->run(count, TRUE, MASTER(cr) ? state_global->box : nullptr,
                             MASTER(cr) ? state_global->x.rvec_array() : nullptr, 0)
             && MASTER(cr))
         {