From: David van der Spoel Date: Wed, 2 Jul 2014 14:12:38 +0000 (+0200) Subject: Fixed inconsistency in blocka handling. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=c6f80ffdbb1e9e0007d9f211d5a39cafdb802742;p=alexxy%2Fgromacs.git Fixed inconsistency in blocka handling. In some cases the inconsistent handling of blocka structure throughout the gromacs code could lead to reading uninitialized variables (src->a[nra]). This is fixed here. Change-Id: I514072e713c11f5ad7c15dbd702468789d3d53d3 --- diff --git a/src/gromacs/topology/block.cpp b/src/gromacs/topology/block.cpp index 2785465a0e..52fd431ac8 100644 --- a/src/gromacs/topology/block.cpp +++ b/src/gromacs/topology/block.cpp @@ -34,6 +34,7 @@ * To help us fund GROMACS development, we humbly ask that you cite * the research papers on the package. Check out http://www.gromacs.org. */ +#include #include "gromacs/topology/block.h" #include "gromacs/utility/smalloc.h" @@ -131,16 +132,21 @@ void stupid_fill_blocka(t_blocka *grp, int natom) void copy_blocka(const t_blocka *src, t_blocka *dest) { dest->nr = src->nr; - dest->nalloc_index = dest->nr + 1; + /* Workaround for inconsistent handling of nalloc_index in + * other parts of the code. Often nalloc_index and nalloc_a + * are not set. + */ + dest->nalloc_index = std::max(src->nalloc_index, dest->nr + 1); snew(dest->index, dest->nalloc_index); for (int i = 0; i < dest->nr+1; ++i) { dest->index[i] = src->index[i]; } dest->nra = src->nra; - dest->nalloc_a = dest->nra + 1; + /* See above. */ + dest->nalloc_a = std::max(src->nalloc_a, dest->nra); snew(dest->a, dest->nalloc_a); - for (int i = 0; i < dest->nra+1; ++i) + for (int i = 0; i < dest->nra; ++i) { dest->a[i] = src->a[i]; }