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".
This commit is contained in:
René van Dorst
2025-09-11 07:34:18 +02:00
parent 94ae1472c3
commit 8ff124af30
+10 -4
View File
@@ -67,14 +67,20 @@ void byte_to_html(uint8_t val)
} while(cnt); } while(cnt);
} }
/* Converts a uint8_t to raw string.
Suppress leading zeros.
*/
void itoa_html(uint8_t v) void itoa_html(uint8_t v)
{ {
uint8_t t = (v / 100) % 10; uint8_t t = (v / 100);
if (t) // 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); char_to_html('0' + t);
t = (v / 10) % 10; t = (v / 10) % 10;
if (t) print_zeros |= t;
if (print_zeros)
char_to_html('0' + t); char_to_html('0' + t);
char_to_html('0' + (v % 10)); char_to_html('0' + (v % 10));
} }