From 17e1e12ecfff1dea9f388b8c816ad638b0eff720 Mon Sep 17 00:00:00 2001 From: "Shreyas B. Prabhu" Date: Wed, 19 Nov 2014 01:07:44 +0530 Subject: vsnprintf: Change print_itoa to use less stack Remove recursive call in print_itoa to reduce the stack usage. Signed-off-by: Shreyas B. Prabhu Signed-off-by: Stewart Smith --- libc/stdio/vsnprintf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c index d1cd4e3..b2f0b94 100644 --- a/libc/stdio/vsnprintf.c +++ b/libc/stdio/vsnprintf.c @@ -29,22 +29,22 @@ print_itoa(char **buffer, unsigned long value, unsigned short base, bool upper) { const char zeichen[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; char c; + int i = 0; + char tmp[16]; if(base <= 2 || base > 16) return 0; - if (value < base) { - c = zeichen[value]; - if (upper) - c = toupper(c); - **buffer = c; - *buffer += 1; - } else { - print_itoa(buffer, value / base, base, upper); + do { c = zeichen[value % base]; if (upper) c = toupper(c); - **buffer = c; + tmp[i++] = c; + value /= base; + } while(value); + + while (i--) { + **buffer = tmp[i]; *buffer += 1; } -- cgit v1.1