From 11da89784f10db2afc6005e8ee508a52e8ffe96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 22 Dec 2009 19:16:34 +0100 Subject: [PATCH] Eric Sesterhenn: Fixed #1130 (False positive uninitialized variable) --- lib/checkother.cpp | 3 ++- test/testother.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a664157ac..77ec55a7f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1399,7 +1399,8 @@ private: } // reading 2nd parameter.. - if (Token::Match(&tok, "strcpy|strncpy ( %any% , %var%")) + if (Token::Match(&tok, "strcpy ( %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 6bf53851e..77147a532 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1286,6 +1286,14 @@ private: " int x = a;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f(struct blame_entry *ent)\n" + "{\n" + " struct origin *suspect = ent->suspect;\n" + " char hex[41];\n" + " strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }