Skip to content

Commit

Permalink
vm: fix compile warnings on linux
Browse files Browse the repository at this point in the history
In function ‘readlink’,
    inlined from ‘vm_executable_path’ at vm/os-linux.cpp:13:27:
/usr/include/x86_64-linux-gnu/bits/unistd.h:68:10: warning: ‘__readlink_alias’ specified size 18446744073709551614 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   68 |   return __glibc_fortify (readlink, __len, sizeof (char),
      |          ^
/usr/include/x86_64-linux-gnu/bits/unistd-decl.h: In function ‘vm_executable_path’:
/usr/include/x86_64-linux-gnu/bits/unistd-decl.h:71:16: note: in a call to function ‘__readlink_alias’ declared with attribute ‘access (write_only, 2, 3)’
   71 | extern ssize_t __REDIRECT_NTH (__readlink_alias,
      |                ^
  • Loading branch information
mrjbq7 committed May 23, 2024
1 parent c418745 commit 135ea5f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vm/os-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace factor {

const char* vm_executable_path() {
ssize_t bufsiz = 4096;
size_t bufsiz = 4096;

// readlink is called in a loop with increasing buffer sizes in case
// someone tries to run Factor from a incredibly deeply nested
// path.
while (true) {
char* buf = new char[bufsiz + 1];
ssize_t size= readlink("/proc/self/exe", buf, bufsiz);
ssize_t size = readlink("/proc/self/exe", buf, bufsiz);
if (size < 0) {
fatal_error("Cannot read /proc/self/exe", errno);
} else {
if (size < bufsiz) {
if (size < ((size_t) bufsiz)) {
// Buffer was large enough, return string.
buf[size] = '\0';
const char* ret = safe_strdup(buf);
Expand Down

0 comments on commit 135ea5f

Please sign in to comment.