From: Matthias Kruk Date: Tue, 31 Dec 2019 05:05:47 +0000 (+0900) Subject: Fix %% and %c conversion specifications in snprintf() format strings X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=4e5e01b944427a532a216a2d20e4826595ef32dd;p=corax Fix %% and %c conversion specifications in snprintf() format strings --- diff --git a/kernel/klibc/stdio.c b/kernel/klibc/stdio.c index 74c2b3d..f8e596a 100644 --- a/kernel/klibc/stdio.c +++ b/kernel/klibc/stdio.c @@ -396,7 +396,7 @@ int snprintf(char *str, size_t size, const char *format, ...) } while(0) #define OUTPUT(_c) do { \ if(offset < size) { \ - str[offset++] = c; \ + str[offset++] = (_c); \ } else { \ goto gtfo; \ } \ @@ -527,6 +527,7 @@ int snprintf(char *str, size_t size, const char *format, ...) #if FEATURE(SNPRINTF_CONV_BIN) case 'b': #endif /* FEATURE(SNPRINTF_CONV_BIN) */ + case '%': /* parse again in STATE_CONV */ SET_STATE(STATE_CONV); break; @@ -585,6 +586,7 @@ int snprintf(char *str, size_t size, const char *format, ...) #if FEATURE(SNPRINTF_CONV_BIN) case 'b': #endif /* FEATURE(SNPRINTF_CONV_BIN) */ + case '%': SET_STATE(STATE_CONV); break; @@ -637,6 +639,7 @@ int snprintf(char *str, size_t size, const char *format, ...) #if FEATURE(SNPRINTF_CONV_BIN) case 'b': #endif /* FEATURE(SNPRINTF_CONV_BIN) */ + case '%': SET_STATE(STATE_CONV); break; @@ -676,6 +679,7 @@ int snprintf(char *str, size_t size, const char *format, ...) #if FEATURE(SNPRINTF_CONV_BIN) case 'b': #endif /* FEATURE(SNPRINTF_CONV_BIN) */ + case '%': SET_STATE(STATE_CONV); break;