From c35124ab54bfb313d305beb9f703b431a2e233f4 Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Fri, 14 Jun 2019 01:02:40 +0200 Subject: [PATCH] mescc: Mes C Library: Use __mesabi_uldiv. * lib/mes/ntoab.c (ntoab): Use __mesabi_uldiv. --- lib/mes/ntoab.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/mes/ntoab.c b/lib/mes/ntoab.c index 3166015f..d3499add 100644 --- a/lib/mes/ntoab.c +++ b/lib/mes/ntoab.c @@ -26,24 +26,27 @@ ntoab (long x, int base, int signed_p) static char itoa_buf[20]; char *p = itoa_buf + 11; *p-- = 0; + assert(base > 0); - int sign = 0; - unsigned long u = x; + int sign_p = 0; + unsigned long u; if (signed_p && x < 0) { - sign = 1; + sign_p = 1; u = -x; } + else + u = x; do { - long i = u % base; + unsigned long i; + u = __mesabi_uldiv(u, (unsigned long) base, &i); *p-- = i > 9 ? 'a' + i - 10 : '0' + i; - u = u / base; } while (u); - if (sign && *(p + 1) != '0') + if (sign_p && *(p + 1) != '0') *p-- = '-'; return p + 1;