diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-05-05 18:07:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-05-05 18:07:15 -0700 |
| commit | b8d17b11a7eba696200ab9b5819121f48ad123d1 (patch) | |
| tree | 364b74d0554e4f1d37b9d5d927695e409244cd21 /test/run_tests.cpp | |
| parent | 094336f07cdf42f2f79df5b190ccc0139412cfbc (diff) | |
| download | zig-b8d17b11a7eba696200ab9b5819121f48ad123d1.tar.gz zig-b8d17b11a7eba696200ab9b5819121f48ad123d1.zip | |
add tests for integer overflow crashing
see #46
Diffstat (limited to 'test/run_tests.cpp')
| -rw-r--r-- | test/run_tests.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 9d5861d9e5..6c898533cb 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1323,6 +1323,46 @@ fn bar(a: []i32) -> i32 { fn baz(a: i32) {} )SOURCE"); + add_debug_safety_case("integer addition overflow", R"SOURCE( +pub fn main(args: [][]u8) -> %void { + add(65530, 10); +} +#static_eval_enable(false) +fn add(a: u16, b: u16) -> u16 { + a + b +} + )SOURCE"); + + add_debug_safety_case("integer subtraction overflow", R"SOURCE( +pub fn main(args: [][]u8) -> %void { + sub(10, 20); +} +#static_eval_enable(false) +fn sub(a: u16, b: u16) -> u16 { + a - b +} + )SOURCE"); + + add_debug_safety_case("integer multiplication overflow", R"SOURCE( +pub fn main(args: [][]u8) -> %void { + mul(300, 6000); +} +#static_eval_enable(false) +fn mul(a: u16, b: u16) -> u16 { + a * b +} + )SOURCE"); + + add_debug_safety_case("integer negation overflow", R"SOURCE( +pub fn main(args: [][]u8) -> %void { + neg(-32768); +} +#static_eval_enable(false) +fn neg(a: i16) -> i16 { + -a +} + )SOURCE"); + } ////////////////////////////////////////////////////////////////////////////// |
