do not implicitly zero freshly allocated memory

Sun, 24 Apr 2022 17:29:34 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 24 Apr 2022 17:29:34 +0200
changeset 533
8d70ad8da899
parent 532
080c304ec176
child 534
0e893f84a7dd

do not implicitly zero freshly allocated memory

src/buffer.c file | annotate | diff | comparison | revisions
--- a/src/buffer.c	Sun Apr 24 17:14:05 2022 +0200
+++ b/src/buffer.c	Sun Apr 24 17:29:34 2022 +0200
@@ -47,7 +47,6 @@
         if (buffer->bytes == NULL) {
             return 1;
         }
-        memset(buffer->bytes, 0, capacity);
         buffer->flags |= CX_BUFFER_FREE_CONTENTS;
     } else {
         buffer->bytes = space;
@@ -122,14 +121,12 @@
 
     unsigned char *newspace = realloc(buffer->bytes, newcap);
     if (newspace) {
-        memset(newspace + buffer->size, 0, newcap - buffer->size);
         buffer->bytes = newspace;
         buffer->capacity = newcap;
+        return 0;
     } else {
         return -1;
     }
-
-    return 0;
 }
 
 size_t cxBufferWrite(

mercurial