Fix unitlized memory read in checkpoint
authorRoland Schulz <roland@utk.edu>
Tue, 27 Jan 2015 07:04:39 +0000 (02:04 -0500)
committerRoland Schulz <roland@utk.edu>
Tue, 27 Jan 2015 07:11:40 +0000 (02:11 -0500)
Older versions didn't prefix the version string
with VERSION and thus the scanf isn't returning
two fields for those.

Change-Id: I0c8734bd18a62ca5fd6841f2c57fa5a9698bc88c

src/gromacs/gmxlib/checkpoint.cpp

index 438eafba7df1a448ca468cc11332e7a8b9d062f9..f53a55d2ae49a1ea664c5ac1ef88c1ca6e114cfb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2008,2009,2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2008,2009,2010,2011,2012,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.
@@ -1759,8 +1759,9 @@ static void check_match(FILE *fplog,
         int   gmx_major, gmx_minor;
         int   cpt_major, cpt_minor;
         sscanf(gmx_version(), "VERSION %5d.%5d", &gmx_major, &gmx_minor);
-        sscanf(version, "VERSION %5d.%5d", &cpt_major, &cpt_minor);
-        version_differs = (gmx_major != cpt_major || gmx_minor != cpt_minor);
+        int   ret = sscanf(version, "VERSION %5d.%5d", &cpt_major, &cpt_minor);
+        version_differs = (ret < 2 || gmx_major != cpt_major ||
+                           gmx_minor != cpt_minor);
     }
 
     check_string(fplog, "Build time", BUILD_TIME, btime, &mm);