From b701d2095681a06939f0c955df7cd77ea0fff63e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 20 Jun 2025 22:43:33 -0500 Subject: [PATCH] [ox/std] Make strToInt return error for empty string (synced from 9d8da7ccda6dddc2396ee6ca8a7e7fcdabf01161) --- src/ox/std/stringview.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ox/std/stringview.hpp b/src/ox/std/stringview.hpp index 6a2221e05..6fc955c61 100644 --- a/src/ox/std/stringview.hpp +++ b/src/ox/std/stringview.hpp @@ -104,13 +104,16 @@ constexpr ox::Result strToInt(StringViewCR str) noexcept { OX_ALLOW_UNSAFE_BUFFERS_BEGIN int total = 0; int multiplier = 1; + if (str.len() == 0) [[unlikely]] { + return Error{1, "Empty string passed to strToInt"}; + } for (auto i = static_cast(str.len()) - 1; i != -1; --i) { auto s = static_cast(i); if (str[s] >= '0' && str[s] <= '9') { total += (str[s] - '0') * multiplier; multiplier *= 10; } else { - return ox::Error(1); + return ox::Error{1}; } } return total;