← Commit list

879209fc88

Daniel Stenberg
Daniel Stenberg
2026-04-11
SUCCESS Duration: 248s

Subject

unit1398: add msnprintf tests with negative precision

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

tests/unit/unit1398.c+25 -0
@@ -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");