Skip to content

Commit

Permalink
Don't try to sanitize path if getenv returns null
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Mar 12, 2018
1 parent aeee185 commit 06e3c8a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/filesystem_boost.cpp
Expand Up @@ -1357,14 +1357,19 @@ std::string get_program_invocation(const std::string &program_name)
return (path(game_config::wesnoth_program_dir) / real_program_name).string();
}

std::string sanitize_path(const std::string& path) {
std::string sanitize_path(const std::string& path)
{
#ifdef _WIN32
const std::string user_name = getenv("USERNAME");
const char* user_name = getenv("USERNAME");
#else
const std::string user_name = getenv("USER");
const char* user_name = getenv("USER");
#endif

std::string canonicalized = filesystem::normalize_path(path, true, false);
boost::replace_all(canonicalized, user_name, "USER");
if(user_name != nullptr) {
boost::replace_all(canonicalized, user_name, "USER");
}

return canonicalized;
}

Expand Down

0 comments on commit 06e3c8a

Please sign in to comment.