From 254fec4f006d6e1fee5e0d345122fd32c9230f51 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Mon, 15 Apr 2024 23:10:31 +0200 Subject: [PATCH] Disable zero padding for signed integers zero padding is mostly used with unsiged integers, and is quite difficult to properly implement for signed integers. Disbaling iti n that case seems like a good compromise --- srv/format.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/srv/format.c b/srv/format.c index baa122b..8bdcc0d 100644 --- a/srv/format.c +++ b/srv/format.c @@ -21,7 +21,7 @@ static uint32_t buffer_write(uint8_t byte, void* arg); static uint32_t render_format(FormatCallback callback, void* arg, const char* restrict format, va_list va); static uint32_t render_signed(FormatCallback callback, void* arg, - int32_t number, uint8_t base, uint8_t width, bool zero_padding); + int32_t number, uint8_t base, uint8_t width); static uint32_t render_unsigned(FormatCallback callback, void* arg, uint32_t number, uint8_t base, uint8_t width, bool zero_padding); @@ -100,7 +100,7 @@ static uint32_t render_format(FormatCallback callback, void* arg, break; case 'i': if (render_signed(callback, arg, va_arg(va, int32_t), - 10, width, zero_padding)) { + 10, width)) { return 1; } break; @@ -158,7 +158,7 @@ static uint32_t render_format(FormatCallback callback, void* arg, } static uint32_t render_signed(FormatCallback callback, void* arg, - int32_t number, uint8_t base, uint8_t width, bool zero_padding) + int32_t number, uint8_t base, uint8_t width) { if (width > 0 && number < 0) { --width; @@ -183,11 +183,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg, while (width > 0) { --width; - if (zero_padding) { - if (callback('0', arg)) return 1; - } else { - if (callback(' ', arg)) return 1; - } + if (callback(' ', arg)) return 1; } } @@ -196,8 +192,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg, number = -number; } - return render_unsigned(callback, arg, (uint32_t)number, base, 0, - zero_padding); + return render_unsigned(callback, arg, (uint32_t)number, base, 0, false); } static uint32_t render_unsigned(FormatCallback callback, void* arg,