From b61feff125ac93c02e6223341d8ac00dcaa7d02c Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 2 Mar 2020 19:01:27 +0300 Subject: [PATCH] Improve test coverage for detecting invalid pointers --- test/testbufferoverrun.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 964afaefa..2485a3292 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2813,6 +2813,13 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is 123 the pointer arithmetic 'x+i' is out of bounds.\n", errout.str()); + check("void f(int i) {\n" + " char x[10];\n" + " if (i == -1) {}\n" + " dostuff(x+i);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (portability) Undefined behaviour, when 'i' is -1 the pointer arithmetic 'x+i' is out of bounds.\n", errout.str()); + check("void f() {\n" // #6350 - fp when there is cast of buffer " wchar_t buf[64];\n" " p = (unsigned char *) buf + sizeof (buf);\n"