Skip to content

Commit

Permalink
Check for overflows when parsing uints from macro
Browse files Browse the repository at this point in the history
Fixes recmo#199
  • Loading branch information
jules committed Oct 31, 2022
1 parent 46937ac commit e88411b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ruint-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ fn parse(value: &str, bits: &str) -> Result<TokenStream, String> {
}

// Add digit to result
limbs[0] += digit; // Never carries
let (result, overflow) = limbs[0].overflowing_add(digit);
limbs[0] = result;
if overflow {
limbs[1] += 1;
}
}

// Remove trailing zeros, pad with zeros
Expand Down

0 comments on commit e88411b

Please sign in to comment.