Skip to content

Commit

Permalink
[flang] Fix a warning
Browse files Browse the repository at this point in the history
This patch fixes:

  flang/runtime/extensions.cpp:111:12: error: variable length arrays
  are a C99 feature [-Werror,-Wvla-extension]
  • Loading branch information
kazutakahirata committed Jan 11, 2024
1 parent 0cc3157 commit 18734f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flang/runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

2 comments on commit 18734f6

@DavidSpickett
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted this due to a failure on our bots: 4210eb1

@DavidSpickett
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing so broke more bots than it fixed, so I've relanded it but please look into the linker issue.

Please sign in to comment.