checking return value of ?scanf() calls to detect problems parsing files

This commit is contained in:
Axel Kohlmeyer
2019-07-19 11:14:39 -04:00
parent 4c328bf846
commit 8526e7a4cd
7 changed files with 77 additions and 38 deletions

View File

@ -170,7 +170,7 @@ bigint ReaderXYZ::read_header(double /*box*/[3][3], int &boxinfo, int &/*triclin
void ReaderXYZ::read_atoms(int n, int nfield, double **fields)
{
int i,m;
int i,m,rv;
char *eof;
int mytype;
double myx, myy, myz;
@ -180,7 +180,9 @@ void ReaderXYZ::read_atoms(int n, int nfield, double **fields)
if (eof == NULL) error->one(FLERR,"Unexpected end of dump file");
++nid;
sscanf(line,"%*s%lg%lg%lg", &myx, &myy, &myz);
rv = sscanf(line,"%*s%lg%lg%lg", &myx, &myy, &myz);
if (rv != 3)
error->one("Dump file is incorrectly formatted");
// XXX: we could insert an element2type translation here
// XXX: for now we flag unrecognized types as type 0,