From 64a7ba3c4c01cf912dfe8617a94cbe6d00667523 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 6 Apr 2022 08:12:41 +0200 Subject: [PATCH] Added regression test for #8332. --- test/teststring.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/teststring.cpp b/test/teststring.cpp index 9323b0b0b..36ea2bf00 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -134,6 +134,16 @@ private: " abc[0] = 'a';\n" "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Modifying string literal u\"abc\" directly or indirectly is undefined behaviour.\n", errout.str()); + + check("void foo() {\n" // #8332 + " int i;\n" + " char *p = \"string literal\";\n" + " for( i = 0; i < strlen(p); i++) {\n" + " p[i] = \'X\';\n" // << + " }\n" + " printf(\"%s\\n\", p);\n" + "}"); + ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (error) Modifying string literal \"string literal\" directly or indirectly is undefined behaviour.\n", errout.str()); } void alwaysTrueFalseStringCompare() {