diff options
| author | bors <bors@rust-lang.org> | 2013-11-17 07:32:13 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-17 07:32:13 -0800 |
| commit | e0943504e4d4c42342cb7c0fa24895f991b01ca8 (patch) | |
| tree | ea862d2329f196894b36f3dc35127e7487de2e0f | |
| parent | 5208332a1a0cc2d07d52c117a6abe7e2c8c1f36e (diff) | |
| parent | c8e6a38693d73e06e59c69fbd40c3924836a10e9 (diff) | |
| download | rust-e0943504e4d4c42342cb7c0fa24895f991b01ca8.tar.gz rust-e0943504e4d4c42342cb7c0fa24895f991b01ca8.zip | |
auto merge of #10523 : huonw/rust/10522, r=cmr
If any of the digits was one past the maximum (e.g. 10**9 for base 10), then this wasn't detected correctly and so the length of the digit was one more than expected, causing a very large allocation. Fixes #10522. Fixes #10288.
| -rw-r--r-- | src/libextra/num/bigint.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index cd5ccc14caf..b79c2bd5cb5 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -660,7 +660,7 @@ impl ToStrRadix for BigUint { let divider = FromPrimitive::from_uint(base).unwrap(); let mut result = ~[]; let mut m = n; - while m > divider { + while m >= divider { let (d, m0) = m.div_mod_floor(÷r); result.push(m0.to_uint().unwrap() as BigDigit); m = d; @@ -2520,6 +2520,11 @@ mod bigint_tests { check("-10", Some(-10)); check("Z", None); check("_", None); + + // issue 10522, this hit an edge case that caused it to + // attempt to allocate a vector of size (-1u) == huge. + let x: BigInt = from_str("1" + "0".repeat(36)).unwrap(); + let _y = x.to_str(); } #[test] |
