Message refactorization: Changed expression "0-terminate" to "null-terminate" as discussed on 24b98feadb
This commit is contained in:
parent
1c399c86ca
commit
6122819832
|
@ -256,7 +256,7 @@ private:
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// mode 2 : reading array data with mem.. function. It's ok if the
|
// mode 2 : reading array data with mem.. function. It's ok if the
|
||||||
// array is not 0-terminated
|
// array is not null-terminated
|
||||||
if (mode == 2 && c->strncpy_)
|
if (mode == 2 && c->strncpy_)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reading array elements with a "mem.." function. It's ok if the array is not 0-terminated.
|
* Reading array elements with a "mem.." function. It's ok if the array is not null-terminated.
|
||||||
* @param checks all available checks
|
* @param checks all available checks
|
||||||
* @param tok variable token
|
* @param tok variable token
|
||||||
*/
|
*/
|
||||||
|
@ -640,7 +640,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// strncpy doesn't 0-terminate first parameter
|
// strncpy doesn't null-terminate first parameter
|
||||||
if (Token::Match(&tok, "strncpy ( %var% ,")) {
|
if (Token::Match(&tok, "strncpy ( %var% ,")) {
|
||||||
if (Token::Match(tok.tokAt(4), "%str% ,")) {
|
if (Token::Match(tok.tokAt(4), "%str% ,")) {
|
||||||
if (Token::Match(tok.tokAt(6), "%num% )")) {
|
if (Token::Match(tok.tokAt(6), "%num% )")) {
|
||||||
|
@ -1337,7 +1337,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer) const
|
||||||
|
|
||||||
void CheckUninitVar::uninitstringError(const Token *tok, const std::string &varname, bool strncpy_)
|
void CheckUninitVar::uninitstringError(const Token *tok, const std::string &varname, bool strncpy_)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "uninitstring", "Dangerous usage of '" + varname + "'" + (strncpy_ ? " (strncpy doesn't always 0-terminate it)." : " (not 0-terminated)."));
|
reportError(tok, Severity::error, "uninitstring", "Dangerous usage of '" + varname + "'" + (strncpy_ ? " (strncpy doesn't always null-terminate it)." : " (not null-terminated)."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckUninitVar::uninitdataError(const Token *tok, const std::string &varname)
|
void CheckUninitVar::uninitdataError(const Token *tok, const std::string &varname)
|
||||||
|
|
|
@ -43,8 +43,8 @@ private:
|
||||||
TEST_CASE(uninitvar_switch); // handling switch
|
TEST_CASE(uninitvar_switch); // handling switch
|
||||||
TEST_CASE(uninitvar_references); // references
|
TEST_CASE(uninitvar_references); // references
|
||||||
TEST_CASE(uninitvar_return); // return
|
TEST_CASE(uninitvar_return); // return
|
||||||
TEST_CASE(uninitvar_strncpy); // strncpy doesn't always 0-terminate
|
TEST_CASE(uninitvar_strncpy); // strncpy doesn't always null-terminate
|
||||||
TEST_CASE(uninitvar_memset); // not 0-terminated
|
TEST_CASE(uninitvar_memset); // not null-terminated
|
||||||
TEST_CASE(uninitvar_func); // analyse functions
|
TEST_CASE(uninitvar_func); // analyse functions
|
||||||
TEST_CASE(func_uninit_var); // analyse function calls for: 'int a(int x) { return x+x; }'
|
TEST_CASE(func_uninit_var); // analyse function calls for: 'int a(int x) { return x+x; }'
|
||||||
TEST_CASE(func_uninit_pointer); // analyse function calls for: 'void a(int *p) { *p = 0; }'
|
TEST_CASE(func_uninit_pointer); // analyse function calls for: 'void a(int *p) { *p = 0; }'
|
||||||
|
@ -1564,7 +1564,7 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// strncpy doesn't always 0-terminate..
|
// strncpy doesn't always null-terminate..
|
||||||
void uninitvar_strncpy() {
|
void uninitvar_strncpy() {
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1572,7 +1572,7 @@ private:
|
||||||
" strncpy(a, s, 20);\n"
|
" strncpy(a, s, 20);\n"
|
||||||
" strncat(a, s, 20);\n"
|
" strncat(a, s, 20);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1580,7 +1580,7 @@ private:
|
||||||
" strncpy(a, \"hello\", 3);\n"
|
" strncpy(a, \"hello\", 3);\n"
|
||||||
" strncat(a, \"world\", 20);\n"
|
" strncat(a, \"world\", 20);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always 0-terminate it).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of 'a' (strncpy doesn't always null-terminate it).\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("void f()\n"
|
checkUninitVar("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1623,7 +1623,7 @@ private:
|
||||||
" memset(a, 'a', 20);\n"
|
" memset(a, 'a', 20);\n"
|
||||||
" strcat(a, s);\n"
|
" strcat(a, s);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not 0-terminated).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not null-terminated).\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string analyseFunctions(const char code[]) {
|
std::string analyseFunctions(const char code[]) {
|
||||||
|
|
Loading…
Reference in New Issue