diff options
author | Jason Evans <je@fb.com> | 2014-01-22 17:00:27 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2014-01-22 17:00:27 (GMT) |
commit | 0c4e743eaf2ab6bcfd56e002fb82f95801b9292e (patch) | |
tree | 0f4ead2f0a836d8af7d8ed76d6a91c6e220b8c24 | |
parent | 0dec3507c62efac909e204217bf9b6c8c59d10ac (diff) | |
download | jemalloc-0c4e743eaf2ab6bcfd56e002fb82f95801b9292e.zip jemalloc-0c4e743eaf2ab6bcfd56e002fb82f95801b9292e.tar.gz jemalloc-0c4e743eaf2ab6bcfd56e002fb82f95801b9292e.tar.bz2 |
Test and fix malloc_printf("%%").
-rw-r--r-- | src/util.c | 13 | ||||
-rw-r--r-- | test/unit/util.c | 2 |
2 files changed, 8 insertions, 7 deletions
@@ -400,11 +400,6 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) unsigned char len = '?'; f++; - if (*f == '%') { - /* %% */ - APPEND_C(*f); - break; - } /* Flags. */ while (true) { switch (*f) { @@ -495,6 +490,11 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap) switch (*f) { char *s; size_t slen; + case '%': + /* %% */ + APPEND_C(*f); + f++; + break; case 'd': case 'i': { intmax_t val JEMALLOC_CC_SILENCE_INIT(0); 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); f++; break; - } - default: not_reached(); + } default: not_reached(); } break; } default: { diff --git a/test/unit/util.c b/test/unit/util.c index 4b4d19d..dc3cfe8 100644 --- a/test/unit/util.c +++ b/test/unit/util.c @@ -181,6 +181,8 @@ TEST_BEGIN(test_malloc_snprintf) TEST("hello", "hello"); + TEST("50%, 100%", "50%%, %d%%", 100); + TEST("a0123b", "a%sb", "0123"); TEST("a 0123b", "a%5sb", "0123"); |