Uninitialized variables: Fixed false 'dangerous usage of strncpy' positive when resulting string is used by strncpy
This commit is contained in:
parent
70c4bb54b4
commit
ba5558748d
|
@ -593,9 +593,17 @@ private:
|
||||||
std::list<const Token *> var;
|
std::list<const Token *> var;
|
||||||
CheckNullPointer::parseFunctionCall(tok, var, 1);
|
CheckNullPointer::parseFunctionCall(tok, var, 1);
|
||||||
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it) {
|
for (std::list<const Token *>::const_iterator it = var.begin(); it != var.end(); ++it) {
|
||||||
|
// does iterator point at first function parameter?
|
||||||
|
const bool firstPar(*it == tok.tokAt(2));
|
||||||
|
|
||||||
// is function memset/memcpy/etc?
|
// is function memset/memcpy/etc?
|
||||||
if (tok.str().compare(0,3,"mem") == 0)
|
if (tok.str().compare(0,3,"mem") == 0)
|
||||||
use_array_mem(checks, *it);
|
use_array_mem(checks, *it);
|
||||||
|
|
||||||
|
// second parameter for strncpy/strncat/etc
|
||||||
|
else if (!firstPar && tok.str().compare(0,4,"strn") == 0)
|
||||||
|
use_array_mem(checks, *it);
|
||||||
|
|
||||||
else
|
else
|
||||||
use_array(checks, *it);
|
use_array(checks, *it);
|
||||||
|
|
||||||
|
|
|
@ -1374,6 +1374,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Using strncpy isn't necessarily dangerous usage
|
||||||
|
checkUninitVar("void f(const char dev[], char *str) {\n"
|
||||||
|
" char buf[10];\n"
|
||||||
|
" strncpy(buf, dev, 10);\n"
|
||||||
|
" strncpy(str, buf, 10);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialization with memset (not 0-terminating string)..
|
// initialization with memset (not 0-terminating string)..
|
||||||
|
|
Loading…
Reference in New Issue