From ce69f18ec7478dba6e1bec25739c7445593eb194 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 2 Nov 2017 10:43:41 +0000 Subject: [PATCH] Replaced getenv usage with safer osg::getEnvVar --- src/osg/ApplicationUsage.cpp | 15 +++++++++++---- src/osg/CullSettings.cpp | 17 +++++++---------- src/osg/DisplaySettings.cpp | 36 ++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/osg/ApplicationUsage.cpp b/src/osg/ApplicationUsage.cpp index ad2404089..26e4510ec 100644 --- a/src/osg/ApplicationUsage.cpp +++ b/src/osg/ApplicationUsage.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -317,10 +318,16 @@ void ApplicationUsage::writeEnvironmentSettings(std::ostream& output) std::string::size_type len = citr->first.find_first_of("\n\r\t "); if (len == std::string::npos) len = citr->first.size(); line.replace(optionPos,len,citr->first.substr(0,len)); - const char *cp = getenv(citr->first.substr(0, len).c_str()); - if (!cp) cp = "[not set]"; - else if (!*cp) cp = "[set]"; - line += std::string(cp) + "\n"; + + std::string value; + if (getEnvVar(citr->first.substr(0, len).c_str(), value)) + { + line += "[set]\n"; + } + else + { + line += "[not set]\n"; + } output << line; } diff --git a/src/osg/CullSettings.cpp b/src/osg/CullSettings.cpp index 370191787..78122bbb5 100644 --- a/src/osg/CullSettings.cpp +++ b/src/osg/CullSettings.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -97,25 +98,21 @@ void CullSettings::readEnvironmentalVariables() { OSG_INFO<<"CullSettings::readEnvironmentalVariables()"< lock(_valueMapMutex); @@ -1122,12 +1122,12 @@ bool DisplaySettings::getValue(const std::string& name, std::string& value, bool return true; } - if (!use_getenv_fallback) return false; + if (!use_env_fallback) return false; - const char* str = getenv(name.c_str()); - if (str) + std::string str; + if (getEnvVar(name.c_str(), str)) { - OSG_INFO<<"DisplaySettings::getValue("<