From c83ce183f0a9ccab4dd3d9f6c8157aa222c55261 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 12 Nov 2024 09:07:05 -0600 Subject: [PATCH] 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 --- shared/strbuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; } -- 2.47.2