Fixed a few cppcheck messages

This commit is contained in:
PKEuS 2014-03-28 18:55:16 +01:00
parent 4e19645d62
commit a01bfcb62d
5 changed files with 14 additions and 14 deletions

View File

@ -182,7 +182,7 @@ void CheckIO::checkFileUsage()
operation = Filepointer::OPEN; operation = Filepointer::OPEN;
} else if ((tok->str() == "rewind" || tok->str() == "fseek" || tok->str() == "fsetpos" || tok->str() == "fflush") || } else if ((tok->str() == "rewind" || tok->str() == "fseek" || tok->str() == "fsetpos" || tok->str() == "fflush") ||
(windows && tok->str() == "_fseeki64")) { (windows && tok->str() == "_fseeki64")) {
if (Token::simpleMatch(tok, "fflush ( stdin )")) if (Token::simpleMatch(tok, "fflush ( stdin )") && !_settings->standards.posix)
fflushOnInputStreamError(tok, tok->strAt(2)); fflushOnInputStreamError(tok, tok->strAt(2));
else { else {
fileTok = tok->tokAt(2); fileTok = tok->tokAt(2);
@ -667,7 +667,7 @@ void CheckIO::checkWrongPrintfScanfArguments()
invalidScanfFormatWidthError(tok, numFormat, numWidth, argInfo.variableInfo); invalidScanfFormatWidthError(tok, numFormat, numWidth, argInfo.variableInfo);
} }
} }
if (argListTok->type() != Token::eString && if (argListTok && argListTok->type() != Token::eString &&
argInfo.isKnownType() && argInfo.isArrayOrPointer() && argInfo.isKnownType() && argInfo.isArrayOrPointer() &&
(!Token::Match(argInfo.typeToken, "char|wchar_t") || (!Token::Match(argInfo.typeToken, "char|wchar_t") ||
argInfo.typeToken->strAt(-1) == "const")) { argInfo.typeToken->strAt(-1) == "const")) {

View File

@ -788,7 +788,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
} }
// init function (global variables) // init function (global variables)
if (!var || !(var->isLocal() || var->isArgument())) if (!(var->isLocal() || var->isArgument()))
break; break;
} }

View File

@ -37,7 +37,7 @@ private:
TEST_CASE(resource); TEST_CASE(resource);
} }
void empty() { void empty() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>"; const char xmldata[] = "<?xml version=\"1.0\"?>\n<def/>";
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
doc.Parse(xmldata, sizeof(xmldata)); doc.Parse(xmldata, sizeof(xmldata));
@ -49,7 +49,7 @@ private:
ASSERT(library.argumentChecks.empty()); ASSERT(library.argumentChecks.empty());
} }
void function() { void function() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
" <function name=\"foo\">\n" " <function name=\"foo\">\n"
@ -67,7 +67,7 @@ private:
ASSERT(library.isnotnoreturn("foo")); ASSERT(library.isnotnoreturn("foo"));
} }
void function_arg() { void function_arg() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
" <function name=\"foo\">\n" " <function name=\"foo\">\n"
@ -92,7 +92,7 @@ private:
ASSERT_EQUALS(true, library.argumentChecks["foo"][6].notbool); ASSERT_EQUALS(true, library.argumentChecks["foo"][6].notbool);
} }
void function_arg_any() { void function_arg_any() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
"<function name=\"foo\">\n" "<function name=\"foo\">\n"
@ -107,7 +107,7 @@ private:
ASSERT_EQUALS(true, library.argumentChecks["foo"][-1].notuninit); ASSERT_EQUALS(true, library.argumentChecks["foo"][-1].notuninit);
} }
void memory() { void memory() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
" <memory>\n" " <memory>\n"
@ -128,7 +128,7 @@ private:
ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX")); ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX"));
} }
void resource() { void resource() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n" const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n" "<def>\n"
" <resource>\n" " <resource>\n"

View File

@ -325,7 +325,7 @@ private:
ASSERT_EQUALS(false, MathLib::isInt("")); ASSERT_EQUALS(false, MathLib::isInt(""));
} }
void isbin() { void isbin() const {
// positive testing // positive testing
ASSERT_EQUALS(true, MathLib::isBin("0b0")); ASSERT_EQUALS(true, MathLib::isBin("0b0"));
ASSERT_EQUALS(true, MathLib::isBin("0b1")); ASSERT_EQUALS(true, MathLib::isBin("0b1"));
@ -381,7 +381,7 @@ private:
ASSERT_EQUALS(false, MathLib::isNegative("")); ASSERT_EQUALS(false, MathLib::isNegative(""));
} }
void isoct() { void isoct() const {
// octal number format: [+|-]0[0-7][suffix] // octal number format: [+|-]0[0-7][suffix]
// positive testing // positive testing
ASSERT_EQUALS(true, MathLib::isOct("010")); ASSERT_EQUALS(true, MathLib::isOct("010"));
@ -442,7 +442,7 @@ private:
ASSERT_EQUALS(false, MathLib::isOct(" -042ULL ")); ASSERT_EQUALS(false, MathLib::isOct(" -042ULL "));
} }
void ishex() { void ishex() const {
// hex number syntax: [sign]0x[hexnumbers][suffix] // hex number syntax: [sign]0x[hexnumbers][suffix]
// positive testing // positive testing
@ -592,7 +592,7 @@ private:
ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1")); ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1"));
} }
void naninf() { void naninf() const {
ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.0")); // nan ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.0")); // nan
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142) ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)

View File

@ -2622,7 +2622,7 @@ private:
// expand macros.. // expand macros..
errout.str(""); errout.str("");
const std::string actual(OurPreprocessor::expandMacros(filedata, this)); OurPreprocessor::expandMacros(filedata, this);
ASSERT_EQUALS("[file.cpp:7]: (error) No pair for character (\"). Can't process file. File is either invalid or unicode, which is currently not supported.\n", errout.str()); ASSERT_EQUALS("[file.cpp:7]: (error) No pair for character (\"). Can't process file. File is either invalid or unicode, which is currently not supported.\n", errout.str());
} }