[bug] Don't negate a signed number (UB fix)

* Fixes a potential UB in number to string conversion because of
    a possible undefined behavior caused by -int64_t(a) code. The
    fix replaces the code with Support::neg() function, which was
    designed for exactly this.
This commit is contained in:
kobalicek
2025-02-12 15:55:06 +01:00
parent e1b20711cc
commit 58c585f003

View File

@@ -291,7 +291,7 @@ Error String::_opNumber(ModifyOp op, uint64_t i, uint32_t base, size_t width, St
// -----------
if (Support::test(flags, StringFormatFlags::kSigned) && int64_t(i) < 0) {
i = uint64_t(-int64_t(i));
i = Support::neg(i);
sign = '-';
}
else if (Support::test(flags, StringFormatFlags::kShowSign)) {