Fixes potential bug in neighborsearching.
[alexxy/gromacs.git] / src / gromacs / mdlib / ns.c
index 496f605300962ce27da0b3a89047a353ffdd4de3..430e26d304780b5b3f828efdad076163127cff1d 100644 (file)
@@ -430,6 +430,14 @@ static gmx_inline void close_i_nblist(t_nblist *nlist)
         nlist->jindex[nri+1] = nlist->nrj;
 
         len = nlist->nrj -  nlist->jindex[nri];
+        /* If there are no j-particles we have to reduce the
+         * number of i-particles again, to prevent errors in the
+         * kernel functions.
+         */
+        if ((len == 0) && (nlist->nri > 0))
+        {
+            nlist->nri--;
+        }
     }
 }