diff options
author | hexcoder- <heiko@hexco.de> | 2020-03-28 13:06:05 +0100 |
---|---|---|
committer | hexcoder- <heiko@hexco.de> | 2020-03-28 13:06:05 +0100 |
commit | 23b3e3c84d3350790b5095a4bb6e1b7c39f28eea (patch) | |
tree | b0985cafaafc01cca73cb25ec78768f59238ddc2 /include/alloc-inl.h | |
parent | 8b8600fdabb20c344063ead1b0ff2d105e0365be (diff) | |
parent | 1938a122226bdecfed8420d21eeb2b240bff1b6a (diff) | |
download | afl++-23b3e3c84d3350790b5095a4bb6e1b7c39f28eea.tar.gz |
Merge branch 'dev' of https://github.com/AFLplusplus/AFLplusplus into dev
Diffstat (limited to 'include/alloc-inl.h')
-rw-r--r-- | include/alloc-inl.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/include/alloc-inl.h b/include/alloc-inl.h index b8c83db4..4211e398 100644 --- a/include/alloc-inl.h +++ b/include/alloc-inl.h @@ -767,11 +767,13 @@ static inline void TRK_ck_free(void *ptr, const char *file, const char *func, #endif /* _WANT_ORIGINAL_AFL_ALLOC */ -/* This function calculates the lowest power of 2 greater or equal its argument. +/* This function calculates the next power of 2 greater or equal its argument. @return The rounded up power of 2 (if no overflow) or 0 on overflow. */ -static inline size_t powerOf2Ceil(size_t in) { - if (in == 0 || in > (size_t)-1) return 0; /* avoid undefined behaviour under-/overflow */ +static inline size_t next_pow2(size_t in) { + + if (in == 0 || in > (size_t)-1) + return 0; /* avoid undefined behaviour under-/overflow */ size_t out = in - 1; out |= out >> 1; out |= out >> 2; @@ -779,6 +781,7 @@ static inline size_t powerOf2Ceil(size_t in) { out |= out >> 8; out |= out >> 16; return out + 1; + } /* This function makes sure *size is > size_needed after call. @@ -801,12 +804,10 @@ static inline void *ck_maybe_grow(void **buf, size_t *size, if (size_needed < INITIAL_GROWTH_SIZE) size_needed = INITIAL_GROWTH_SIZE; /* grow exponentially */ - size_t next_size = powerOf2Ceil(size_needed); + size_t next_size = next_pow2(size_needed); /* handle overflow */ - if (!next_size) { - next_size = size_needed; - } + if (!next_size) { next_size = size_needed; } /* alloc */ *buf = ck_realloc(*buf, next_size); |