about summary refs log tree commit diff
path: root/include/alloc-inl.h
diff options
context:
space:
mode:
authorhexcoder- <heiko@hexco.de>2020-03-28 11:01:29 +0100
committerhexcoder- <heiko@hexco.de>2020-03-28 11:01:29 +0100
commit7a92bf974d716da8ccc9b7f89b4e18a909c849ad (patch)
tree4aa5ad41a2669abf31c6aea6190fa4d1548ff419 /include/alloc-inl.h
parentfc46e9c9a0fb36fa7baeed9957f2c72a1318ec1e (diff)
downloadafl++-7a92bf974d716da8ccc9b7f89b4e18a909c849ad.tar.gz
alloc-inl.h/ck_maybe_grow() back to size_t, reimplement overflow check
Diffstat (limited to 'include/alloc-inl.h')
-rw-r--r--include/alloc-inl.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/include/alloc-inl.h b/include/alloc-inl.h
index ae908162..11c1143a 100644
--- a/include/alloc-inl.h
+++ b/include/alloc-inl.h
@@ -771,10 +771,10 @@ static inline void TRK_ck_free(void *ptr, const char *file, const char *func,
  It will realloc *buf otherwise.
  *size will grow exponentially as per:
  https://blog.mozilla.org/nnethercote/2014/11/04/please-grow-your-buffers-exponentially/
- Will FATAL if size_needed is <1 or *size is negative.
+ Will FATAL if size_needed is <1.
  @return For convenience, this function returns *buf.
  */
-static inline void *ck_maybe_grow(void **buf, ssize_t *size,
+static inline void *ck_maybe_grow(void **buf, size_t *size,
                                   size_t size_needed) {
 
   /* Oops. found a bug? */
@@ -782,14 +782,14 @@ static inline void *ck_maybe_grow(void **buf, ssize_t *size,
 
   /* No need to realloc */
   if (likely(*size >= size_needed)) return *buf;
-  if (unlikely(*size < 0)) FATAL("Negative size detected!");
-  /* No inital size was set */
+
+  /* No initial size was set */
   if (*size == 0) *size = INITIAL_GROWTH_SIZE;
   while (*size < size_needed) {
 
-    *size *= 2;
     /* in case of overflow we'll realloc to size_needed */
-    if ((*size) < 0) *size = size_needed;
+    if (2*(*size) < size_needed) *size = size_needed;
+    else *size *= 2;
 
   }