]> git.proxmox.com Git - wasi-libc.git/commitdiff
code deduplication
authorvms <michail.vms@gmail.com>
Sun, 5 May 2019 08:17:37 +0000 (12:17 +0400)
committerDan Gohman <sunfish@mozilla.com>
Mon, 6 May 2019 16:46:36 +0000 (09:46 -0700)
libc-bottom-half/mman/mman.c

index 4d7fa77be38e3d0ac5459e9d7a01e62f2eae347f..e0b1021c59cda269474e2910c8dc0c28a5bdbc95 100644 (file)
@@ -58,14 +58,16 @@ void *mmap(void *addr, size_t length, int prot, int flags,
         return MAP_FAILED;
     }
 
+    const size_t buf_len = sizeof(struct map) + length;
+
     // Check for integer overflow.
-    if(sizeof(struct map) + length < sizeof(struct map)) {
+    if(buf_len < length) {
         errno = EINVAL;
         return MAP_FAILED;
     }
 
     // Allocate the memory.
-    struct map *map = malloc(sizeof(struct map) + length);
+    struct map *map = malloc(buf_len);
     if (!map) {
         errno = ENOMEM;
         return MAP_FAILED;