Compare commits

..

2 Commits

Author SHA1 Message Date
254fec4f00 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
2024-04-15 23:10:31 +02:00
0088322ee7 Fix warning 2024-04-15 23:10:19 +02:00

View File

@ -21,7 +21,7 @@ static uint32_t buffer_write(uint8_t byte, void* arg);
static uint32_t render_format(FormatCallback callback, void* arg, static uint32_t render_format(FormatCallback callback, void* arg,
const char* restrict format, va_list va); const char* restrict format, va_list va);
static uint32_t render_signed(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);
static uint32_t render_unsigned(FormatCallback callback, void* arg, static uint32_t render_unsigned(FormatCallback callback, void* arg,
uint32_t number, uint8_t base, uint8_t width, bool zero_padding); 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; break;
case 'i': case 'i':
if (render_signed(callback, arg, va_arg(va, int32_t), if (render_signed(callback, arg, va_arg(va, int32_t),
10, width, zero_padding)) { 10, width)) {
return 1; return 1;
} }
break; break;
@ -121,6 +121,7 @@ static uint32_t render_format(FormatCallback callback, void* arg,
zero_padding = true; zero_padding = true;
continue; continue;
} }
// fall through
case '1': case '1':
case '2': case '2':
case '3': case '3':
@ -157,7 +158,7 @@ static uint32_t render_format(FormatCallback callback, void* arg,
} }
static uint32_t render_signed(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) { if (width > 0 && number < 0) {
--width; --width;
@ -182,11 +183,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
while (width > 0) { while (width > 0) {
--width; --width;
if (zero_padding) { if (callback(' ', arg)) return 1;
if (callback('0', arg)) return 1;
} else {
if (callback(' ', arg)) return 1;
}
} }
} }
@ -195,8 +192,7 @@ static uint32_t render_signed(FormatCallback callback, void* arg,
number = -number; number = -number;
} }
return render_unsigned(callback, arg, (uint32_t)number, base, 0, return render_unsigned(callback, arg, (uint32_t)number, base, 0, false);
zero_padding);
} }
static uint32_t render_unsigned(FormatCallback callback, void* arg, static uint32_t render_unsigned(FormatCallback callback, void* arg,