Fix conf_handle_char_p zero-sized dest and remove unused conf_handle_unsigned

This commit is contained in:
Slobodan Predolac 2026-03-27 12:27:00 -07:00
parent 3ac9f96158
commit b507644cb0
3 changed files with 27 additions and 93 deletions

View file

@ -25,50 +25,6 @@ TEST_BEGIN(test_conf_handle_bool_invalid) {
}
TEST_END
TEST_BEGIN(test_conf_handle_unsigned_in_range) {
uintmax_t result = 0;
bool err = conf_handle_unsigned(
"100", sizeof("100") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed for in-range value");
expect_u64_eq((uint64_t)result, 100, "result should be 100");
}
TEST_END
TEST_BEGIN(test_conf_handle_unsigned_clip_max) {
uintmax_t result = 0;
bool err = conf_handle_unsigned(
"9999", sizeof("9999") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed with clipping");
expect_u64_eq(
(uint64_t)result, 2048, "result should be clipped to max 2048");
}
TEST_END
TEST_BEGIN(test_conf_handle_unsigned_clip_min) {
uintmax_t result = 0;
bool err = conf_handle_unsigned(
"0", sizeof("0") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed with clipping");
expect_u64_eq((uint64_t)result, 1, "result should be clipped to min 1");
}
TEST_END
TEST_BEGIN(test_conf_handle_unsigned_no_clip_reject) {
uintmax_t result = 0;
bool err = conf_handle_unsigned(
"9999", sizeof("9999") - 1, 1, 2048, true, true, false, &result);
expect_true(err, "Should fail for out-of-range value without clip");
}
TEST_END
TEST_BEGIN(test_conf_handle_unsigned_invalid) {
uintmax_t result = 0;
bool err = conf_handle_unsigned(
"abc", sizeof("abc") - 1, 1, 2048, true, true, true, &result);
expect_true(err, "Should fail for non-numeric input");
}
TEST_END
TEST_BEGIN(test_conf_handle_signed_valid) {
intmax_t result = 0;
bool err = conf_handle_signed("5000", sizeof("5000") - 1, -1,
@ -113,14 +69,21 @@ TEST_BEGIN(test_conf_handle_char_p) {
}
TEST_END
TEST_BEGIN(test_conf_handle_char_p_zero_dest_sz) {
char buf[4] = {'X', 'Y', 'Z', '\0'};
bool err;
err = conf_handle_char_p("abc", sizeof("abc") - 1, buf, 0);
expect_false(err, "Should succeed for zero-sized destination");
expect_c_eq(buf[0], 'X', "Zero-sized destination must not be modified");
}
TEST_END
int
main(void) {
return test(test_conf_handle_bool_true, test_conf_handle_bool_false,
test_conf_handle_bool_invalid, test_conf_handle_unsigned_in_range,
test_conf_handle_unsigned_clip_max,
test_conf_handle_unsigned_clip_min,
test_conf_handle_unsigned_no_clip_reject,
test_conf_handle_unsigned_invalid, test_conf_handle_signed_valid,
test_conf_handle_bool_invalid, test_conf_handle_signed_valid,
test_conf_handle_signed_negative,
test_conf_handle_signed_out_of_range, test_conf_handle_char_p);
test_conf_handle_signed_out_of_range, test_conf_handle_char_p,
test_conf_handle_char_p_zero_dest_sz);
}