From: Michael Tremer Date: Mon, 6 Jan 2025 21:18:51 +0000 (+0000) Subject: string: Choose a more sensible error code when we run out of space X-Git-Tag: 0.9.30~514 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba1695d78745595f1576706b90f9fa38a181dfd9;p=pakfire.git string: Choose a more sensible error code when we run out of space Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/string.c b/src/pakfire/string.c index 19fe4aa85..9b75effbd 100644 --- a/src/pakfire/string.c +++ b/src/pakfire/string.c @@ -47,12 +47,11 @@ int __pakfire_string_vformat(char* s, const size_t length, const char* format, v // Catch any errors if (required < 0) - return -ENOBUFS; + return -errno; // Check if the entire string could be written - if ((size_t)required >= length) { - return -ENOMEM; - } + if ((size_t)required >= length) + return -ENOBUFS; // Success return 0; diff --git a/tests/libpakfire/string.c b/tests/libpakfire/string.c index 75de6882d..bfe4f6acf 100644 --- a/tests/libpakfire/string.c +++ b/tests/libpakfire/string.c @@ -35,7 +35,7 @@ static int test_string_set(const struct test* t) { ASSERT_STRING_EQUALS(buffer, "ABC"); // Write a string which would not fit - ASSERT(pakfire_string_set(buffer, "1234") == -ENOMEM); + ASSERT_ERROR(pakfire_string_set(buffer, "1234"), ENOBUFS); ASSERT_STRING_EQUALS(buffer, "123"); return EXIT_SUCCESS; @@ -250,7 +250,7 @@ static int test_format_size(const struct test* t) { ASSERT_SUCCESS(pakfire_format_size(buffer, 1024 * 1024) ); ASSERT_STRING_EQUALS(buffer, "1.0M"); - ASSERT(pakfire_format_size(small_buffer, 0) == -ENOMEM); + ASSERT_ERROR(pakfire_format_size(small_buffer, 0), ENOBUFS); return EXIT_SUCCESS;