Fixed #4380
This commit is contained in:
parent
ed477ceb74
commit
096fa2f771
|
@ -1224,7 +1224,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Token::Match(tok, "strncpy|strncat ( %varid% , %var%", arrayInfo.varid()) && Token::Match(tok->linkAt(1)->tokAt(-2), ", %num% )"))) {
|
if ((Token::Match(tok, "strncpy|strncat ( %varid% ,", arrayInfo.varid()) && Token::Match(tok->linkAt(1)->tokAt(-2), ", %num% )"))) {
|
||||||
const Token* param3 = tok->linkAt(1)->previous();
|
const Token* param3 = tok->linkAt(1)->previous();
|
||||||
|
|
||||||
// check for strncpy which is not terminated
|
// check for strncpy which is not terminated
|
||||||
|
|
|
@ -195,6 +195,7 @@ private:
|
||||||
TEST_CASE(strncat1);
|
TEST_CASE(strncat1);
|
||||||
TEST_CASE(strncat2);
|
TEST_CASE(strncat2);
|
||||||
TEST_CASE(strncat3);
|
TEST_CASE(strncat3);
|
||||||
|
TEST_CASE(strncat4);
|
||||||
|
|
||||||
TEST_CASE(strcat1);
|
TEST_CASE(strcat1);
|
||||||
TEST_CASE(strcat2);
|
TEST_CASE(strcat2);
|
||||||
|
@ -3140,6 +3141,14 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: x.a\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: x.a\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strncat4() {
|
||||||
|
check("void f(char *a) {\n"
|
||||||
|
" char str[5];\n"
|
||||||
|
" strncat(str, \"foobar\", 5);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void strcat1() {
|
void strcat1() {
|
||||||
check("struct Foo { char a[4]; };\n"
|
check("struct Foo { char a[4]; };\n"
|
||||||
|
|
Loading…
Reference in New Issue