From: Daniel Stenberg Date: Sun, 11 May 2025 12:56:16 +0000 (+0200) Subject: mprintf: provide hex digits for escape.c to use X-Git-Tag: curl-8_14_0~110 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f862f863bfc18ca4796e17cd93773f0744c4d3b4;p=thirdparty%2Fcurl.git mprintf: provide hex digits for escape.c to use Since they need the exact same set, use the same set. The mprintf string was longer than it had to be. Closes #17311 --- diff --git a/lib/curl_printf.h b/lib/curl_printf.h index 4a5fe489a5..6e0fa1fa8d 100644 --- a/lib/curl_printf.h +++ b/lib/curl_printf.h @@ -30,6 +30,12 @@ #define MERR_MEM 1 #define MERR_TOO_LARGE 2 +/* Lower-case digits. */ +extern const unsigned char Curl_ldigits[]; + +/* Upper-case digits. */ +extern const unsigned char Curl_udigits[]; + #ifdef BUILDING_LIBCURL /* diff --git a/lib/escape.c b/lib/escape.c index 372c692d9d..3cd906dc6c 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -232,9 +232,7 @@ void Curl_hexbyte(unsigned char *dest, /* must fit two bytes */ unsigned char val, bool lowercase) { - const unsigned char uhex[] = "0123456789ABCDEF"; - const unsigned char lhex[] = "0123456789abcdef"; - const unsigned char *t = lowercase ? lhex : uhex; + const unsigned char *t = lowercase ? Curl_ldigits : Curl_udigits; dest[0] = t[val >> 4]; dest[1] = t[val & 0x0F]; } diff --git a/lib/mprintf.c b/lib/mprintf.c index 31008105e5..41717bb309 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -64,10 +64,10 @@ #endif /* Lower-case digits. */ -static const char lower_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; +const unsigned char Curl_ldigits[] = "0123456789abcdef"; /* Upper-case digits. */ -static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const unsigned char Curl_udigits[] = "0123456789ABCDEF"; #define OUTCHAR(x) \ do { \ @@ -645,7 +645,7 @@ static int formatf( va_list ap_save) /* list of parameters */ { static const char nilstr[] = "(nil)"; - const char *digits = lower_digits; /* Base-36 digits for numbers. */ + const unsigned char *digits = Curl_ldigits; int done = 0; /* number of characters written */ int i; int ocount = 0; /* number of output segments */ @@ -748,7 +748,7 @@ static int formatf( } else if(flags & FLAGS_HEX) { /* Hexadecimal unsigned integer */ - digits = (flags & FLAGS_UPPER) ? upper_digits : lower_digits; + digits = (flags & FLAGS_UPPER) ? Curl_udigits : Curl_ldigits; base = 16; is_neg = FALSE; } @@ -777,6 +777,7 @@ number: /* Put the number in WORK. */ w = workend; + DEBUGASSERT(base <= 16); switch(base) { case 10: while(num > 0) { @@ -894,7 +895,7 @@ number: if(iptr->val.ptr) { /* If the pointer is not NULL, write it as a %#x spec. */ base = 16; - digits = (flags & FLAGS_UPPER) ? upper_digits : lower_digits; + digits = (flags & FLAGS_UPPER) ? Curl_udigits : Curl_ldigits; is_alt = TRUE; num = (size_t) iptr->val.ptr; is_neg = FALSE;