diff options
author | Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com> | 2014-11-19 01:07:44 +0530 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2014-11-26 11:22:23 +1100 |
commit | 17e1e12ecfff1dea9f388b8c816ad638b0eff720 (patch) | |
tree | ef0f25b757cd9d874edcc9ff1f378a8a56058ea0 /libc | |
parent | 7854b261c98ca419e3f33af969ccc5e74f3b5716 (diff) | |
download | skiboot-17e1e12ecfff1dea9f388b8c816ad638b0eff720.zip skiboot-17e1e12ecfff1dea9f388b8c816ad638b0eff720.tar.gz skiboot-17e1e12ecfff1dea9f388b8c816ad638b0eff720.tar.bz2 |
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 <shreyas@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc')
-rw-r--r-- | libc/stdio/vsnprintf.c | 18 |
1 files 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; } |