From 2230e39340779c3450389a0707b37f9e8d03ff6a Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Tue, 29 Sep 2015 23:51:20 +0100 Subject: [PATCH] microbit: BUGFIX: #1291 ManagedString(INT_MIN) does not work properly Corner case error in serialization code for INT_MIN only - corrected. --- source/MicroBitCompat.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/MicroBitCompat.cpp b/source/MicroBitCompat.cpp index 101cab9..fac127c 100644 --- a/source/MicroBitCompat.cpp +++ b/source/MicroBitCompat.cpp @@ -37,20 +37,20 @@ void string_reverse(char *s) void itoa(int n, char *s) { int i = 0; - int sign = (n >= 0); + int positive = (n >= 0); // Record the sign of the number, // Ensure our working value is positive. - if (!sign) + if (positive) n = -n; // Calculate each character, starting with the LSB. do { - s[i++] = n % 10 + '0'; - } while ((n /= 10) > 0); + s[i++] = abs(n % 10) + '0'; + } while (abs(n /= 10) > 0); // Add a negative sign as needed - if (!sign) + if (!positive) s[i++] = '-'; // Terminate the string.