]> Savannah Git Hosting - gnulib.git/commitdiff
xstrtol: remove the base-checking changes
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 26 Jul 2024 00:24:20 +0000 (17:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 26 Jul 2024 00:24:54 +0000 (17:24 -0700)
* lib/xstrtol.c (__xstrtol): Stop worrying about hypothetical
implementations that are causing more confusion than the code is
worth.  Instead, go back more to old way of doing things.
None of this matters for practical applications.
* lib/xstrtol.h: Document that behavior is undefined
if the base is negative, 1, or greater than 36.
* modules/xstrtol (Depends-on): Remove nullptr; no longer needed.

ChangeLog
lib/xstrtol.c
lib/xstrtol.h
modules/xstrtol

index 21b1840decca555105ff1917304aa241c304b47c..0c35378606bff47b95656acdf8f249585fc69052 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-07-25  Paul Eggert  <eggert@cs.ucla.edu>
+
+       xstrtol: remove the base-checking changes
+       * lib/xstrtol.c (__xstrtol): Stop worrying about hypothetical
+       implementations that are causing more confusion than the code is
+       worth.  Instead, go back more to old way of doing things.
+       None of this matters for practical applications.
+       * lib/xstrtol.h: Document that behavior is undefined
+       if the base is negative, 1, or greater than 36.
+       * modules/xstrtol (Depends-on): Remove nullptr; no longer needed.
+
 2024-07-25  Bruno Haible  <bruno@clisp.org>
 
        xstrtol, xstrtoll tests: Avoid test failure on FreeBSD.
index 797d3e4deef955269778e91a7dd807b63c0b3f08..4e7c0fcfda528c32b6868734e3a77959a8ca7c7d 100644 (file)
@@ -71,7 +71,7 @@ strtol_error
 __xstrtol (char const *nptr, char **endptr, int base,
            __strtol_t *val, char const *valid_suffixes)
 {
-  char *t_ptr = nullptr;
+  char *t_ptr;
   char **p = endptr ? endptr : &t_ptr;
 
   if (! TYPE_SIGNED (__strtol_t))
@@ -88,13 +88,10 @@ __xstrtol (char const *nptr, char **endptr, int base,
     }
 
   errno = 0;
-  __strtol_t tmp = __strtol (nptr, &t_ptr, base);
-  if (!t_ptr)
-    return LONGINT_INVALID;
-  *p = t_ptr;
+  __strtol_t tmp = __strtol (nptr, p, base);
   strtol_error err = LONGINT_OK;
 
-  if (*p == nptr && (errno == 0 || errno == EINVAL))
+  if (*p == nptr)
     {
       /* If there is no number but there is a valid suffix, assume the
          number is 1.  The string is invalid otherwise.  */
index 1fab74881096e0d0c79bdb8e0e4140b47896e694..45c892157848834b39207b071a7698b11e9b2701 100644 (file)
@@ -47,6 +47,8 @@ typedef enum strtol_error strtol_error;
    - Return strtol_error, and store any result through an additional
      TYPE *VAL pointer instead of returning the result.
    - If TYPE is unsigned, reject leading '-'.
+   - Behavior is undefined if BASE is negative, 1, or greater than 36.
+     (In this respect xstrtol acts like the C standard, not like POSIX.)
    - Accept an additional char const *VALID_SUFFIXES pointer to a
      possibly-empty string containing allowed numeric suffixes,
      which multiply the value.  These include SI suffixes like 'k' and 'M';
index 1f8a28fa6c8ce910ede6136974d427ea14ec787d..ef49dfc357b1f215d1985dfdd0ad2917ac51e126 100644 (file)
@@ -9,7 +9,6 @@ m4/xstrtol.m4
 
 Depends-on:
 intprops
-nullptr
 stdckdint
 stdint