Salome HOME
spns #33658: in case environment variable does not exist, getenv returns nullptr... spns/33658 V9_11_0a1 V9_11_0a2 3/head
authorNabil Ghodbane <nabil.ghodbane@cea.fr>
Thu, 4 May 2023 14:45:45 +0000 (16:45 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Tue, 9 May 2023 12:03:24 +0000 (14:03 +0200)
Test rewrite parameter first, then check if environment variable is nullptr, and finally check if environment variable exists but is empty

Useful for setting MeshGems license

src/Basics/Basics_Utils.cxx

index 1725a319c6ec28a3607c3ccb799d034e77acc087..63fe64c6976c0aad57cea59c8e38980e29acbed1 100644 (file)
@@ -175,7 +175,7 @@ namespace Kernel_Utils
   {
     std::stringstream sstr;
     sstr<<name<<'='<<value;
-    if(rewrite || std::string(getenv(name)).length() == 0)
+    if(rewrite || getenv(name) == nullptr || std::string(getenv(name)).length() == 0)
       return _putenv(sstr.str().c_str());
     else return -1;
   }