From: Lucas De Marchi Date: Tue, 12 Nov 2024 15:07:05 +0000 (-0600) Subject: strbuf: Re-use buf_realloc() X-Git-Tag: v34~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c83ce183f0a9ccab4dd3d9f6c8157aa222c55261;p=thirdparty%2Fkmod.git strbuf: Re-use buf_realloc() Let the realloc happen in only one place, so we can change its behavior in future. Signed-off-by: Lucas De Marchi Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/239 --- diff --git a/shared/strbuf.c b/shared/strbuf.c index 290d1db3..e193d219 100644 --- a/shared/strbuf.c +++ b/shared/strbuf.c @@ -55,12 +55,14 @@ char *strbuf_steal(struct strbuf *buf) { char *bytes; - bytes = realloc(buf->bytes, buf->used + 1); - if (!bytes) { + if (!buf_realloc(buf, buf->used + 1)) { free(buf->bytes); return NULL; } + + bytes = buf->bytes; bytes[buf->used] = '\0'; + return bytes; }