Added safety check for fitting group in anaeig.
authorJan Henning Peters <jpeters@gwdg.de>
Mon, 10 Feb 2014 17:53:32 +0000 (18:53 +0100)
committerCarsten Kutzner <ckutzne@gwdg.de>
Tue, 11 Feb 2014 09:11:01 +0000 (10:11 +0100)
Previously, g_anaeig would not check the number of atoms in the selected
fit group against the number of atoms in the reference structure if this
was read from the eigenvector file (g_covar adds the reference structure
to the eigenvector file if fit and analysis group are identitcal). As a
result, anaeig would run out of bounds when selecting the atoms for
fitting, reading random values from memory.

This simple check should prevent this behaviour by terminating anaeig
with a fatal error similar to the one that is invoked if the group
selected for analysis has an incorrect number of atoms.

Change-Id: I63a1e1629144e539808d95d867e0ad0673480fdf

src/tools/gmx_anaeig.c

index f5c37369827dcd482418e37409e398c7f14f3ea5..bda9de7c879867ac77c2a0a473af8430980d744b 100644 (file)
@@ -1277,6 +1277,11 @@ int gmx_anaeig(int argc, char *argv[])
             snew(xrefp, atoms->nr);
             if (xref1 != NULL)
             {
+                /* Safety check between selected fit-group and reference structure read from the eigenvector file */
+                if (natoms != nfit)
+                {
+                    gmx_fatal(FARGS, "you selected a group with %d elements instead of %d, your selection does not fit the reference structure in the eigenvector file.", nfit, natoms);
+                }
                 for (i = 0; (i < nfit); i++)
                 {
                     copy_rvec(xref1[i], xrefp[ifit[i]]);