[flang-commits] [flang] 18734f6 - [flang] Fix a warning

Kazu Hirata via flang-commits flang-commits at lists.llvm.org
Thu Jan 11 11:23:15 PST 2024


Author: Kazu Hirata
Date: 2024-01-11T11:23:08-08:00
New Revision: 18734f606635f4f4270f911b68060890ce3dd94a

URL: https://github.com/llvm/llvm-project/commit/18734f606635f4f4270f911b68060890ce3dd94a
DIFF: https://github.com/llvm/llvm-project/commit/18734f606635f4f4270f911b68060890ce3dd94a.diff

LOG: [flang] Fix a warning

This patch fixes:

  flang/runtime/extensions.cpp:111:12: error: variable length arrays
  are a C99 feature [-Werror,-Wvla-extension]

Added: 
    

Modified: 
    flang/runtime/extensions.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
index f72acf83a4409f..352da8f11d9d56 100644
--- a/flang/runtime/extensions.cpp
+++ b/flang/runtime/extensions.cpp
@@ -108,12 +108,13 @@ void FORTRAN_PROCEDURE_NAME(getlog)(std::byte *arg, std::int64_t length) {
   if (nameMaxLen == -1)
     nameMaxLen = _POSIX_LOGIN_NAME_MAX + 1;
 #endif
-  char str[nameMaxLen];
+  std::vector<char> str(nameMaxLen);
 
-  int error{getlogin_r(str, nameMaxLen)};
+  int error{getlogin_r(str.data(), nameMaxLen)};
   if (error == 0) {
     // no error: find first \0 in string then pad from there
-    CopyAndPad(reinterpret_cast<char *>(arg), str, length, std::strlen(str));
+    CopyAndPad(reinterpret_cast<char *>(arg), str.data(), length,
+        std::strlen(str.data()));
   } else {
     // error occur: get username from environment variable
     GetUsernameEnvVar("LOGNAME", arg, length);


        


More information about the flang-commits mailing list