1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibPDF: Parse integer numbers with atoi() instead of strtof()

strtof() produces rounding errors for very large numbers, which we
don't want for integers, as they may have to be precise.
This commit is contained in:
Julian Offenhäuser 2022-11-11 12:07:11 +01:00 committed by Andreas Kling
parent c2ad29c85f
commit 0bc3333740

View file

@ -194,12 +194,10 @@ PDFErrorOr<Value> Parser::parse_number()
m_reader.consume_whitespace();
auto string = String(m_reader.bytes().slice(start_offset, m_reader.offset() - start_offset));
float f = strtof(string.characters(), nullptr);
if (is_float)
return Value(f);
return Value(strtof(string.characters(), nullptr));
VERIFY(floorf(f) == f);
return Value(static_cast<int>(f));
return Value(atoi(string.characters()));
}
PDFErrorOr<NonnullRefPtr<NameObject>> Parser::parse_name()