unit1398: add msnprintf tests with negative precision

Closes #21292
This commit is contained in:
Daniel Stenberg 2026-04-11 11:04:41 +02:00
parent 3e40ccb875
commit 879209fc88
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -40,6 +40,31 @@ static CURLcode test_unit1398(const char *arg)
/* #define curl_msnprintf snprintf */
/* negative precision is treated as if omitted */
rc = curl_msnprintf(output, sizeof(output), "%.*s", -1, str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
rc = curl_msnprintf(output, sizeof(output), "%.*s", -1, "0123456789");
fail_unless(rc == 10, "return code should be 10");
fail_unless(!strcmp(output, "0123456789"), "wrong output");
rc = curl_msnprintf(output, sizeof(output), "%.*s", 0, "0123456789");
fail_unless(rc == 0, "return code should be 0");
fail_unless(!strcmp(output, ""), "wrong output");
rc = curl_msnprintf(output, sizeof(output), "%.*s", -2, str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
rc = curl_msnprintf(output, sizeof(output), "%.*d", -3, 10000);
fail_unless(rc == 5, "return code should be 5");
fail_unless(!strcmp(output, "10000"), "wrong output");
rc = curl_msnprintf(output, sizeof(output), "%.*d", 0, 1234567);
fail_unless(rc == 7, "return code should be 0");
fail_unless(!strcmp(output, "1234567"), "wrong output");
/* without a trailing zero */
rc = curl_msnprintf(output, 4, "%.*s", width, buf);
fail_unless(rc == 3, "return code should be 3");