Test and fix malloc_printf("%%").
This commit is contained in:
parent
0dec3507c6
commit
0c4e743eaf
13
src/util.c
13
src/util.c
@ -400,11 +400,6 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
unsigned char len = '?';
|
unsigned char len = '?';
|
||||||
|
|
||||||
f++;
|
f++;
|
||||||
if (*f == '%') {
|
|
||||||
/* %% */
|
|
||||||
APPEND_C(*f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
@ -495,6 +490,11 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
switch (*f) {
|
switch (*f) {
|
||||||
char *s;
|
char *s;
|
||||||
size_t slen;
|
size_t slen;
|
||||||
|
case '%':
|
||||||
|
/* %% */
|
||||||
|
APPEND_C(*f);
|
||||||
|
f++;
|
||||||
|
break;
|
||||||
case 'd': case 'i': {
|
case 'd': case 'i': {
|
||||||
intmax_t val JEMALLOC_CC_SILENCE_INIT(0);
|
intmax_t val JEMALLOC_CC_SILENCE_INIT(0);
|
||||||
char buf[D2S_BUFSIZE];
|
char buf[D2S_BUFSIZE];
|
||||||
@ -561,8 +561,7 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
|||||||
APPEND_PADDED_S(s, slen, width, left_justify);
|
APPEND_PADDED_S(s, slen, width, left_justify);
|
||||||
f++;
|
f++;
|
||||||
break;
|
break;
|
||||||
}
|
} default: not_reached();
|
||||||
default: not_reached();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} default: {
|
} default: {
|
||||||
|
@ -181,6 +181,8 @@ TEST_BEGIN(test_malloc_snprintf)
|
|||||||
|
|
||||||
TEST("hello", "hello");
|
TEST("hello", "hello");
|
||||||
|
|
||||||
|
TEST("50%, 100%", "50%%, %d%%", 100);
|
||||||
|
|
||||||
TEST("a0123b", "a%sb", "0123");
|
TEST("a0123b", "a%sb", "0123");
|
||||||
|
|
||||||
TEST("a 0123b", "a%5sb", "0123");
|
TEST("a 0123b", "a%5sb", "0123");
|
||||||
|
Loading…
Reference in New Issue
Block a user