make Input::file(const char *) function safe for passing a null pointer
This commit is contained in:
@ -327,15 +327,14 @@ void Input::file(const char *filename)
|
|||||||
// call to file() will close filename and decrement nfile
|
// call to file() will close filename and decrement nfile
|
||||||
|
|
||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
if (nfile == maxfile)
|
if (nfile == maxfile) error->one(FLERR,"Too many nested levels of input scripts");
|
||||||
error->one(FLERR,"Too many nested levels of input scripts");
|
|
||||||
|
|
||||||
infile = fopen(filename,"r");
|
if (filename) {
|
||||||
if (infile == nullptr)
|
infile = fopen(filename,"r");
|
||||||
error->one(FLERR,"Cannot open input script {}: {}",
|
if (infile == nullptr)
|
||||||
filename, utils::getsyserror());
|
error->one(FLERR,"Cannot open input script {}: {}", filename, utils::getsyserror());
|
||||||
|
infiles[nfile++] = infile;
|
||||||
infiles[nfile++] = infile;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process contents of file
|
// process contents of file
|
||||||
@ -343,9 +342,11 @@ void Input::file(const char *filename)
|
|||||||
file();
|
file();
|
||||||
|
|
||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
fclose(infile);
|
if (filename) {
|
||||||
nfile--;
|
fclose(infile);
|
||||||
infile = infiles[nfile-1];
|
nfile--;
|
||||||
|
infile = infiles[nfile-1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -532,8 +532,7 @@ void lammps_file(void *handle, const char *filename)
|
|||||||
BEGIN_CAPTURE
|
BEGIN_CAPTURE
|
||||||
{
|
{
|
||||||
if (lmp->update->whichflag != 0)
|
if (lmp->update->whichflag != 0)
|
||||||
lmp->error->all(FLERR,"Library error: issuing LAMMPS commands "
|
lmp->error->all(FLERR, "Library error: issuing LAMMPS commands during a run is not allowed");
|
||||||
"during a run is not allowed.");
|
|
||||||
else
|
else
|
||||||
lmp->input->file(filename);
|
lmp->input->file(filename);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user