Merge pull request #1145 from isaachier/bigint-neg-one-incr-fix

Fix bigint -1 increment operation
This commit is contained in:
Andrew Kelley 2018-06-21 13:40:37 -04:00 committed by GitHub
commit 47dd1049c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -1683,10 +1683,15 @@ void bigint_incr(BigInt *x) {
bigint_init_unsigned(x, 1);
return;
}
if (x->digit_count == 1 && x->data.digit != UINT64_MAX) {
x->data.digit += 1;
return;
if (x->digit_count == 1) {
if (x->is_negative && x->data.digit != 0) {
x->data.digit -= 1;
return;
} else if (!x->is_negative && x->data.digit != UINT64_MAX) {
x->data.digit += 1;
return;
}
}
BigInt copy;

View File

@ -13,6 +13,7 @@ comptime {
_ = @import("cases/bugs/656.zig");
_ = @import("cases/bugs/828.zig");
_ = @import("cases/bugs/920.zig");
_ = @import("cases/bugs/1111.zig");
_ = @import("cases/byval_arg_var.zig");
_ = @import("cases/cast.zig");
_ = @import("cases/const_slice_child.zig");

12
test/cases/bugs/1111.zig Normal file
View File

@ -0,0 +1,12 @@
const Foo = extern enum {
Bar = -1,
};
test "issue 1111 fixed" {
const v = Foo.Bar;
switch(v) {
Foo.Bar => return,
else => return,
}
}