Skip to content

Commit 6baf6cd

Browse files
Fix vfprintf and derived functions badly handling +/` flag conflict (#1269)
1 parent 06a1193 commit 6baf6cd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

libc/stdio/fmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
#define FLAGS_PRECISION 0x20
7777
#define FLAGS_ISSIGNED 0x40
7878
#define FLAGS_NOQUOTE 0x80
79+
#define FLAGS_REPR 0x100
7980
#define FLAGS_QUOTE FLAGS_SPACE
8081
#define FLAGS_GROUPING FLAGS_NOQUOTE
81-
#define FLAGS_REPR FLAGS_PLUS
8282

8383
#define __FMT_PUT(C) \
8484
do { \

test/libc/stdio/snprintf_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ TEST(snprintf, testVeryLargePrecision) {
2727
ASSERT_EQ(i, 9999);
2828
ASSERT_EQ(strlen(buf), 511);
2929
}
30+
31+
TEST(snprintf, testPlusFlagOnChar) {
32+
char buf[10] = {};
33+
int i = snprintf(buf, sizeof(buf), "%+c", '=');
34+
35+
ASSERT_EQ(i, 1);
36+
ASSERT_STREQ(buf, "=");
37+
}

0 commit comments

Comments
 (0)