fix cxBufferMinimumCapacity implementation still using additional_bytes

Sun, 24 Apr 2022 17:14:05 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 24 Apr 2022 17:14:05 +0200
changeset 532
080c304ec176
parent 531
1b8624c8448e
child 533
8d70ad8da899

fix cxBufferMinimumCapacity implementation still using additional_bytes

src/buffer.c file | annotate | diff | comparison | revisions
--- a/src/buffer.c	Sun Apr 24 16:23:44 2022 +0200
+++ b/src/buffer.c	Sun Apr 24 17:14:05 2022 +0200
@@ -114,13 +114,10 @@
 
 int cxBufferMinimumCapacity(
         CxBuffer *buffer,
-        size_t additional_bytes
+        size_t newcap
 ) {
-    size_t newcap = buffer->capacity + additional_bytes;
-
-    // overflow protection
-    if (newcap < buffer->capacity) {
-        return -1;
+    if (newcap <= buffer->capacity) {
+        return 0;
     }
 
     unsigned char *newspace = realloc(buffer->bytes, newcap);

mercurial