From 0becff9d7f2bc7c246f0fed8ba20f1303506b534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 9 Jan 2020 10:48:43 +0100 Subject: [PATCH] testsuites/danmar-verify: Add divbyzero tests --- test/testsuites/danmar-verify/divbyzero.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testsuites/danmar-verify/divbyzero.cpp b/test/testsuites/danmar-verify/divbyzero.cpp index fa408b3ec..10e0657fc 100644 --- a/test/testsuites/danmar-verify/divbyzero.cpp +++ b/test/testsuites/danmar-verify/divbyzero.cpp @@ -6,6 +6,8 @@ struct S { int x; }; int globalvar; +void dostuff(); + void callfunc1() { int x = 16; scanf("%i\n", &x); @@ -33,6 +35,13 @@ void globalVar1() { return 100000 / globalvar; } +void globalVar1() { + globalvar = 123; + dostuff(); + // cppcheck-suppress verificationDivByZero + return 100000 / globalvar; +} + void pointer1(int *p) { // cppcheck-suppress verificationDivByZero return 100000 / *p; @@ -52,3 +61,13 @@ void struct1(struct S *s) { // cppcheck-suppress verificationDivByZero return 100000 / s->x; } + +void trycatch() { + int x = 0; + try { + dostuff(); + x = 1; + } catch (...) {} + // cppcheck-suppress verificationDivByZero + return 100000 / x; +}