Skip to content

Commit 7c8edab

Browse files
committed
Accommodate arith-overflow in serialize::json numeric parsing.
1 parent c8db89a commit 7c8edab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libserialize/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,8 @@ impl<T: Iterator<Item=char>> Parser<T> {
15691569
while !self.eof() {
15701570
match self.ch_or_null() {
15711571
c @ '0' ... '9' => {
1572-
accum *= 10;
1573-
accum += (c as u64) - ('0' as u64);
1572+
accum = accum.wrapping_mul(10);
1573+
accum = accum.wrapping_add((c as u64) - ('0' as u64));
15741574

15751575
// Detect overflow by comparing to the last value.
15761576
if accum <= last_accum { return self.error(InvalidNumber); }

0 commit comments

Comments
 (0)