]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
mprintf: provide hex digits for escape.c to use
authorDaniel Stenberg <daniel@haxx.se>
Sun, 11 May 2025 12:56:16 +0000 (14:56 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 12 May 2025 05:44:35 +0000 (07:44 +0200)
Since they need the exact same set, use the same set. The mprintf string
was longer than it had to be.

Closes #17311

lib/curl_printf.h
lib/escape.c
lib/mprintf.c

index 4a5fe489a52d5164c20e2e6517e375c237735099..6e0fa1fa8d8450b65b46be01a5d7b150e4e30616 100644 (file)
 #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
 
 /*
index 372c692d9d1416cfe9d58bf6435882042e53693e..3cd906dc6c2cfe5fcb990f6a32eeda076f13e8dc 100644 (file)
@@ -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];
 }
index 31008105e5de79405bf3dedc3bc272c9c656d6ad..41717bb30985870a65c58920749363e4b9203ac2 100644 (file)
 #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;