1
0
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:
Andrew Hutchings
2023-11-17 17:41:23 +00:00
committed by Andrew Hutchings
parent be6d48fd53
commit f552febe43
10 changed files with 160 additions and 22 deletions

View File

@@ -55,9 +55,9 @@
#include "my_sys.h" /* defines errno */
#include <errno.h>
#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\
#define char_val(X, Y) (X >= '0' && X <= '9' ? X-'0' :\
X >= 'A' && X <= 'Z' ? X-'A'+10 :\
X >= 'a' && X <= 'z' ? X-'a'+10 :\
X >= 'a' && X <= 'z' ? (Y <= 36 ? X-'a'+10 : X-'a'+36) :\
'\177')
char *str2int(register const char *src, register int radix, long int lower,
@@ -76,10 +76,10 @@ char *str2int(register const char *src, register int radix, long int lower,
*val = 0;
/* Check that the radix is in the range 2..36 */
/* Check that the radix is in the range 2..62 */
#ifndef DBUG_OFF
if (radix < 2 || radix > 36) {
if (radix < 2 || radix > 62) {
errno=EDOM;
return NullS;
}
@@ -126,7 +126,7 @@ char *str2int(register const char *src, register int radix, long int lower,
to left in order to avoid overflow. Answer is after last digit.
*/
for (n = 0; (digits[n]=char_val(*src)) < radix && n < 20; n++,src++) ;
for (n = 0; (digits[n]=char_val(*src, radix)) < radix && n < 20; n++,src++) ;
/* Check that there is at least one digit */