h-vetinari commented on code in PR #1882:
URL: https://github.com/apache/orc/pull/1882#discussion_r1560372138


##########
c++/test/TestTimezone.cc:
##########
@@ -420,9 +421,21 @@ namespace orc {
 #endif
   }
 
+  char* deepcopy(const char* name) {
+    // this allocates a new buffer that must be freed after use
+#ifdef _MSC_VER
+    return _strdup(name);
+#else
+    return strdup(name);
+#endif
+  }
+
   TEST(TestTimezone, testMissingTZDB) {
-    const char* tzDirBackup = std::getenv("TZDIR");
-    if (tzDirBackup != nullptr) {
+    const char* tzDir = std::getenv("TZDIR");
+    char* tzDirBackup = nullptr;
+    if (tzDir != nullptr) {
+      // avoid that unsetting environment variable wrecks pointer to tzDir
+      tzDirBackup = deepcopy(tzDir);

Review Comment:
   Sorry for the newbie mistakes; I had checked that `std::string` can be 
initialized with `nullptr` (even though I now get that it's against the 
design), but not that it cannot be compared. 😅 
   
   Anyway, using `s.empty()` 
[works](https://en.cppreference.com/w/cpp/string/basic_string/empty) even 
without an explicit initialization of `std::string`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to