adamreeve commented on code in PR #49148:
URL: https://github.com/apache/arrow/pull/49148#discussion_r2779812348


##########
cpp/src/arrow/util/io_util.cc:
##########
@@ -1762,38 +1763,54 @@ Result<std::string> GetEnvVar(std::string_view name) {
 #ifdef _WIN32
   // On Windows, getenv() reads an early copy of the process' environment
   // which doesn't get updated when SetEnvironmentVariable() is called.
-  constexpr int32_t bufsize = 2000;
-  char c_str[bufsize];
-  auto res = GetEnvironmentVariableA(name.data(), c_str, bufsize);
-  if (res >= bufsize) {
-    return Status::CapacityError("environment variable value too long");
-  } else if (res == 0) {
-    return Status::KeyError("environment variable '", name, "'undefined");
-  }
-  return std::string(c_str);
+  std::string value(100, '\0');
+
+  uint32_t res = GetEnvironmentVariableA(name.data(), value.data(),
+                                         static_cast<uint32_t>(value.size()));
+  if (res >= value.size()) {

Review Comment:
   This `>=` comparison was a bit confusing to me at first but this is fine as 
the `==` case should never happen.



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