[libc-commits] [libc] [llvm] [libc] Don't touch str_end in strto* and wcsto* functions when base is incorrect (PR #200073)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Wed May 27 21:59:10 PDT 2026


================
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Shared implementation of strto* and wcsto* endpoints.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/str_to_integer.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace internal {
+
+// Shared implementation of strto* and wcsto* endpoints. Invokes
+// strtointeger shared API and sets errno and str_end pointer according to the
+// standard.
+template <typename T, typename CharType>
+LIBC_INLINE constexpr T str_to_helper(const CharType *__restrict str,
+                                      CharType **__restrict str_end, int base) {
+  auto result = strtointeger<T>(str, base);
+  if (result.has_error())
+    libc_errno = result.error;
----------------
vonosmas wrote:

Understood (BTW would be nice to add some kind of build-time check for this). I've reverted most of the change and added a bunch of explicit `EINVAL` checks at the entrypoint -- looks like the opportunity for refactoring is slim then.

https://github.com/llvm/llvm-project/pull/200073


More information about the libc-commits mailing list