]> git.proxmox.com Git - wasi-libc.git/commitdiff
Fix `find_relpath` to handle large buffers correctly.
authorDan Gohman <dev@sunfishcode.online>
Tue, 10 May 2022 01:16:05 +0000 (18:16 -0700)
committerDan Gohman <dev@sunfishcode.online>
Tue, 10 May 2022 01:54:07 +0000 (18:54 -0700)
As a follow-up to #247, fix `find_relpath` to handle large buffers
correctly.

Co-Authored-by: Yuta Saito <kateinoigakukun@gmail.com>
libc-bottom-half/sources/posix.c

index b1696bbf5080f49809bb99c2032367a3762b970e..35dd99b309b09e0a4ba835283419ce588f31e76c 100644 (file)
@@ -31,16 +31,20 @@ static int find_relpath2(
 static int find_relpath(const char *path, char **relative) {
     static __thread char *relative_buf = NULL;
     static __thread size_t relative_buf_len = 0;
+    int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
+    // find_relpath2 can update relative_buf, so assign it after the call
     *relative = relative_buf;
-    return find_relpath2(path, relative, &relative_buf_len);
+    return fd;
 }
 
 // same as `find_relpath`, but uses another set of static variables to cache
 static int find_relpath_alt(const char *path, char **relative) {
     static __thread char *relative_buf = NULL;
     static __thread size_t relative_buf_len = 0;
+    int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
+    // find_relpath2 can update relative_buf, so assign it after the call
     *relative = relative_buf;
-    return find_relpath2(path, relative, &relative_buf_len);
+    return fd;
 }
 
 int open(const char *path, int oflag, ...) {