Fix memory-usage error in g_chi
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Thu, 12 Jun 2014 07:58:11 +0000 (09:58 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 13 Jun 2014 15:48:52 +0000 (17:48 +0200)
Out of array bounds writing error as pointed out by valgrind
is fixed by this patch, preventing a SEGV.

Fixes #1503

Change-Id: I57959f4751f3eb645ff66bbcd4418607af56c1a4

src/tools/anadih.c

index 5f5da0eefba94486a9cf09ebfc4f653ca0e5e3bc..1c0e9000dd9a08a4cd0da1ffd5d56d0fd17b44d2 100644 (file)
@@ -417,7 +417,8 @@ void mk_chi_lookup (int **lookup, int maxchi, real **dih,
     int i, j, Dih, Chi;
 
     j = 0;
-    for (Dih = 0; (Dih < NONCHI+maxchi); Dih++)
+    /* NONCHI points to chi1, therefore we have to start counting there. */
+    for (Dih = NONCHI; (Dih < NONCHI+maxchi); Dih++)
     {
         for (i = 0; (i < nlist); i++)
         {