move to __builtin_add_overflow

This commit is contained in:
vms 2019-05-05 20:59:48 +04:00 committed by Dan Gohman
parent ccfe4bda30
commit 30e5a1fd1f

View File

@ -58,10 +58,9 @@ void *mmap(void *addr, size_t length, int prot, int flags,
return MAP_FAILED; return MAP_FAILED;
} }
const size_t buf_len = sizeof(struct map) + length;
// Check for integer overflow. // Check for integer overflow.
if(buf_len < length) { size_t buf_len = 0;
if(__builtin_add_overflow(length, sizeof(struct map), &buf_len)) {
errno = EINVAL; errno = EINVAL;
return MAP_FAILED; return MAP_FAILED;
} }