[all-commits] [llvm/llvm-project] 934e56: [libc] Don't touch str_end in strto* and wcsto* fu...
Alexey Samsonov via All-commits
all-commits at lists.llvm.org
Thu May 28 10:05:51 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 934e5610ebfae936598896dc188cad331992d1af
https://github.com/llvm/llvm-project/commit/934e5610ebfae936598896dc188cad331992d1af
Author: Alexey Samsonov <vonosmas at gmail.com>
Date: 2026-05-28 (Thu, 28 May 2026)
Changed paths:
M libc/src/inttypes/strtoimax.cpp
M libc/src/inttypes/strtoumax.cpp
M libc/src/stdlib/strtol.cpp
M libc/src/stdlib/strtol_l.cpp
M libc/src/stdlib/strtoll.cpp
M libc/src/stdlib/strtoll_l.cpp
M libc/src/stdlib/strtoul.cpp
M libc/src/stdlib/strtoul_l.cpp
M libc/src/stdlib/strtoull.cpp
M libc/src/stdlib/strtoull_l.cpp
M libc/src/wchar/wcstol.cpp
M libc/src/wchar/wcstoll.cpp
M libc/src/wchar/wcstoul.cpp
M libc/src/wchar/wcstoull.cpp
M libc/test/src/stdlib/StrtolTest.h
M libc/test/src/stdlib/strtoint32_test.cpp
M libc/test/src/stdlib/strtoint64_test.cpp
M libc/test/src/wchar/WcstolTest.h
Log Message:
-----------
[libc] Don't touch str_end in strto* and wcsto* functions when base is incorrect (#200073)
Updates the behavior of `stro*` and `wcsto*` endpoints to not touch
`str_end` pointer when the provided value of `base` is incorrect and
errno is set to `EINVAL`.
`strto*` and `wcsto*` functions accept `base` as an input argument,
which can only be 0 or lie in [2,36] range. In case of invalid argument,
the functions should return 0 and set errno accordingly. Should the
"output argument" of `str_end` be updated in this case to point to the
beginning of the input string?
* C standard is unclear about it -
is says that `str` should be stored in `str_end` **if `str` is empty or
does not have the expected form** -- but there is no "expected form" for
invalid base values.
* POSIX standard explicitly mentions that for incorrect base value errno
should be set to `EINVAL` and points out that the value of `str_end`
is **unspecified** in this case.
Known implementations don't have a universal agreement about it:
* musl sets `str_end` unconditionally
* glibc doesn't do that in `EINVAL` case
* newlib doesn't do that either.
LLVM-libc used to unconditionally set `str_end` even in `EINVAL` case,
which is changed in this PR. This would not only help with portability,
but makes sense by itself - if input arguments are clearly invalid,
let's not touch output arguments either.
Assisted by: Gemini, human-reviewed
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list