Fixed bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
pjz SDL_ltoa(-2147483648,s,10) only returns "-" because there is a bug in the code: if ( value < 0 ) { *bufp++ = '-'; value = -value; } but -(-2147483648) is still -2147483648 (0x80000000) as signed int (or long), so the following loop doesn't run at all. Similar bug are also in SDL_lltoa. BTW, there is no sanity check for radix.
parent
fcf692276a
commit
35ab76d083
|
@ -665,23 +665,9 @@ SDL_ltoa(long value, char *string, int radix)
|
||||||
|
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
*bufp++ = '-';
|
*bufp++ = '-';
|
||||||
value = -value;
|
SDL_ultoa(-value, bufp, radix);
|
||||||
}
|
|
||||||
if (value) {
|
|
||||||
while (value > 0) {
|
|
||||||
*bufp++ = ntoa_table[value % radix];
|
|
||||||
value /= radix;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
*bufp++ = '0';
|
SDL_ultoa(value, bufp, radix);
|
||||||
}
|
|
||||||
*bufp = '\0';
|
|
||||||
|
|
||||||
/* The numbers went into the string backwards. :) */
|
|
||||||
if (*string == '-') {
|
|
||||||
SDL_strrev(string + 1);
|
|
||||||
} else {
|
|
||||||
SDL_strrev(string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
@ -723,23 +709,9 @@ SDL_lltoa(Sint64 value, char *string, int radix)
|
||||||
|
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
*bufp++ = '-';
|
*bufp++ = '-';
|
||||||
value = -value;
|
SDL_ulltoa(-value, bufp, radix);
|
||||||
}
|
|
||||||
if (value) {
|
|
||||||
while (value > 0) {
|
|
||||||
*bufp++ = ntoa_table[value % radix];
|
|
||||||
value /= radix;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
*bufp++ = '0';
|
SDL_ulltoa(value, bufp, radix);
|
||||||
}
|
|
||||||
*bufp = '\0';
|
|
||||||
|
|
||||||
/* The numbers went into the string backwards. :) */
|
|
||||||
if (*string == '-') {
|
|
||||||
SDL_strrev(string + 1);
|
|
||||||
} else {
|
|
||||||
SDL_strrev(string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
|
Loading…
Reference in New Issue