Protect from getenv("HOME") returning nullptr (#907) (#908)

* Protect from getenv("HOME") returning nullptr (e.g., in case running in systemd)

* Write proper warning in Module.cpp

Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
This commit is contained in:
2024-02-07 10:27:03 +01:00
committed by GitHub
parent d17bc5da62
commit f6b0ba9703
2 changed files with 8 additions and 1 deletions

View File

@ -20,6 +20,7 @@ Still this is better than strcpy and a buffer overflow...
*/
template <size_t array_size>
void strcpy_safe(char (&destination)[array_size], const char *source) {
assert(source != nullptr);
assert(array_size > strlen(source));
strncpy(destination, source, array_size - 1);
destination[array_size - 1] = '\0';