From 03f24e132518a55c0d574569dac04119fb7daad2 Mon Sep 17 00:00:00 2001 From: Erik Hallberg Date: Wed, 5 Jun 2019 08:11:59 +0200 Subject: [PATCH 1/2] Do not assume char is always signed This is platform-dependent and having it wrong makes the PRId8 and PRIi8 macros print int8_t values as unsigned on some platforms. --- printf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/printf.c b/printf.c index 8a700add..f2357f45 100644 --- a/printf.c +++ b/printf.c @@ -732,7 +732,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } else { - const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); + const int value = (flags & FLAGS_CHAR) ? (signed char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } } From eb3bc6204b6b32fc5dd0e954a25f6ec7b51a9739 Mon Sep 17 00:00:00 2001 From: Erik Hallberg Date: Wed, 5 Jun 2019 17:31:41 +0200 Subject: [PATCH 2/2] Update the README.md table too --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9554ebfe..a8d3999e 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ The length sub-specifier modifies the length of the data type. | Length | d i | u o x X | |--------|------|---------| | (none) | int | unsigned int | -| hh | char | unsigned char | +| hh | signed char | unsigned char | | h | short int | unsigned short int | | l | long int | unsigned long int | | ll | long long int | unsigned long long int (if PRINTF_SUPPORT_LONG_LONG is defined) |