This commit is contained in:
parent
eebd1393ff
commit
5b5ea29f23
|
@ -1226,6 +1226,12 @@ void CheckOther::invalidScanfError(const Token *tok)
|
||||||
|
|
||||||
void CheckOther::checkWrongPrintfScanfArguments()
|
void CheckOther::checkWrongPrintfScanfArguments()
|
||||||
{
|
{
|
||||||
|
// This check is experimental. See #3311, #3313, #3339
|
||||||
|
// TODO : fix tickets and remove this condition. When the condition
|
||||||
|
// is removed the classInfo and getErrorMessages must be updated
|
||||||
|
if (!_settings->experimental)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!_settings->isEnabled("style"))
|
if (!_settings->isEnabled("style"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ public:
|
||||||
c.bitwiseOnBooleanError(0, "varname", "&&");
|
c.bitwiseOnBooleanError(0, "varname", "&&");
|
||||||
c.comparisonOfBoolExpressionWithIntError(0);
|
c.comparisonOfBoolExpressionWithIntError(0);
|
||||||
c.SuspiciousSemicolonError(0);
|
c.SuspiciousSemicolonError(0);
|
||||||
c.wrongPrintfScanfArgumentsError(0,"printf",3,2);
|
//c.wrongPrintfScanfArgumentsError(0,"printf",3,2);
|
||||||
c.cctypefunctionCallError(0, "funname", "value");
|
c.cctypefunctionCallError(0, "funname", "value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ public:
|
||||||
"* sizeof for numeric given as function argument\n"
|
"* sizeof for numeric given as function argument\n"
|
||||||
"* incorrect length arguments for 'substr' and 'strncmp'\n"
|
"* incorrect length arguments for 'substr' and 'strncmp'\n"
|
||||||
"* invalid usage of output stream. For example: std::cout << std::cout;'\n"
|
"* invalid usage of output stream. For example: std::cout << std::cout;'\n"
|
||||||
"* wrong number of arguments given to 'printf' or 'scanf;'\n"
|
//"* wrong number of arguments given to 'printf' or 'scanf;'\n"
|
||||||
|
|
||||||
// style
|
// style
|
||||||
"* C-style pointer cast in cpp file\n"
|
"* C-style pointer cast in cpp file\n"
|
||||||
|
|
|
@ -151,13 +151,14 @@ private:
|
||||||
TEST_CASE(checkForSuspiciousSemicolon2);
|
TEST_CASE(checkForSuspiciousSemicolon2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const char code[], const char *filename = NULL) {
|
void check(const char code[], const char *filename = NULL, bool experimental = false) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.addEnabled("style");
|
settings.addEnabled("style");
|
||||||
settings.inconclusive = true;
|
settings.inconclusive = true;
|
||||||
|
settings.experimental = experimental;
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
|
@ -1897,7 +1898,9 @@ private:
|
||||||
" b = fscanf(file, \"aa%%ds\", &a);\n"
|
" b = fscanf(file, \"aa%%ds\", &a);\n"
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n"
|
ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n"
|
||||||
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n"
|
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n"
|
||||||
"[test.cpp:8]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
"[test.cpp:8]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
||||||
|
@ -1914,7 +1917,9 @@ private:
|
||||||
" b = fscanf(file, \"aa%%ds\", &a);\n"
|
" b = fscanf(file, \"aa%%ds\", &a);\n"
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true);
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n"
|
ASSERT_EQUALS("[test.cpp:6]: (warning) scanf without field width limits can crash with huge input data\n"
|
||||||
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n"
|
"[test.cpp:7]: (warning) scanf without field width limits can crash with huge input data\n"
|
||||||
"[test.cpp:8]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
"[test.cpp:8]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
||||||
|
@ -1930,7 +1935,9 @@ private:
|
||||||
" c = fscanf(file, \"%[^ ] %d\n\", a, &b);\n"
|
" c = fscanf(file, \"%[^ ] %d\n\", a, &b);\n"
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return c;\n"
|
" return c;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("#include <stdio.h>\n"
|
check("#include <stdio.h>\n"
|
||||||
|
@ -1942,7 +1949,9 @@ private:
|
||||||
" b = fscanf(file, \"%[^ \n\", a);\n"
|
" b = fscanf(file, \"%[^ \n\", a);\n"
|
||||||
" fclose(file);\n"
|
" fclose(file);\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n");
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true);
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (warning) fscanf format string has 0 parameters but 1 are given\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1955,7 +1964,9 @@ private:
|
||||||
" printf(\"%udfd%%dfa%s%d\", 0, bar());\n"
|
" printf(\"%udfd%%dfa%s%d\", 0, bar());\n"
|
||||||
" fprintf(stderr,\"%u%s\");\n"
|
" fprintf(stderr,\"%u%s\");\n"
|
||||||
" snprintf(str,10,\"%u%s\");\n"
|
" snprintf(str,10,\"%u%s\");\n"
|
||||||
"}\n"
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) printf format string has 1 parameters but only 0 are given\n"
|
ASSERT_EQUALS("[test.cpp:2]: (error) printf format string has 1 parameters but only 0 are given\n"
|
||||||
"[test.cpp:3]: (error) printf format string has 2 parameters but only 1 are given\n"
|
"[test.cpp:3]: (error) printf format string has 2 parameters but only 1 are given\n"
|
||||||
|
@ -1969,7 +1980,9 @@ private:
|
||||||
" printf(\"\", 0);\n"
|
" printf(\"\", 0);\n"
|
||||||
" printf(\"%u\", 123, bar());\n"
|
" printf(\"%u\", 123, bar());\n"
|
||||||
" printf(\"%u%s\", 0, bar(), 43123);\n"
|
" printf(\"%u%s\", 0, bar(), 43123);\n"
|
||||||
"}\n"
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) printf format string has 0 parameters but 1 are given\n"
|
ASSERT_EQUALS("[test.cpp:2]: (warning) printf format string has 0 parameters but 1 are given\n"
|
||||||
"[test.cpp:3]: (warning) printf format string has 1 parameters but 2 are given\n"
|
"[test.cpp:3]: (warning) printf format string has 1 parameters but 2 are given\n"
|
||||||
|
@ -1984,7 +1997,9 @@ private:
|
||||||
" printf(\"%\"PRId64\"\n\", 123);\n"
|
" printf(\"%\"PRId64\"\n\", 123);\n"
|
||||||
" fprintf(stderr,\"%\"PRId64\"\n\", 123);\n"
|
" fprintf(stderr,\"%\"PRId64\"\n\", 123);\n"
|
||||||
" snprintf(str,10,\"%\"PRId64\"\n\", 123);\n"
|
" snprintf(str,10,\"%\"PRId64\"\n\", 123);\n"
|
||||||
"}\n"
|
"}\n",
|
||||||
|
"test.cpp",
|
||||||
|
true
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue