Merge pull request #434 from andreas-volz/master

fix a undefined behaviour for std::string and nullptr access
This commit is contained in:
Tim Felgentreff 2023-03-01 20:08:53 +01:00 committed by GitHub
commit 4c23bcd825
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -202,7 +202,11 @@ static void SetUserDataPath(char* data_path) {
} }
strcat(data_path, "\\Stratagus\\"); strcat(data_path, "\\Stratagus\\");
#else #else
std::string appimage = std::string(getenv("APPIMAGE")); char *appimage_ptr = getenv("APPIMAGE");
std::string appimage;
if (appimage_ptr != nullptr) {
appimage = std::string(appimage_ptr);
}
if (!appimage.empty() && fs::exists(fs::path(appimage))) { if (!appimage.empty() && fs::exists(fs::path(appimage))) {
if (fs::exists(fs::path(appimage + ".data"))) { if (fs::exists(fs::path(appimage + ".data"))) {
strcpy(data_path, (appimage + ".data/stratagus").c_str()); strcpy(data_path, (appimage + ".data/stratagus").c_str());