Skip to content

Commit 18734f6

Browse files
[flang] Fix a warning
This patch fixes: flang/runtime/extensions.cpp:111:12: error: variable length arrays are a C99 feature [-Werror,-Wvla-extension]
1 parent 0cc3157 commit 18734f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

flang/runtime/extensions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,13 @@ void FORTRAN_PROCEDURE_NAME(getlog)(std::byte *arg, std::int64_t length) {
108108
if (nameMaxLen == -1)
109109
nameMaxLen = _POSIX_LOGIN_NAME_MAX + 1;
110110
#endif
111-
char str[nameMaxLen];
111+
std::vector<char> str(nameMaxLen);
112112

113-
int error{getlogin_r(str, nameMaxLen)};
113+
int error{getlogin_r(str.data(), nameMaxLen)};
114114
if (error == 0) {
115115
// no error: find first \0 in string then pad from there
116-
CopyAndPad(reinterpret_cast<char *>(arg), str, length, std::strlen(str));
116+
CopyAndPad(reinterpret_cast<char *>(arg), str.data(), length,
117+
std::strlen(str.data()));
117118
} else {
118119
// error occur: get username from environment variable
119120
GetUsernameEnvVar("LOGNAME", arg, length);

0 commit comments

Comments
 (0)