From 6c966c68ad0d6a9844210088585612774caf3fe6 Mon Sep 17 00:00:00 2001 From: Max Sikstrom Date: Tue, 14 Feb 2023 14:57:13 +0100 Subject: [PATCH] Use "unsigned char:1" for flags "char" is treated, at least in many cases, as signed values. Having that field as 1 bit means it can be treated as one sign bit, no data bits. Thus only values 0 and -1 will be accepted It seems to differ between versions of the compiler. But in any case, explicitly defining it as unsigned means only the values 0 and 1 will be accepted, and therefore there shouldn't be any issues between compiler versions --- tinyprintf.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tinyprintf.c b/tinyprintf.c index bb22700..f8f96da 100644 --- a/tinyprintf.c +++ b/tinyprintf.c @@ -70,14 +70,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Implementation */ struct param { - char lz:1; /**< Leading zeros */ - char alt:1; /**< alternate form */ - char uc:1; /**< Upper case (for base16 only) */ - char align_left:1; /**< 0 == align right (default), 1 == align left */ - unsigned int width; /**< field width */ - char sign; /**< The sign to display (if any) */ - unsigned int base; /**< number base (e.g.: 8, 10, 16) */ - char *bf; /**< Buffer to output */ + unsigned char lz:1; /**< Leading zeros */ + unsigned char alt:1; /**< alternate form */ + unsigned char uc:1; /**< Upper case (for base16 only) */ + unsigned char align_left:1; + /**< 0 == align right (default), 1 == align left */ + unsigned int width; /**< field width */ + char sign; /**< The sign to display (if any) */ + unsigned int base; /**< number base (e.g.: 8, 10, 16) */ + char *bf; /**< Buffer to output */ };