]> git.proxmox.com Git - wasi-libc.git/commitdiff
use ENOMEM instead of EINVAL, set EINVAL if length == 0
authorvms <michail.vms@gmail.com>
Sun, 5 May 2019 20:53:18 +0000 (00:53 +0400)
committerDan Gohman <sunfish@mozilla.com>
Mon, 6 May 2019 16:46:36 +0000 (09:46 -0700)
libc-bottom-half/mman/mman.c

index 575a49578ce830358e7b9f9efc5491ae7ca61907..b358908f2fbd61f416443d284892fffa3ac21983 100644 (file)
@@ -58,10 +58,16 @@ void *mmap(void *addr, size_t length, int prot, int flags,
         return MAP_FAILED;
     }
 
+    //  To be consistent with POSIX.
+    if (length == 0) {
+        errno = EINVAL;
+        return MAP_FAILED;
+    }
+
     // Check for integer overflow.
     size_t buf_len = 0;
-    if(__builtin_add_overflow(length, sizeof(struct map), &buf_len)) {
-        errno = EINVAL;
+    if (__builtin_add_overflow(length, sizeof(struct map), &buf_len)) {
+        errno = ENOMEM;
         return MAP_FAILED;
     }