From 33fde8ae6b5f2d8a6fa3241cf9e7ff84c50443bb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 29 Sep 2022 12:33:34 +0200 Subject: [PATCH] Add tests for #1770, #10130 (#4519) * Add test for #6541, avoid duplicate warning * Add test for #5475 * Fix test * Merge * Add test for #8666 * Fix #11239 checkLibraryCheckType with asm goto() (invalid varid) * Format * Add tests for #1201, #2654 * Fix test * Add test for #6379 * Add tests for #1770, #10130 --- test/testbufferoverrun.cpp | 10 ++++++++++ test/testfunctions.cpp | 3 +++ 2 files changed, 13 insertions(+) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5e488e756..50b390961 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2612,6 +2612,16 @@ private: "ImageSet *ActorSprite::targetCursorImages[2][10];"); ASSERT_EQUALS("", errout.str()); + check("int f(const std::size_t s) {\n" // #10130 + " const char a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\n" + " return (s > sizeof(a)) ? 11 : (int)a[s];\n" + "}\n" + "int g() {\n" + " return f(16);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (warning) Either the condition 's>sizeof(a)' is redundant or the array 'a[16]' is accessed at index 16, which is out of bounds.\n", + errout.str()); + } void array_index_valueflow_pointer() { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 1c361d759..a23e12382 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -763,6 +763,9 @@ private: check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str()); + + check("void f() { char a[10] = \"1234567890\"; puts(a); }", "test.c"); // #1770 + ASSERT_EQUALS("[test.c:1]: (error) Invalid puts() argument nr 1. A nul-terminated string is required.\n", errout.str()); } void mathfunctionCall_sqrt() {