From a21bde5cca1f940e75269336985ddd127b488e9f Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 10 Feb 2025 17:10:54 +0000 Subject: [PATCH] tests: string: Fail with a clear error code on invalid input Signed-off-by: Michael Tremer --- src/pakfire/string.c | 2 +- tests/libpakfire/string.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pakfire/string.c b/src/pakfire/string.c index 4bca3ee8..09aa6037 100644 --- a/src/pakfire/string.c +++ b/src/pakfire/string.c @@ -657,7 +657,7 @@ int __pakfire_format_time(char* buffer, const size_t length, const time_t t) { // Values smaller than zero for t are invalid if (t < 0) - return 1; + return -EINVAL; if (t >= 86400) format = "%dd%Hh%Mm"; diff --git a/tests/libpakfire/string.c b/tests/libpakfire/string.c index 706c0b4a..f569833f 100644 --- a/tests/libpakfire/string.c +++ b/tests/libpakfire/string.c @@ -307,8 +307,7 @@ static int test_format_time(const struct test* t) { char buffer[128]; // Values smaller than zero - ASSERT_SUCCESS(pakfire_format_time(buffer, -1)); - ASSERT_STRING_EQUALS(buffer, NULL); + ASSERT_ERROR(pakfire_format_time(buffer, -1), EINVAL); // Values greater than a day ASSERT_SUCCESS(pakfire_format_time(buffer, 86400)); -- 2.39.5