From: Emil Velikov Date: Sun, 2 Aug 2026 12:26:13 +0000 (+0100) Subject: Use DECLARE_STRBUF where possible X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89a6a4bd54a466f55180e16baeaa19b613fb50b0;p=thirdparty%2Fkmod.git Use DECLARE_STRBUF where possible _cleanup_strbuf_ + strbuf_init() can be replaced by DECLARE_STRBUF. Make all call-sites to use the respective macro. The one place still calling strbuf_init() in strbuf_to_vector() is "documenting" that strbuf is invalidated after its data is stolen, so keep it as is for now. Signed-off-by: Emil Velikov Signed-off-by: Lucas De Marchi Link: https://github.com/kmod-project/kmod/pull/451 Signed-off-by: Lucas De Marchi --- diff --git a/shared/strbuf.h b/shared/strbuf.h index 20ed7a2..9b886d6 100644 --- a/shared/strbuf.h +++ b/shared/strbuf.h @@ -83,8 +83,7 @@ void strbuf_popchar(struct strbuf *buf); * * Example: * - * struct strbuf buf; - * strbuf_init(&buf); + * DECLARE_STRBUF(buf); * strbuf_pushchars(&buf, "foobar"); * strbuf_popchars(&buf, 5); * diff --git a/testsuite/test-shared.c b/testsuite/test-shared.c index b45162d..d7e78a2 100644 --- a/testsuite/test-shared.c +++ b/testsuite/test-shared.c @@ -475,12 +475,10 @@ static const char *TEXT = static int test_strbuf_pushchar(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); const char *result; const char *c; - strbuf_init(&buf); - for (c = TEXT; *c != '\0'; c++) strbuf_pushchar(&buf, *c); @@ -494,13 +492,12 @@ DEFINE_TEST(test_strbuf_pushchar, .description = "test strbuf_{pushchar, str, st static int test_strbuf_pushchars(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); const char *result; char *saveptr = NULL, *str; const char *c; size_t lastwordlen = 0; - strbuf_init(&buf); str = strdup(TEXT); for (c = strtok_r(str, " ", &saveptr); c != NULL; c = strtok_r(NULL, " ", &saveptr)) { @@ -589,9 +586,8 @@ DEFINE_TEST(test_strbuf_with_heap, .description = "test strbuf with heap only"); static int test_strbuf_pushmem(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); - strbuf_init(&buf); strbuf_pushmem(&buf, "", 0); strbuf_pushmem(&buf, TEXT, strlen(TEXT) + 1); @@ -603,9 +599,8 @@ DEFINE_TEST(test_strbuf_pushmem, .description = "test strbuf_reserve"); static int test_strbuf_used(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); - strbuf_init(&buf); TS_ASSERT(strbuf_used(&buf) == 0); strbuf_pushchars(&buf, TEXT); @@ -652,9 +647,8 @@ DEFINE_TEST(test_strbuf_reserve_extra, .description = "test strbuf_reserve_extra static int test_strbuf_shrink_to(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); - strbuf_init(&buf); strbuf_shrink_to(&buf, 0); TS_ASSERT(strbuf_used(&buf) == 0); @@ -668,9 +662,8 @@ DEFINE_TEST(test_strbuf_shrink_to, .description = "test strbuf_shrink_to"); static int xfail_strbuf_shrink_to(void) { - _cleanup_strbuf_ struct strbuf buf; + DECLARE_STRBUF(buf); - strbuf_init(&buf); strbuf_pushchar(&buf, '/'); /* This should crash on assert */