[ox/std] Make strToInt return error for empty string
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
2025-06-20 22:43:33 -05:00
parent 394b568e72
commit 9d8da7ccda

View File

@ -104,13 +104,16 @@ constexpr ox::Result<int> 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<int64_t>(str.len()) - 1; i != -1; --i) {
auto s = static_cast<std::size_t>(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;