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
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]]);