]> PatchyGit - patchyircd.git/commitdiff
remove dumb null termination from append_strn
authorEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 08:10:05 +0000 (11:10 +0300)
committerEgor <egor@patchysicp.xyz>
Tue, 3 May 2022 08:10:05 +0000 (11:10 +0300)
literal buffer overrun

util.c

diff --git a/util.c b/util.c
index 73e84c1..df9b878 100644 (file)
--- a/util.c
+++ b/util.c
@@ -6,15 +6,12 @@ void append_strn(struct dynarr *d, const char *s, int len){
        if (d->len + len > d->cap){
                while (d->len + len > d->cap)
                        d->cap *= 2;
-               void* ndata=realloc(d->buf, d->cap);
-               if(!ndata)abort();
+               void *ndata = realloc(d->buf, d->cap);
+               if(!ndata) abort();
                d->buf = ndata;
        }
        memcpy(d->buf + d->len, s, len);
        d->len += len;
-       // Null
-       d->buf[d->len] = 0;
-       d->buf[d->cap] = 0;
 }
 void append_str(struct dynarr *d, const char *s){
        append_strn(d, s, strlen(s));