changeset 253:d1b4f4ea4715

Fix handling of negative values.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Feb 2016 21:27:19 +0200
parents 80ffeb316596
children 3d1e2af4e4e6
files th_string.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Tue Feb 16 20:53:10 2016 +0200
+++ b/th_string.c	Tue Feb 16 21:27:19 2016 +0200
@@ -112,7 +112,7 @@
 // Simple implementations of printf() type functions
 //
 static int th_vput_int(th_printf_ctx *ctx, int (*vputch)(th_printf_ctx *ctx, const char ch),
-    int val, const int radix, const char padMode, const char padChar,
+    int pval, const int radix, const char padMode, const char padChar,
     const int width, const BOOL unsig, const BOOL upcase, const BOOL sign)
 {
     char buf[64];
@@ -124,16 +124,17 @@
         return EOF;
 
     // Check for negative value
-    if (val < 0 && !unsig)
+    if (pval < 0 && !unsig)
     {
         neg = TRUE;
-        val = -val;
+        pval = -pval;
     }
 
     // Render the value to a string in buf (reversed)
+    unsigned int val = pval;
     do
     {
-        int digit = val % radix;
+        unsigned int digit = val % radix;
         if (digit < 10)
             buf[pos] = '0' + digit;
         else