From 6b583869c09134ec05ca79b630459d1ae227f048 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 8 Nov 2011 11:13:48 +1100 Subject: [PATCH] desktop: fixed ultoa_invert() the string was backwards --- libraries/Desktop/support/ultoa_invert.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/Desktop/support/ultoa_invert.c b/libraries/Desktop/support/ultoa_invert.c index b7e941cd3f..0bbd000894 100644 --- a/libraries/Desktop/support/ultoa_invert.c +++ b/libraries/Desktop/support/ultoa_invert.c @@ -2,11 +2,23 @@ char * __ultoa_invert(unsigned long val, char *s, int base) { + char tbuf[32]; + char *p; switch (base) { case 8: - return s+sprintf(s, "%lo", val); + snprintf(tbuf, sizeof(tbuf), "%lo", val); + break; case 16: - return s+sprintf(s, "%lx", val); + snprintf(tbuf, sizeof(tbuf), "%lx", val); + break; + case 10: + default: + snprintf(tbuf, sizeof(tbuf), "%lu", val); + break; } - return s+sprintf(s, "%lu", val); + p = &tbuf[strlen(tbuf)-1]; + while (p >= &tbuf[0]) { + *s++ = *p--; + } + return s; }