Skip to content

bigint add function cause Segmentation fault #10288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ksh8281 opened this issue Nov 5, 2013 · 5 comments
Closed

bigint add function cause Segmentation fault #10288

ksh8281 opened this issue Nov 5, 2013 · 5 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@ksh8281
Copy link
Contributor

ksh8281 commented Nov 5, 2013

i worked with rust(bf98981)

i try to use bigint module. but bigint.add function cause segfault in some cases.
the cases is below

extern mod extra;

use extra::bigint;
use extra::bigint::BigInt;
use extra::bigint::FromStr;
fn main() {
    let a:bigint::BigInt = FromStr::from_str("31").unwrap();
    let b:bigint::BigInt = FromStr::from_str("999999999999999999999999999999999999").unwrap();
    let c = (a+b).to_str();
    println(format!("{:?}",c));
}
@huonw
Copy link
Member

huonw commented Nov 8, 2013

@cmr has run this testcase on some months-old compilers, and it still crashes with them; so it looks like this has existed forever and isn't a (recent) regression. (Just as a general data point.)

@thestinger
Copy link
Contributor

This causes a failure for me:

task '<main>' failed at 'vector size is too large: 18446744073709551615', /build/rust-git/src/rust/src/libstd/vec.rs:191

@emberian
Copy link
Member

Aha, I must have fixed this with the check-for-overflow. I'll add tests for this.

@ghost ghost assigned emberian Nov 15, 2013
@huonw
Copy link
Member

huonw commented Nov 15, 2013

I don't think this is fixed, the fundamental problem of the bigint implementation of to_str being wrong is still there.

@emberian
Copy link
Member

@huonw I opened #10522 about fixing the overflow issues.

bors added a commit that referenced this issue Nov 17, 2013
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.
@huonw huonw closed this as completed in c8e6a38 Nov 17, 2013
Jarcho pushed a commit to Jarcho/rust that referenced this issue Feb 26, 2023
…ro_wrapper, r=llogiq

Add the `transmute_int_to_non_zero` lint

Fixes rust-lang#10288

This adds a new complexity lint `transmute_int_to_non_zero` which checks for transmutes to any of the `NonZero*` types, and suggests their `new_unchecked` method instead.

r? `@llogiq`

changelog: New lint: [`transmute_int_to_non_zero`]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants