]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Use isdigit(3) instead of a reimplementation of it 481/head
authorAlejandro Colomar <alx.manpages@gmail.com>
Tue, 28 Dec 2021 18:55:09 +0000 (19:55 +0100)
committerAlejandro Colomar <alx.manpages@gmail.com>
Wed, 29 Dec 2021 01:41:09 +0000 (02:41 +0100)
C89 defined isdigit as a function that tests for any decimal-digit
character, defining the decimal digits as 0 1 2 3 4 5 6 7 8 9.

I don't own a copy of C89 to check, but check in C17:

7.4.1.5
5.2.1

More specifically:

> In both the source and execution basic character sets, the value
> of each character after 0 in the above list of decimal digits
> shall be one greater than the value of the previous.

And since in ascii(7), the character after '9' is ':', it's highly
unlikely that any implementation will ever accept any
_decimal digit_ other than 0..9.

POSIX simply defers to the ISO C standard.

This is exactly what we wanted from ISDIGIT(c), so just use it.
Non-standard implementations might have been slower or considered
other characters as digits in the past, but let's assume
implementations available today conform to ISO C89.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
libmisc/getdate.y

index 82f1369cb70f8e076553dd51bdb1865698764c35..0c07f7466a9477839e50fa76fa8482fd12ebeb38 100644 (file)
 #include <ctype.h>
 #include <time.h>
 
-/* ISDIGIT differs from isdigit(3), as follows:
-   - Its arg may be any int or unsigned int; it need not be an unsigned char.
-   - It's typically faster.
-   Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
-   only '0' through '9' are digits.  Prefer ISDIGIT to isdigit(3) unless
-   it's important to use the locale's definition of `digit' even when the
-   host does not conform to Posix.  */
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
-
 #include "getdate.h"
 
 #include <string.h>
@@ -760,18 +751,18 @@ yylex (void)
       while (isspace (*yyInput))
        yyInput++;
 
-      if (ISDIGIT (c = *yyInput) || c == '-' || c == '+')
+      if (isdigit (c = *yyInput) || c == '-' || c == '+')
        {
          if (c == '-' || c == '+')
            {
              sign = c == '-' ? -1 : 1;
-             if (!ISDIGIT (*++yyInput))
+             if (!isdigit (*++yyInput))
                /* skip the '-' sign */
                continue;
            }
          else
            sign = 0;
-         for (yylval.Number = 0; ISDIGIT (c = *yyInput++);)
+         for (yylval.Number = 0; isdigit (c = *yyInput++);)
            yylval.Number = 10 * yylval.Number + c - '0';
          yyInput--;
          if (sign < 0)