mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-30879 Add support for up to BASE 62 to CONV()
BASE 62 uses 0-9, A-Z and then a-z to give the numbers 0-61. This patch increases the range of the string functions to cover this. Based on ideas and tests in PR #2589, but re-written into the charset functions. Includes fix by Sergei, UBSAN complained: ctype-simple.c:683:38: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself Co-authored-by: Weijun Huang <huangweijun1001@gmail.com> Co-authored-by: Sergei Golubchik <serg@mariadb.org>
This commit is contained in:
committed by
Andrew Hutchings
parent
be6d48fd53
commit
f552febe43
@@ -35,8 +35,8 @@
|
||||
result is normally a pointer to this NUL character, but if the radix
|
||||
is dud the result will be NullS and nothing will be changed.
|
||||
|
||||
If radix is -2..-36, val is taken to be SIGNED.
|
||||
If radix is 2.. 36, val is taken to be UNSIGNED.
|
||||
If radix is -2..-62, val is taken to be SIGNED.
|
||||
If radix is 2.. 62, val is taken to be UNSIGNED.
|
||||
That is, val is signed if and only if radix is. You will normally
|
||||
use radix -10 only through itoa and ltoa, for radix 2, 8, or 16
|
||||
unsigned is what you generally want.
|
||||
@@ -63,12 +63,17 @@ char *ll2str(longlong val,char *dst,int radix, int upcase)
|
||||
char buffer[65];
|
||||
register char *p;
|
||||
long long_val;
|
||||
const char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
|
||||
const char *dig_vec;
|
||||
ulonglong uval= (ulonglong) val;
|
||||
|
||||
if (radix < -36 || radix > 36)
|
||||
dig_vec= _dig_vec_base62;
|
||||
else
|
||||
dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
|
||||
|
||||
if (radix < 0)
|
||||
{
|
||||
if (radix < -36 || radix > -2) return (char*) 0;
|
||||
if (radix < -62 || radix > -2) return (char*) 0;
|
||||
if (val < 0) {
|
||||
*dst++ = '-';
|
||||
/* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
|
||||
@@ -78,7 +83,7 @@ char *ll2str(longlong val,char *dst,int radix, int upcase)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (radix > 36 || radix < 2) return (char*) 0;
|
||||
if (radix > 62 || radix < 2) return (char*) 0;
|
||||
}
|
||||
if (uval == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user