diff --git a/src/procmap.cpp b/src/procmap.cpp index 9d1ed83e73..8207b61f4c 100644 --- a/src/procmap.cpp +++ b/src/procmap.cpp @@ -301,7 +301,8 @@ void ProcMap::custom_grid(char *cfile, int nprocs, MPI_Bcast(&n,1,MPI_INT,0,world); MPI_Bcast(line,n,MPI_CHAR,0,world); - sscanf(line,"%d %d %d",&procgrid[0],&procgrid[1],&procgrid[2]); + int rv = sscanf(line,"%d %d %d",&procgrid[0],&procgrid[1],&procgrid[2]); + if (rv != 3) error->all(FLERR,"Processors custom grid file is inconsistent"); int flag = 0; if (procgrid[0]*procgrid[1]*procgrid[2] != nprocs) flag = 1; @@ -320,8 +321,10 @@ void ProcMap::custom_grid(char *cfile, int nprocs, for (int i = 0; i < nprocs; i++) { if (!fgets(line,MAXLINE,fp)) error->one(FLERR,"Unexpected end of custom file"); - sscanf(line,"%d %d %d %d", - &cmap[i][0],&cmap[i][1],&cmap[i][2],&cmap[i][3]); + rv = sscanf(line,"%d %d %d %d", + &cmap[i][0],&cmap[i][1],&cmap[i][2],&cmap[i][3]); + if (rv != 4) + error->one(FLERR,"Processors custom grid file is inconsistent"); } fclose(fp); } diff --git a/src/universe.cpp b/src/universe.cpp index f078590103..dba31f8b76 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -114,19 +114,19 @@ void Universe::reorder(char *style, char *arg) // read nprocs lines // uni2orig = inverse mapping - int me_orig,me_new; - sscanf(line,"%d %d",&me_orig,&me_new); + int me_orig,me_new,rv; + rv = sscanf(line,"%d %d",&me_orig,&me_new); if (me_orig < 0 || me_orig >= nprocs || - me_new < 0 || me_new >= nprocs) + me_new < 0 || me_new >= nprocs || rv != 2) error->one(FLERR,"Invalid entry in -reorder file"); uni2orig[me_new] = me_orig; for (int i = 1; i < nprocs; i++) { if (!fgets(line,MAXLINE,fp)) error->one(FLERR,"Unexpected end of -reorder file"); - sscanf(line,"%d %d",&me_orig,&me_new); + rv = sscanf(line,"%d %d",&me_orig,&me_new); if (me_orig < 0 || me_orig >= nprocs || - me_new < 0 || me_new >= nprocs) + me_new < 0 || me_new >= nprocs || rv != 2) error->one(FLERR,"Invalid entry in -reorder file"); uni2orig[me_new] = me_orig; } diff --git a/src/variable.cpp b/src/variable.cpp index ea7f3044d7..63a425bcf5 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5162,8 +5162,8 @@ int VarReader::read_peratom() for (i = 0; i < nchunk; i++) { next = strchr(buf,'\n'); *next = '\0'; - sscanf(buf,TAGINT_FORMAT " %lg",&tag,&value); - if (tag <= 0 || tag > map_tag_max) + int rv = sscanf(buf,TAGINT_FORMAT " %lg",&tag,&value); + if (tag <= 0 || tag > map_tag_max || rv != 2) error->one(FLERR,"Invalid atom ID in variable file"); if ((m = atom->map(tag)) >= 0) vstore[m] = value; buf = next + 1;