Fix %c with nul character

Fixes #417
This commit is contained in:
Justine Tunney 2022-06-12 22:25:42 -07:00
parent 91953dd308
commit 3c285337a2
2 changed files with 19 additions and 6 deletions

View file

@ -283,6 +283,15 @@ TEST(fmt, quoted) {
ASSERT_STREQ("\"hello\" ", gc(xasprintf("%-`*.*s", 10, 5, "hello")));
}
TEST(fmt, nulCharacter) {
char b[3] = {1, 1, 1};
ASSERT_EQ(1, snprintf(0, 0, "%c", 0));
ASSERT_EQ(1, snprintf(b, 3, "%c", 0));
ASSERT_EQ(0, b[0]);
ASSERT_EQ(0, b[1]);
ASSERT_EQ(1, b[2]);
}
TEST(fmt, regress) {
char buf[512];
const char *meth = "GET";