Fixes potential bug in neighborsearching.
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Mon, 22 Sep 2014 11:05:20 +0000 (13:05 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 23 Sep 2014 13:49:59 +0000 (15:49 +0200)
From put_in_list we first call new_i_nblist, then add some
j particles and then close_i_nblist

In new_i_nblist the number of i particles is typically
increased by one, that is nblist->nri is increased.

However, in case that there are no j particles, the nri
is not decreased again, which can lead to reading garbage
data from e.g. nblist->jjindex. In addition there is a
left-over variable (len) that computes the number of
j particles added, but this value is not used.

Change-Id: I38601a6865f6a4d879bec55246deded40943afb7

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--;
+        }
     }
 }