]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
string: Choose a more sensible error code when we run out of space
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 6 Jan 2025 21:18:51 +0000 (21:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 6 Jan 2025 21:18:51 +0000 (21:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/string.c
tests/libpakfire/string.c

index 19fe4aa85bf3bc5fcc0bf53bee6c792d2b83aa32..9b75effbd4f4b4213e2247310d53f4f95dc05289 100644 (file)
@@ -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;
index 75de6882d9e457101b9ae5d55f1dbe56e25ae90e..bfe4f6acf73d94a7603c53d700fe6ce9da215b26 100644 (file)
@@ -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;