wgtmac commented on code in PR #1882:
URL: https://github.com/apache/orc/pull/1882#discussion_r1559522442


##########
c++/src/Timezone.cc:
##########
@@ -656,12 +656,21 @@ namespace orc {
     epoch_ = utcEpoch - getVariant(utcEpoch).gmtOffset;
   }
 
-  const char* getTimezoneDirectory() {
+  std::string getTimezoneDirectory() {
     const char* dir = getenv("TZDIR");
     if (!dir) {
-      dir = DEFAULT_TZDIR;
+      // this is present if we're in an activated conda environment
+      const char* condaPrefix = getenv("CONDA_PREFIX");
+      if (condaPrefix) {
+        std::string condaDir(condaPrefix);
+        condaDir += "/share/zoneinfo";
+        return condaDir;
+      } else {
+        dir = DEFAULT_TZDIR;
+      }
     }
-    return dir;
+    std::string tzDir(dir);
+    return tzDir;

Review Comment:
   ```suggestion
       return dir;
   ```
   This is enough



##########
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:
   Could we simply use `std::string tzDirBackup = tzDir;` In this way, we don't 
need to free it in the end.



-- 
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