+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.
__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))
}
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. */
- 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';
Depends-on:
intprops
-nullptr
stdckdint
stdint