The contents of the string returned by getenv() is not guaranteed across calls to getenv(). The code to handle the CC_PRINT etc env vars calls getenv() and saves the results in just a char *. The string returned by getenv() needs to be copied and saved. Switching the type of the strings from char * to std::string will do this and manage the alloated memory.
Details
Details
Diff Detail
Diff Detail
Event Timeline
| clang/include/clang/Driver/Driver.h | ||
|---|---|---|
| 160 | I'm seeing code left unchanged like: TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");Assigning to a std::string from a null char * is known to cause things like Segmentation fault | |
| clang/lib/Driver/Compilation.cpp | ||
| 173–174 | Please update for the clang-format suggestions. | |
Comment Actions
Changed the code checking the env vars so it doesn't assign a null_ptr to the string.
| clang/include/clang/Driver/Driver.h | ||
|---|---|---|
| 160 | I've fixed in newest patch. | |
Comment Actions
LGTM; thanks.
| clang/lib/Driver/Driver.cpp | ||
|---|---|---|
| 4042 | Just noting that this means having the environment variable set (but empty) will now "work" instead of generating an error. | |
I'm seeing code left unchanged like:
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");Assigning to a std::string from a null char * is known to cause things like