1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-23 04:04:09 +01:00

Codefix: StringConsumer integer parsing failed for the most negative value, which has no positive equivalent. (#14048)

This commit is contained in:
frosch
2025-04-20 22:20:53 +02:00
committed by GitHub
parent fc45bb5a2b
commit 8aa2f6b8a6
2 changed files with 17 additions and 2 deletions

View File

@@ -813,10 +813,10 @@ private:
/* Try negative hex */
if (std::is_signed_v<T> && (src.starts_with("-0x") || src.starts_with("-0X"))) {
using Unsigned = std::make_signed_t<T>;
using Unsigned = std::make_unsigned_t<T>;
auto [len, uvalue] = ParseIntegerBase<Unsigned>(src.substr(3), 16, log_errors);
if (len == 0) return {};
T value = -uvalue;
T value = static_cast<T>(0 - uvalue);
if (value > 0) {
if (log_errors) LogError(fmt::format("Integer out of range: '{}'", src.substr(0, len + 3)));
return {};