Merge release-4-5-patches into release-4-6
[alexxy/gromacs.git] / src / gmxlib / index.c
index 35dd32358001c67797019885a1783fb1883a87fe..91df2be5dc0199042da716ccc307e0c066a80e89 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <assert.h>
 #include "sysstuff.h"
 #include "strdb.h"
 #include "futil.h"
@@ -725,7 +726,7 @@ gmx_residuetype_get_name(gmx_residuetype_t rt, int index)
 
 void analyse(t_atoms *atoms,t_blocka *gb,char ***gn,gmx_bool bASK,gmx_bool bVerb)
 {
-    gmx_residuetype_t rt;
+    gmx_residuetype_t rt=NULL;
     char    *resnm;
     atom_id *aid;
     const char **  restype;
@@ -754,6 +755,7 @@ void analyse(t_atoms *atoms,t_blocka *gb,char ***gn,gmx_bool bASK,gmx_bool bVerb
 
     /* For every residue, get a pointer to the residue type name */
     gmx_residuetype_init(&rt);
+    assert(rt);
 
     snew(restype,atoms->nres);
     ntypes = 0;
@@ -921,8 +923,12 @@ t_blocka *init_index(const char *gfile, char ***grpname)
        b->index[b->nr]=b->index[b->nr-1];
        (*grpname)[b->nr-1]=strdup(str);
       } else {
+          if (b->nr==0)
+          {
+              gmx_fatal(FARGS,"The first header of your indexfile is invalid");
+          }
        pt=line;
-       while ((i=sscanf(pt,"%s",str)) == 1) {
+       while (sscanf(pt,"%s",str) == 1) {
          i=b->index[b->nr];
          if (i>=maxentries) {
            maxentries+=1024;