microbit: BUGFIX: #1291 ManagedString(INT_MIN) does not work properly

Corner case error in serialization code for INT_MIN only - corrected.
master td2
Joe Finney 7 years ago
parent 3cfc7ec6e7
commit 2230e39340
  1. 10
      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.

Loading…
Cancel
Save