Skip to content

Commit

Permalink
Check null pointer for getenv (#147)
Browse files Browse the repository at this point in the history
In `configRead`, a string was assigned from the return value of `getenv`:

```
string install_dir;
install_dir.assign(getenv("NEKRS_HOME"));
```

However, if `NEKRS_HOME` isn't defined, `getenv` will return a null pointer, and `string::assign` will segfault.  This update will avoid that issue with an error message.
  • Loading branch information
RonRahaman authored Sep 11, 2020
1 parent 179477e commit 108a57c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core/configReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ void configRead(MPI_Comm comm)
{
int rank;
MPI_Comm_rank(comm, &rank);

string install_dir;
install_dir.assign(getenv("NEKRS_HOME"));

char* nekrs_home = getenv("NEKRS_HOME");
if (nekrs_home == nullptr) {
if (rank == 0) {
cout << "\nERROR: The environment variable NEKRS_HOME could not be found!\n";
}
ABORT(1);
}
string install_dir{nekrs_home};
string configFile = install_dir + "/nekrs.conf";

const char* ptr = realpath(configFile.c_str(), NULL);
Expand Down

0 comments on commit 108a57c

Please sign in to comment.