xcb: Deal with case of getenv() returning NULL.
authorIan Elliott <ian@LunarG.com>
Fri, 20 Feb 2015 21:12:18 +0000 (14:12 -0700)
committerCourtney Goeltzenleuchter <courtney@LunarG.com>
Tue, 3 Mar 2015 00:21:09 +0000 (17:21 -0700)
At least on Windows, getenv() returns NULL when the environment variable is not
found.  This causes a problem inside of "xcb_nvidia.cpp" when a C++ std::string
is assigned the return value of getenv().

demos/xcb_nvidia.cpp

index 5ecd088..5a35d93 100644 (file)
@@ -37,11 +37,11 @@ std::deque<XcbId> g_xcbIds;
 
 xcb_connection_t * xcb_connect(const char *displayname, int *screenp)
 {
-    std::string xglNvidia = getenv(DRIVER_PATH_ENV);
+    std::string xglNvidia = (getenv(DRIVER_PATH_ENV) == NULL) ? "" : getenv(DRIVER_PATH_ENV);
     xglNvidia += "\\xgl_nvidia.dll";
     HMODULE module = LoadLibrary(xglNvidia.c_str());
     if (!module) {
-        std::string xglNulldrv = getenv("LIBXGL_DRIVERS_PATH");
+        std::string xglNulldrv = (getenv("XGL_DRIVERS_PATH") == NULL) ? "" : getenv("LIBXGL_DRIVERS_PATH");
         xglNulldrv += "\\xgl_nulldrv.dll";
         module = LoadLibrary(xglNulldrv.c_str());
     }