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