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
Notes: sideshowbarker 2024-07-17 06:35:23 +09:00

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()