Unverified Commit e72aef2a authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

more sscanf() return value checking

parent d730ef5b
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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",
      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);
  }
+5 −5
Original line number Diff line number Diff line
@@ -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;
      }
+2 −2
Original line number Diff line number Diff line
@@ -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;