From 8ff124af3092a83ee184b45f4ae3f1e76f93b2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20van=20Dorst?= Date: Wed, 10 Sep 2025 16:07:59 +0200 Subject: [PATCH] httpd: fix itoa_html() does not print the middle zero. when the input is 100. the first zero is not printed because t = 0 and skip printing. So the output is "10" instead of "100". --- httpd/page_impl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 0888bf2..79f62f8 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -67,14 +67,20 @@ void byte_to_html(uint8_t val) } while(cnt); } - +/* Converts a uint8_t to raw string. + Suppress leading zeros. +*/ void itoa_html(uint8_t v) { - uint8_t t = (v / 100) % 10; - if (t) + uint8_t t = (v / 100); + // when print_zeros is not zero, we know that a non-zero number has printed. + // That have to print all the next numbers. + uint8_t print_zeros = t; + if (print_zeros) char_to_html('0' + t); t = (v / 10) % 10; - if (t) + print_zeros |= t; + if (print_zeros) char_to_html('0' + t); char_to_html('0' + (v % 10)); }