Avoid segmentation fault in gmx chi.
authorJustin Lemkul <jalemkul@vt.edu>
Fri, 14 Aug 2015 00:28:21 +0000 (20:28 -0400)
committerJustin Lemkul <jalemkul@vt.edu>
Fri, 14 Aug 2015 01:05:08 +0000 (21:05 -0400)
If a system containing a custom residue is being analyzed, gmx chi
would seg fault if that residue was not in residuetypes.dat. This
can occur, for instance, when the topology is created in some
directory and analysis in another, or if the analysis is done on
a different machine.

Fixes #1802

Change-Id: I85df855381c8e233020fd1e1f73165d4e1215ab9

src/gromacs/gmxana/dlist.c

index 11ee4eaea02e047789b1a88be26da662a4fa3cbc..32b3cb6482ee2123f97de8a93c788e8f3733840c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -224,6 +224,16 @@ t_dlist *mk_dlist(FILE *log,
             }
             dl[nl].index = gmx_residuetype_get_index(rt, thisres);
 
+            /* Prevent seg fault from unknown residues. If one adds a custom residue to
+             * residuetypes.dat but somehow loses it, changes it, or does analysis on
+             * another machine, the residue type will be unknown. */
+            if (dl[nl].index == -1)
+            {
+                gmx_fatal(FARGS, "Unknown residue %s when searching for residue type.\n"
+                          "Maybe you need to add a custom residue in residuetypes.dat.",
+                          thisres, __FILE__, __LINE__);
+            }
+
             sprintf(dl[nl].name, "%s%d", thisres, ires+r0);
             nl++;
         }