From 2bd60ab6c84fc2bdc86fee21a6662e43eeda2438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 22 Dec 2009 21:07:56 +0100 Subject: [PATCH] Fixed #1133 (Uninitialized array: strchr, strrchr, etc) --- lib/checkother.cpp | 4 ++-- test/testother.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0870d836b..5baa921cf 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1393,13 +1393,13 @@ private: if (Token::Match(&tok, "%var% (")) { // reading 1st parameter.. - if (Token::Match(&tok, "strcat|strncat|strlen ( %var%")) + if (Token::Match(&tok, "strcat|strncat|strchr|strrchr|strstr|strlen|strdup ( %var%")) { use_array(foundError, checks, tok.tokAt(2)); } // reading 2nd parameter.. - if (Token::Match(&tok, "strcpy ( %any% , %var% ) ") || + if (Token::Match(&tok, "strcpy|strstr ( %any% , %var% ) ") || Token::Match(&tok, "strncpy ( %any% , %var% ,")) { use_array(foundError, checks, tok.tokAt(4)); diff --git a/test/testother.cpp b/test/testother.cpp index 835edbe00..539c4d0fc 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1233,6 +1233,13 @@ private: "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char s[20];\n" + " strchr(s, ' ');\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str()); + checkUninitVar("void f()\n" "{\n" " char s[20];\n"