mirror of
https://github.com/MariaDB/server.git
synced 2025-08-15 22:37:22 +00:00
BUG#31799: Scrambled number output due to integer overflow
An integer overflow in number->string conversion caused completely wrong output of the number LONGLONG_MIN with gcc 4.2.1. Fixed by eliminating the overflow, using only operations that are well-defined in ANSI C. strings/ctype-simple.c: An integer overflow in number->string conversion caused completely wrong output of the number LONGLONG_MIN with gcc 4.2.1. Fixed by eliminating the overflow, using only operations that are well-defined in ANSI C. strings/ctype-ucs2.c: An integer overflow in number->string conversion caused completely wrong output of the number LONGLONG_MIN with gcc 4.2.1. Fixed by eliminating the overflow, using only operations that are well-defined in ANSI C. strings/int2str.c: An integer overflow in number->string conversion caused completely wrong output of the number LONGLONG_MIN with gcc 4.2.1. Fixed by eliminating the overflow, using only operations that are well-defined in ANSI C. strings/longlong2str.c: An integer overflow in number->string conversion caused completely wrong output of the number LONGLONG_MIN with gcc 4.2.1. Fixed by eliminating the overflow, using only operations that are well-defined in ANSI C.
This commit is contained in:
@ -57,6 +57,7 @@ int2str(register long int val, register char *dst, register int radix,
|
||||
register char *p;
|
||||
long int new_val;
|
||||
char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
|
||||
ulong uval= (ulong) val;
|
||||
|
||||
if (radix < 0)
|
||||
{
|
||||
@ -65,7 +66,8 @@ int2str(register long int val, register char *dst, register int radix,
|
||||
if (val < 0)
|
||||
{
|
||||
*dst++ = '-';
|
||||
val = -val;
|
||||
/* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
|
||||
uval = (ulong)0 - uval;
|
||||
}
|
||||
radix = -radix;
|
||||
}
|
||||
@ -86,8 +88,8 @@ int2str(register long int val, register char *dst, register int radix,
|
||||
*/
|
||||
p = &buffer[sizeof(buffer)-1];
|
||||
*p = '\0';
|
||||
new_val=(ulong) val / (ulong) radix;
|
||||
*--p = dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)];
|
||||
new_val= uval / (ulong) radix;
|
||||
*--p = dig_vec[(uchar) (uval- (ulong) new_val*(ulong) radix)];
|
||||
val = new_val;
|
||||
#ifdef HAVE_LDIV
|
||||
while (val != 0)
|
||||
@ -133,20 +135,22 @@ char *int10_to_str(long int val,char *dst,int radix)
|
||||
char buffer[65];
|
||||
register char *p;
|
||||
long int new_val;
|
||||
unsigned long int uval = (unsigned long int) val;
|
||||
|
||||
if (radix < 0) /* -10 */
|
||||
{
|
||||
if (val < 0)
|
||||
{
|
||||
*dst++ = '-';
|
||||
val = -val;
|
||||
/* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
|
||||
uval = (unsigned long int)0 - uval;
|
||||
}
|
||||
}
|
||||
|
||||
p = &buffer[sizeof(buffer)-1];
|
||||
*p = '\0';
|
||||
new_val= (long) ((unsigned long int) val / 10);
|
||||
*--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10);
|
||||
new_val= (long) (uval / 10);
|
||||
*--p = '0'+ (char) (uval - (unsigned long) new_val * 10);
|
||||
val = new_val;
|
||||
|
||||
while (val != 0)
|
||||
|
Reference in New Issue
Block a user