From 781ef2acadf70ab05c983eff74811092d0cabaeb Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 26 Jun 2024 20:36:06 +0200 Subject: [PATCH] Added test for #11175 - FN: zerodiv (#6550) Reference: https://trac.cppcheck.net/ticket/11175 --- test/testother.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index d71fd173d63..018806a87d0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -58,6 +58,7 @@ class TestOther : public TestFixture { TEST_CASE(zeroDiv17); // #9931 TEST_CASE(zeroDiv18); TEST_CASE(zeroDiv19); + TEST_CASE(zeroDiv20); // #11175 TEST_CASE(zeroDivCond); // division by zero / useless condition @@ -661,6 +662,16 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout_str()); } + void zeroDiv20() + { + check("uint16_t f(void)\n" // #11175 + "{\n" + " uint16_t x = 0xFFFFU;\n" // UINT16_MAX=0xFFFF + " return 42/(++x);\n" + "}"); + ASSERT_EQUALS("[test.cpp:4]: (error) Division by zero.\n", errout_str()); + } + void zeroDivCond() { check("void f(unsigned int x) {\n" " int y = 17 / x;\n"