Unidata / netcdf-cxx4

Official GitHub repository for netCDF-C++ libraries and utilities.
Other
125 stars 49 forks source link

NcException: changed member variables to std::string* #1

Closed jarlela closed 10 years ago

jarlela commented 10 years ago

These changes to the NcException class will address two issues: 1: Member function what() returned a const char* to a locally declared string variable. The returned pointer was a dangeling pointer as the string variable will be destructed when the function returns. 2: Construction of string variables can throw exceptions. Using strings as membervariables in NcException could result in the constructor throwing in certain cases.

To avoid the possibility of the NcException constructor throwing, the member variables have been changed to a single string. If an exception is thrown in the construction of the message string it will be caught in the NcException constructor and not propagate further. This will also resolve the first issue as the what() function now returns a const char to a non local string.

Note: I used 'nullptr' in the code which is C++11. If the code should not use C++11 'nullptr' should be replaced by 'NULL'

russrew commented 10 years ago

Thanks, Jarle. I just merged your first pull request, except that I changed "nullptr" keyword to NULL for compilers not up to C++11, as you noted.