mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:44:58 +00:00
AK: printf was not accounting for plus sign with "%+d"
We have to include the plus sign in the number of characters written, otherwise sprintf() will put the null terminator too early.
This commit is contained in:
parent
eed78ffa5a
commit
e9403e2b03
2 changed files with 15 additions and 1 deletions
|
@ -284,7 +284,7 @@ ALWAYS_INLINE int print_signed_number(PutChFunc putch, char*& bufptr, int number
|
|||
}
|
||||
if (always_sign)
|
||||
putch(bufptr, '+');
|
||||
return print_number(putch, bufptr, number, left_pad, zero_pad, field_width);
|
||||
return print_number(putch, bufptr, number, left_pad, zero_pad, field_width) + always_sign;
|
||||
}
|
||||
|
||||
struct ModifierState {
|
||||
|
|
|
@ -242,4 +242,18 @@ TEST_CASE(builder_zero_initial_capacity)
|
|||
EXPECT_EQ(built.length(), 0u);
|
||||
}
|
||||
|
||||
TEST_CASE(sprintf)
|
||||
{
|
||||
char buf1[128];
|
||||
int ret1 = sprintf(buf1, "%+d", 12);
|
||||
EXPECT_EQ(ret1, 3);
|
||||
|
||||
char buf2[128];
|
||||
int ret2 = sprintf(buf2, "%+d", -12);
|
||||
EXPECT_EQ(ret2, 3);
|
||||
|
||||
EXPECT_EQ(String(buf1), String("+12"));
|
||||
EXPECT_EQ(String(buf2), String("-12"));
|
||||
}
|
||||
|
||||
TEST_MAIN(String)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue