mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
parent
7f925e6be9
commit
999481ace0
2 changed files with 15 additions and 7 deletions
|
@ -30,6 +30,7 @@ struct SprintfStr {
|
|||
};
|
||||
|
||||
static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) {
|
||||
if (n) {
|
||||
if (n == 1 && t->i < t->n) {
|
||||
t->p[t->i] = s[0];
|
||||
} else if (t->i + n <= t->n) {
|
||||
|
@ -38,6 +39,7 @@ static int vsnprintfputchar(const char *s, struct SprintfStr *t, size_t n) {
|
|||
memcpy(t->p + t->i, s, t->n - t->i);
|
||||
}
|
||||
t->i += n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -628,6 +628,12 @@ TEST(sprintf, commas) {
|
|||
ASSERT_STREQ("123,456,789", buf);
|
||||
}
|
||||
|
||||
TEST(vsnprintf, issue785) {
|
||||
ASSERT_EQ(0, snprintf(0, 0, "%s", ""));
|
||||
ASSERT_EQ(1, snprintf(0, 0, "%s", " "));
|
||||
ASSERT_EQ(2, snprintf(0, 0, "%s", " "));
|
||||
}
|
||||
|
||||
BENCH(palandprintf, bench) {
|
||||
EZBENCH2("ascii", donothing, Format(VEIL("r", "hiuhcreohucreo")));
|
||||
EZBENCH2("ascii %s", donothing, Format("%s", VEIL("r", "hiuhcreohucreo")));
|
||||
|
|
Loading…
Add table
Reference in a new issue