]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: prefer c_isxdigit when that is the intent
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 27 Oct 2023 15:45:50 +0000 (08:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 30 Oct 2023 07:58:03 +0000 (00:58 -0700)
* src/digest.c (valid_digits, split_3):
* src/echo.c (main):
* src/printf.c (print_esc):
* src/ptx.c (unescape_string):
* src/stat.c (print_it):
When the code is supposed to support only POSIX-locale hex digits,
use c_isxdigit rather than isxdigit.  Include c-ctype.h as needed.
This defends against oddball locales where isxdigit != c_isxdigit.

src/digest.c
src/echo.c
src/printf.c
src/ptx.c
src/stat.c

index b996dde1159e998e479e3391eb3fd84def463537..1f36953081f5c175d7dbbbfa4e28507cc1d9066f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "system.h"
 #include "argmatch.h"
+#include "c-ctype.h"
 #include "quote.h"
 #include "xdectoint.h"
 #include "xstrtol.h"
@@ -660,7 +661,7 @@ valid_digits (unsigned char const *s, size_t len)
     {
       for (idx_t i = 0; i < digest_hex_bytes; i++)
         {
-          if (!isxdigit (*s))
+          if (!c_isxdigit (*s))
             return false;
           ++s;
         }
@@ -856,7 +857,7 @@ split_3 (char *s, size_t s_len,
 # endif
   unsigned char const *hp = *digest;
   digest_hex_bytes = 0;
-  while (isxdigit (*hp++))
+  while (c_isxdigit (*hp++))
     digest_hex_bytes++;
   if (digest_hex_bytes < 2 || digest_hex_bytes % 2
       || BLAKE2B_MAX_LEN * 2 < digest_hex_bytes)
index 278778ec6754457c01f2030ded75e1091de49134..f80ead86f1d3b5f158ed4ea2696d543697861cbc 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include "system.h"
 #include "assure.h"
+#include "c-ctype.h"
 
 /* The official name of this program (e.g., no 'g' prefix).  */
 #define PROGRAM_NAME "echo"
@@ -219,12 +220,12 @@ just_echo:
                     case 'x':
                       {
                         unsigned char ch = *s;
-                        if (! isxdigit (ch))
+                        if (! c_isxdigit (ch))
                           goto not_an_escape;
                         s++;
                         c = hextobin (ch);
                         ch = *s;
-                        if (isxdigit (ch))
+                        if (c_isxdigit (ch))
                           {
                             s++;
                             c = c * 16 + hextobin (ch);
index f36b455190cc119a7f66f48e8a24522ad439b0b7..ebe09ba7642a088d185294dc7e81f48123e897b6 100644 (file)
@@ -56,6 +56,7 @@
 #include <wchar.h>
 
 #include "system.h"
+#include "c-ctype.h"
 #include "cl-strtod.h"
 #include "quote.h"
 #include "unicodeio.h"
@@ -262,7 +263,7 @@ print_esc (char const *escstart, bool octal_0)
     {
       /* A hexadecimal \xhh escape sequence must have 1 or 2 hex. digits.  */
       for (esc_length = 0, ++p;
-           esc_length < 2 && isxdigit (to_uchar (*p));
+           esc_length < 2 && c_isxdigit (to_uchar (*p));
            ++esc_length, ++p)
         esc_value = esc_value * 16 + hextobin (*p);
       if (esc_length == 0)
@@ -292,7 +293,7 @@ print_esc (char const *escstart, bool octal_0)
            esc_length > 0;
            --esc_length, ++p)
         {
-          if (! isxdigit (to_uchar (*p)))
+          if (! c_isxdigit (to_uchar (*p)))
             error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
           uni_value = uni_value * 16 + hextobin (*p);
         }
index 3601875ed77a8c98415b8664a89e489dae10bb16..3cd84b2e95a6ea1283446ca366ab630aab93cf3d 100644 (file)
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -24,6 +24,7 @@
 #include "system.h"
 #include <regex.h>
 #include "argmatch.h"
+#include "c-ctype.h"
 #include "fadvise.h"
 #include "quote.h"
 #include "read-file.h"
@@ -308,7 +309,7 @@ unescape_string (char *string)
             case 'x':          /* \xhhh escape, 3 chars maximum */
               value = 0;
               for (length = 0, string++;
-                   length < 3 && isxdigit (to_uchar (*string));
+                   length < 3 && c_isxdigit (to_uchar (*string));
                    length++, string++)
                 value = value * 16 + HEXTOBIN (*string);
               if (length == 0)
index 39acfee70262f9ce85c3453ca8d62a7850890d5d..522e922ed4407b394b8bccc82d626502571d6f2c 100644 (file)
@@ -58,6 +58,7 @@
 
 #include "areadlink.h"
 #include "argmatch.h"
+#include "c-ctype.h"
 #include "file-type.h"
 #include "filemode.h"
 #include "fs.h"
@@ -1215,13 +1216,13 @@ print_it (char const *format, int fd, char const *filename,
               putchar (esc_value);
               --b;
             }
-          else if (*b == 'x' && isxdigit (to_uchar (b[1])))
+          else if (*b == 'x' && c_isxdigit (to_uchar (b[1])))
             {
               int esc_value = hextobin (b[1]); /* Value of \xhh escape. */
               /* A hexadecimal \xhh escape sequence must have
                  1 or 2 hex. digits.  */
               ++b;
-              if (isxdigit (to_uchar (b[1])))
+              if (c_isxdigit (to_uchar (b[1])))
                 {
                   ++b;
                   esc_value = esc_value * 16 + hextobin (*b);