From 239b0faa4c18ddfbc2678cb97c18adb16636684f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 2 Nov 2017 10:00:28 +0000 Subject: [PATCH] Replaced getenv calls with safer osg::getEnvVar usage --- src/osg/DisplaySettings.cpp | 216 ++++++++++++++---------------------- src/osg/GLExtensions.cpp | 14 ++- 2 files changed, 95 insertions(+), 135 deletions(-) diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 9c1f3c75b..c63e66715 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -391,222 +392,182 @@ static ApplicationUsageProxy DisplaySetting_e33(ApplicationUsage::ENVIRONMENTAL_ void DisplaySettings::readEnvironmentalVariables() { - const char* ptr = 0; - - if ((ptr = getenv("OSG_DISPLAY_TYPE")) != 0) + std::string value; + if (getEnvVar("OSG_DISPLAY_TYPE", value)) { - if (strcmp(ptr,"MONITOR")==0) + if (value=="MONITOR") { _displayType = MONITOR; } else - if (strcmp(ptr,"POWERWALL")==0) + if (value=="POWERWALL") { _displayType = POWERWALL; } else - if (strcmp(ptr,"REALITY_CENTER")==0) + if (value=="REALITY_CENTER") { _displayType = REALITY_CENTER; } else - if (strcmp(ptr,"HEAD_MOUNTED_DISPLAY")==0) + if (value=="HEAD_MOUNTED_DISPLAY") { _displayType = HEAD_MOUNTED_DISPLAY; } } - if( (ptr = getenv("OSG_STEREO_MODE")) != 0) + if (getEnvVar("OSG_STEREO_MODE", value)) { - if (strcmp(ptr,"QUAD_BUFFER")==0) + if (value=="QUAD_BUFFER") { _stereoMode = QUAD_BUFFER; } - else if (strcmp(ptr,"ANAGLYPHIC")==0) + else if (value=="ANAGLYPHIC") { _stereoMode = ANAGLYPHIC; } - else if (strcmp(ptr,"HORIZONTAL_SPLIT")==0) + else if (value=="HORIZONTAL_SPLIT") { _stereoMode = HORIZONTAL_SPLIT; } - else if (strcmp(ptr,"VERTICAL_SPLIT")==0) + else if (value=="VERTICAL_SPLIT") { _stereoMode = VERTICAL_SPLIT; } - else if (strcmp(ptr,"LEFT_EYE")==0) + else if (value=="LEFT_EYE") { _stereoMode = LEFT_EYE; } - else if (strcmp(ptr,"RIGHT_EYE")==0) + else if (value=="RIGHT_EYE") { _stereoMode = RIGHT_EYE; } - else if (strcmp(ptr,"HORIZONTAL_INTERLACE")==0) + else if (value=="HORIZONTAL_INTERLACE") { _stereoMode = HORIZONTAL_INTERLACE; } - else if (strcmp(ptr,"VERTICAL_INTERLACE")==0) + else if (value=="VERTICAL_INTERLACE") { _stereoMode = VERTICAL_INTERLACE; } - else if (strcmp(ptr,"CHECKERBOARD")==0) + else if (value=="CHECKERBOARD") { _stereoMode = CHECKERBOARD; } } - if( (ptr = getenv("OSG_STEREO")) != 0) + if (getEnvVar("OSG_STEREO", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _stereo = false; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _stereo = true; } } - if( (ptr = getenv("OSG_EYE_SEPARATION")) != 0) - { - _eyeSeparation = osg::asciiToFloat(ptr); - } + getEnvVar("OSG_EYE_SEPARATION", _eyeSeparation); + getEnvVar("OSG_SCREEN_WIDTH", _screenWidth); + getEnvVar("OSG_SCREEN_HEIGHT", _screenHeight); + getEnvVar("OSG_SCREEN_DISTANCE", _screenDistance); - if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0) + if (getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING", value)) { - _screenWidth = osg::asciiToFloat(ptr); - } - - if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0) - { - _screenHeight = osg::asciiToFloat(ptr); - } - - if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0) - { - _screenDistance = osg::asciiToFloat(ptr); - } - - if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0) - { - if (strcmp(ptr,"LEFT_EYE_LEFT_VIEWPORT")==0) + if (value=="LEFT_EYE_LEFT_VIEWPORT") { _splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT; } else - if (strcmp(ptr,"LEFT_EYE_RIGHT_VIEWPORT")==0) + if (value=="LEFT_EYE_RIGHT_VIEWPORT") { _splitStereoHorizontalEyeMapping = LEFT_EYE_RIGHT_VIEWPORT; } } - if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION")) != 0) - { - _splitStereoHorizontalSeparation = atoi(ptr); - } + getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION", _splitStereoHorizontalSeparation); - if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING")) != 0) + if (getEnvVar("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING", value)) { - if (strcmp(ptr,"LEFT_EYE_TOP_VIEWPORT")==0) + if (value=="LEFT_EYE_TOP_VIEWPORT") { _splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT; } else - if (strcmp(ptr,"LEFT_EYE_BOTTOM_VIEWPORT")==0) + if (value=="LEFT_EYE_BOTTOM_VIEWPORT") { _splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT; } } - if( (ptr = getenv("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO")) != 0) + if (getEnvVar("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _splitStereoAutoAdjustAspectRatio = false; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _splitStereoAutoAdjustAspectRatio = true; } } - if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_SEPARATION")) != 0) - { - _splitStereoVerticalSeparation = atoi(ptr); - } + getEnvVar("OSG_SPLIT_STEREO_VERTICAL_SEPARATION", _splitStereoVerticalSeparation); - if( (ptr = getenv("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS")) != 0) - { - _maxNumOfGraphicsContexts = atoi(ptr); - } + getEnvVar("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS", _maxNumOfGraphicsContexts); - if( (ptr = getenv("OSG_COMPILE_CONTEXTS")) != 0) + if (getEnvVar("OSG_COMPILE_CONTEXTS", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _compileContextsHint = false; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _compileContextsHint = true; } } - if( (ptr = getenv("OSG_SERIALIZE_DRAW_DISPATCH")) != 0) + if (getEnvVar("OSG_SERIALIZE_DRAW_DISPATCH", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _serializeDrawDispatch = false; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _serializeDrawDispatch = true; } } - if( (ptr = getenv("OSG_USE_SCENEVIEW_FOR_STEREO")) != 0) + if (getEnvVar("OSG_USE_SCENEVIEW_FOR_STEREO", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _useSceneViewForStereoHint = false; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _useSceneViewForStereoHint = true; } } - if( (ptr = getenv("OSG_NUM_DATABASE_THREADS")) != 0) - { - _numDatabaseThreadsHint = atoi(ptr); - } + getEnvVar("OSG_NUM_DATABASE_THREADS", _numDatabaseThreadsHint); - if( (ptr = getenv("OSG_NUM_HTTP_DATABASE_THREADS")) != 0) - { - _numHttpDatabaseThreadsHint = atoi(ptr); - } + getEnvVar("OSG_NUM_HTTP_DATABASE_THREADS", _numHttpDatabaseThreadsHint); - if( (ptr = getenv("OSG_MULTI_SAMPLES")) != 0) - { - _numMultiSamples = atoi(ptr); - } + getEnvVar("OSG_MULTI_SAMPLES", _numMultiSamples); - if( (ptr = getenv("OSG_TEXTURE_POOL_SIZE")) != 0) - { - _maxTexturePoolSize = atoi(ptr); - } + getEnvVar("OSG_TEXTURE_POOL_SIZE", _maxTexturePoolSize); - if( (ptr = getenv("OSG_BUFFER_OBJECT_POOL_SIZE")) != 0) - { - _maxBufferObjectPoolSize = atoi(ptr); - } + getEnvVar("OSG_BUFFER_OBJECT_POOL_SIZE", _maxBufferObjectPoolSize); { // Read implicit buffer attachments combinations for both render and resolve mask @@ -642,71 +603,65 @@ void DisplaySettings::readEnvironmentalVariables() } } - if( (ptr = getenv("OSG_GL_VERSION")) != 0 || (ptr = getenv("OSG_GL_CONTEXT_VERSION")) != 0) + if (getEnvVar("OSG_GL_VERSION", value) || getEnvVar("OSG_GL_CONTEXT_VERSION", value)) { - _glContextVersion = ptr; + _glContextVersion = value; } - if( (ptr = getenv("OSG_GL_CONTEXT_FLAGS")) != 0) - { - _glContextFlags = atoi(ptr); - } + getEnvVar("OSG_GL_CONTEXT_FLAGS", _glContextFlags); - if( (ptr = getenv("OSG_GL_CONTEXT_PROFILE_MASK")) != 0) - { - _glContextProfileMask = atoi(ptr); - } + getEnvVar("OSG_GL_CONTEXT_PROFILE_MASK", _glContextProfileMask); - if ((ptr = getenv("OSG_SWAP_METHOD")) != 0) + if (getEnvVar("OSG_SWAP_METHOD", value)) { - if (strcmp(ptr,"DEFAULT")==0) + if (value=="DEFAULT") { _swapMethod = SWAP_DEFAULT; } else - if (strcmp(ptr,"EXCHANGE")==0) + if (value=="EXCHANGE") { _swapMethod = SWAP_EXCHANGE; } else - if (strcmp(ptr,"COPY")==0) + if (value=="COPY") { _swapMethod = SWAP_COPY; } else - if (strcmp(ptr,"UNDEFINED")==0) + if (value=="UNDEFINED") { _swapMethod = SWAP_UNDEFINED; } } - if ((ptr = getenv("OSG_SYNC_SWAP_BUFFERS")) != 0) + if (getEnvVar("OSG_SYNC_SWAP_BUFFERS", value)) { - if (strcmp(ptr,"OFF")==0) + if (value=="OFF") { _syncSwapBuffers = 0; } else - if (strcmp(ptr,"ON")==0) + if (value=="ON") { _syncSwapBuffers = 1; } else { - _syncSwapBuffers = atoi(ptr); + _syncSwapBuffers = atoi(value.c_str()); } } - if ((ptr = getenv("OSG_VERTEX_BUFFER_HINT")) != 0) + if (getEnvVar("OSG_VERTEX_BUFFER_HINT", value)) { - if (strcmp(ptr,"VERTEX_BUFFER_OBJECT")==0 || strcmp(ptr,"VBO")==0) + if (value=="VERTEX_BUFFER_OBJECT" || value=="VBO") { OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<= 1.2f); isTextureStorageEnabled = validContext && ((glVersion >= 4.2f) || isGLExtensionSupported(contextID, "GL_ARB_texture_storage")); - if ( (ptr = getenv("OSG_GL_TEXTURE_STORAGE")) != 0 && isTextureStorageEnabled) - { - if (strcmp(ptr,"OFF")==0 || strcmp(ptr,"DISABLE")==0 ) isTextureStorageEnabled = false; - else isTextureStorageEnabled = true; - } + if (isTextureStorageEnabled) + { + std::string value; + if (getEnvVar("OSG_GL_TEXTURE_STORAGE", value)) + { + if (value=="OFF" || value=="DISABLE") isTextureStorageEnabled = false; + else isTextureStorageEnabled = true; + } + } // Texture3D extensions isTexture3DFast = validContext && (OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D"));