From 3acec9446e43553cb549e0775a5f4e235c7b783c Mon Sep 17 00:00:00 2001 From: David van der Spoel Date: Mon, 22 Sep 2014 13:05:20 +0200 Subject: [PATCH] Fixes potential bug in neighborsearching. 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gromacs/mdlib/ns.c b/src/gromacs/mdlib/ns.c index 496f605300..430e26d304 100644 --- a/src/gromacs/mdlib/ns.c +++ b/src/gromacs/mdlib/ns.c @@ -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--; + } } } -- 2.22.0