diff --git a/Makefile b/Makefile index 9e74ff9f6..7c0dce148 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CXXFLAGS=-Wall -Wextra -Wshadow -pedantic -Wno-long-long -Wfloat-equal -Wcast-qual -g -D_GLIBCXX_DEBUG +CXXFLAGS=-Wall -Wextra -Wshadow -pedantic -Wno-long-long -Wfloat-equal -Wcast-qual -Wsign-conversion -g -D_GLIBCXX_DEBUG CXX=g++ BIN=${DESTDIR}/usr/bin @@ -98,34 +98,34 @@ install: cppcheck ###### Build -lib/checkautovariables.o: lib/checkautovariables.cpp lib/checkautovariables.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkautovariables.o: lib/checkautovariables.cpp lib/checkautovariables.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkautovariables.o lib/checkautovariables.cpp -lib/checkbufferoverrun.o: lib/checkbufferoverrun.cpp lib/checkbufferoverrun.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h +lib/checkbufferoverrun.o: lib/checkbufferoverrun.cpp lib/checkbufferoverrun.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkbufferoverrun.o lib/checkbufferoverrun.cpp -lib/checkclass.o: lib/checkclass.cpp lib/checkclass.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkclass.o: lib/checkclass.cpp lib/checkclass.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkclass.o lib/checkclass.cpp -lib/checkdangerousfunctions.o: lib/checkdangerousfunctions.cpp lib/checkdangerousfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkdangerousfunctions.o: lib/checkdangerousfunctions.cpp lib/checkdangerousfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkdangerousfunctions.o lib/checkdangerousfunctions.cpp -lib/checkexceptionsafety.o: lib/checkexceptionsafety.cpp lib/checkexceptionsafety.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkexceptionsafety.o: lib/checkexceptionsafety.cpp lib/checkexceptionsafety.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkexceptionsafety.o lib/checkexceptionsafety.cpp -lib/checkmemoryleak.o: lib/checkmemoryleak.cpp lib/checkmemoryleak.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h +lib/checkmemoryleak.o: lib/checkmemoryleak.cpp lib/checkmemoryleak.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkmemoryleak.o lib/checkmemoryleak.cpp -lib/checkother.o: lib/checkother.cpp lib/checkother.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h +lib/checkother.o: lib/checkother.cpp lib/checkother.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkother.o lib/checkother.cpp -lib/checkstl.o: lib/checkstl.cpp lib/checkstl.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkstl.o: lib/checkstl.cpp lib/checkstl.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkstl.o lib/checkstl.cpp -lib/checkunusedfunctions.o: lib/checkunusedfunctions.cpp lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h +lib/checkunusedfunctions.o: lib/checkunusedfunctions.cpp lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/settings.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkunusedfunctions.o lib/checkunusedfunctions.cpp -lib/cppcheck.o: lib/cppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/preprocessor.h lib/filelister.h lib/path.h +lib/cppcheck.o: lib/cppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h lib/preprocessor.h lib/filelister.h lib/path.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/cppcheck.o lib/cppcheck.cpp lib/errorlogger.o: lib/errorlogger.cpp lib/errorlogger.h lib/path.h @@ -143,79 +143,79 @@ lib/filelister_unix.o: lib/filelister_unix.cpp lib/filelister.h lib/filelister_u lib/filelister_win32.o: lib/filelister_win32.cpp lib/filelister.h lib/filelister_win32.h lib/path.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/filelister_win32.o lib/filelister_win32.cpp -lib/mathlib.o: lib/mathlib.cpp lib/mathlib.h lib/tokenize.h +lib/mathlib.o: lib/mathlib.cpp lib/mathlib.h lib/tokenize.h lib/classinfo.h lib/token.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/mathlib.o lib/mathlib.cpp lib/path.o: lib/path.cpp lib/path.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/path.o lib/path.cpp -lib/preprocessor.o: lib/preprocessor.cpp lib/preprocessor.h lib/tokenize.h lib/token.h lib/filelister.h lib/path.h lib/errorlogger.h lib/settings.h +lib/preprocessor.o: lib/preprocessor.cpp lib/preprocessor.h lib/tokenize.h lib/classinfo.h lib/token.h lib/filelister.h lib/path.h lib/errorlogger.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/preprocessor.o lib/preprocessor.cpp lib/settings.o: lib/settings.cpp lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/settings.o lib/settings.cpp -lib/token.o: lib/token.cpp lib/token.h lib/errorlogger.h lib/check.h lib/tokenize.h lib/settings.h +lib/token.o: lib/token.cpp lib/token.h lib/errorlogger.h lib/check.h lib/tokenize.h lib/classinfo.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/token.o lib/token.cpp -lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/token.h lib/filelister.h lib/mathlib.h lib/settings.h lib/errorlogger.h lib/check.h lib/classinfo.h +lib/tokenize.o: lib/tokenize.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/filelister.h lib/mathlib.h lib/settings.h lib/errorlogger.h lib/check.h $(CXX) $(CXXFLAGS) -Ilib -c -o lib/tokenize.o lib/tokenize.cpp -cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h cli/threadexecutor.h +cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h cli/threadexecutor.h $(CXX) $(CXXFLAGS) -Ilib -c -o cli/cppcheckexecutor.o cli/cppcheckexecutor.cpp cli/main.o: cli/main.cpp cli/cppcheckexecutor.h lib/errorlogger.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -c -o cli/main.o cli/main.cpp -cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h +cli/threadexecutor.o: cli/threadexecutor.cpp cli/threadexecutor.h lib/settings.h lib/errorlogger.h lib/cppcheck.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h $(CXX) $(CXXFLAGS) -Ilib -c -o cli/threadexecutor.o cli/threadexecutor.cpp -test/testautovariables.o: test/testautovariables.cpp lib/tokenize.h lib/checkautovariables.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testautovariables.o: test/testautovariables.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkautovariables.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testautovariables.o test/testautovariables.cpp -test/testbufferoverrun.o: test/testbufferoverrun.cpp lib/tokenize.h lib/checkbufferoverrun.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testbufferoverrun.o: test/testbufferoverrun.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkbufferoverrun.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testbufferoverrun.o test/testbufferoverrun.cpp -test/testcharvar.o: test/testcharvar.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testcharvar.o: test/testcharvar.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testcharvar.o test/testcharvar.cpp -test/testclass.o: test/testclass.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testclass.o: test/testclass.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkclass.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testclass.o test/testclass.cpp -test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkclass.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testconstructors.o test/testconstructors.cpp -test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h lib/path.h test/tinyxml/tinyxml.h test/tinyxml/tinystr.h +test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h lib/path.h test/tinyxml/tinyxml.h test/tinyxml/tinystr.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testcppcheck.o test/testcppcheck.cpp -test/testdangerousfunctions.o: test/testdangerousfunctions.cpp lib/tokenize.h lib/checkdangerousfunctions.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testdangerousfunctions.o: test/testdangerousfunctions.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkdangerousfunctions.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testdangerousfunctions.o test/testdangerousfunctions.cpp -test/testdivision.o: test/testdivision.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testdivision.o: test/testdivision.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testdivision.o test/testdivision.cpp -test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/checkexceptionsafety.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkexceptionsafety.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp test/testfilelister.o: test/testfilelister.cpp test/testsuite.h lib/errorlogger.h lib/filelister_win32.h lib/filelister.h lib/filelister_unix.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testfilelister.o test/testfilelister.cpp -test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h +test/testincompletestatement.o: test/testincompletestatement.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testincompletestatement.o test/testincompletestatement.cpp test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h test/testsuite.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testmathlib.o test/testmathlib.cpp -test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/checkmemoryleak.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkmemoryleak.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testmemleak.o test/testmemleak.cpp -test/testother.o: test/testother.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testother.o: test/testother.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testother.o test/testother.cpp -test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h lib/preprocessor.h lib/tokenize.h lib/token.h lib/settings.h +test/testpreprocessor.o: test/testpreprocessor.cpp test/testsuite.h lib/errorlogger.h lib/preprocessor.h lib/tokenize.h lib/classinfo.h lib/token.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testpreprocessor.o test/testpreprocessor.cpp -test/testredundantif.o: test/testredundantif.cpp lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testredundantif.o: test/testredundantif.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testredundantif.o test/testredundantif.cpp test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h @@ -224,31 +224,31 @@ test/testrunner.o: test/testrunner.cpp test/testsuite.h lib/errorlogger.h test/testsettings.o: test/testsettings.cpp lib/settings.h test/testsuite.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsettings.o test/testsettings.cpp -test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/token.h lib/settings.h +test/testsimplifytokens.o: test/testsimplifytokens.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/classinfo.h lib/token.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsimplifytokens.o test/testsimplifytokens.cpp -test/teststl.o: test/teststl.cpp lib/tokenize.h lib/checkstl.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/teststl.o: test/teststl.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkstl.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/teststl.o test/teststl.cpp test/testsuite.o: test/testsuite.cpp test/testsuite.h lib/errorlogger.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testsuite.o test/testsuite.cpp -test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h test/testsuite.h +test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp -test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/token.h +test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/classinfo.h lib/token.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testtoken.o test/testtoken.cpp -test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/token.h lib/classinfo.h lib/settings.h +test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/classinfo.h lib/token.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testtokenize.o test/testtokenize.cpp -test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/settings.h +test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h lib/classinfo.h lib/token.h test/testsuite.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedfunctions.o test/testunusedfunctions.cpp -test/testunusedprivfunc.o: test/testunusedprivfunc.cpp lib/tokenize.h lib/checkclass.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h +test/testunusedprivfunc.o: test/testunusedprivfunc.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkclass.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedprivfunc.o test/testunusedprivfunc.cpp -test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/checkother.h lib/check.h lib/token.h lib/settings.h +test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h lib/settings.h $(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedvar.o test/testunusedvar.cpp test/tinyxml/tinystr.o: test/tinyxml/tinystr.cpp test/tinyxml/tinystr.h diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 97f9ecfdc..520ed16a4 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -61,7 +61,7 @@ void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, int size, int i } } -void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index) +void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index) { std::ostringstream oss; oss << "Array '" << arrayInfo.varname; @@ -80,7 +80,7 @@ void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok, const ArrayInfo reportError(tok, Severity::error, "arrayIndexOutOfBounds", oss.str().c_str()); } -void CheckBufferOverrun::arrayIndexOutOfBounds(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index) +void CheckBufferOverrun::arrayIndexOutOfBounds(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index) { std::ostringstream oss; oss << "Array '" << arrayInfo.varname; @@ -586,17 +586,17 @@ void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, c { if (Token::Match(ftok->previous(), "[=+-*/;{}] %var% [ %num% ]")) { - unsigned long index = MathLib::toLongNumber(ftok->strAt(2)); + long index = MathLib::toLongNumber(ftok->strAt(2)); if (index >= arrayInfo.num[0]) { std::list callstack; callstack.push_back(&tok); callstack.push_back(ftok); - std::vector ints; - ints.push_back(index); + std::vector indexes; + indexes.push_back(index); - arrayIndexOutOfBounds(callstack, arrayInfo, ints); + arrayIndexOutOfBounds(callstack, arrayInfo, indexes); } } } @@ -613,7 +613,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector(total_size)); if (Token::Match(tok, ("%var% ( " + varnames + " ,").c_str())) checkFunctionCall(*tok, 1, arrayInfo); if (Token::Match(tok, ("%var% ( %var% , " + varnames + " ,").c_str())) @@ -748,19 +748,18 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectornext(), counter_varid)) break; - ArrayInfo arrayInfo(varid, varnames, size, total_size); + ArrayInfo arrayInfo(varid, varnames, (unsigned int)size, (unsigned int)total_size); parse_for_body(tok2->next(), arrayInfo, strindex, condition_out_of_bounds, counter_varid, min_counter_value, max_counter_value); continue; } - // Writing data into array.. if ((varid > 0 && Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", varid)) || (varid == 0 && Token::Match(tok, ("strcpy|strcat ( " + varnames + " , %str% )").c_str()))) { - const long len = Token::getStrLength(tok->tokAt(varc + 4)); - if (len < 0 || len >= total_size) + const size_t len = Token::getStrLength(tok->tokAt(varc + 4)); + if (total_size > 0 && len >= static_cast(total_size)) { bufferOverrun(tok, varid > 0 ? "" : varnames.c_str()); continue; @@ -788,17 +787,18 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector 0" check. const std::string sprintfPattern = varid > 0 ? std::string("sprintf ( %varid% , %str% [,)]") : ("sprintf ( " + varnames + " , %str% [,)]"); - if (Token::Match(tok, sprintfPattern.c_str(), varid)) + if (Token::Match(tok, sprintfPattern.c_str(), varid) && total_size > 0) { - checkSprintfCall(tok, total_size); + checkSprintfCall(tok, static_cast(total_size)); } // snprintf.. const std::string snprintfPattern = varid > 0 ? std::string("snprintf ( %varid% , %num% ,") : ("snprintf ( " + varnames + " , %num% ,"); if (Token::Match(tok, snprintfPattern.c_str(), varid)) { - int n = MathLib::toLongNumber(tok->strAt(4 + varc)); + const long n = MathLib::toLongNumber(tok->strAt(4 + varc)); if (n > total_size) outOfBounds(tok->tokAt(4 + varc), "snprintf size"); } @@ -833,16 +833,16 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo else if (Token::Match(tok, "%varid% [ %num% ]", arrayInfo.varid)) { - std::vector indexes; + std::vector indexes; for (const Token *tok2 = tok->next(); Token::Match(tok2, "[ %num% ]"); tok2 = tok2->tokAt(3)) { - const int index = MathLib::toLongNumber(tok2->strAt(1)); + const long index = MathLib::toLongNumber(tok2->strAt(1)); if (index < 0) { indexes.clear(); break; } - indexes.push_back(index); + indexes.push_back(static_cast(index)); } if (indexes.size() == arrayInfo.num.size()) { @@ -1090,7 +1090,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() if (Token::Match(tok, "%type% *| %var% [ %var% ] [;=]")) { - unsigned int varpos = 1; + unsigned char varpos = 1; if (tok->next()->str() == "*") ++varpos; @@ -1186,7 +1186,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() // manually unsigned int sizeOfType = _tokenizer->sizeOfType(declTok->next()); if (sizeOfType > 0) - size /= sizeOfType; + size /= static_cast(sizeOfType); } } else @@ -1199,7 +1199,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() Token sizeTok(0); sizeTok.str(type); - int total_size = size * _tokenizer->sizeOfType(&sizeTok); + int total_size = size * static_cast(_tokenizer->sizeOfType(&sizeTok)); if (total_size == 0) continue; @@ -1266,7 +1266,7 @@ void CheckBufferOverrun::checkStructVariable() if (Token::simpleMatch(tok4, ") {")) { std::vector v; - checkScope(tok4->tokAt(2), v, arrayInfo.num[0], arrayInfo.num[0] * arrayInfo.element_size, arrayInfo.varid); + checkScope(tok4->tokAt(2), v, static_cast(arrayInfo.num[0]), static_cast(arrayInfo.num[0] * arrayInfo.element_size), arrayInfo.varid); break; } } @@ -1323,7 +1323,7 @@ void CheckBufferOverrun::checkStructVariable() continue; // Check variable usage.. - checkScope(CheckTok, varname, arrayInfo.num[0], arrayInfo.num[0] * arrayInfo.element_size, 0); + checkScope(CheckTok, varname, static_cast(arrayInfo.num[0]), static_cast(arrayInfo.num[0] * arrayInfo.element_size), 0); } } } @@ -1340,10 +1340,10 @@ void CheckBufferOverrun::bufferOverrun() //--------------------------------------------------------------------------- -int CheckBufferOverrun::countSprintfLength(const std::string &input_string, const std::list ¶meters) +unsigned int CheckBufferOverrun::countSprintfLength(const std::string &input_string, const std::list ¶meters) { bool percentCharFound = false; - int input_string_size = 1; + unsigned int input_string_size = 1; bool handleNextParameter = false; std::string digits_string = ""; bool i_d_x_f_found = false; @@ -1408,14 +1408,14 @@ int CheckBufferOverrun::countSprintfLength(const std::string &input_string, cons if (handleNextParameter) { - unsigned int tempDigits = std::abs(std::atoi(digits_string.c_str())); + unsigned int tempDigits = static_cast(std::abs(std::atoi(digits_string.c_str()))); if (i_d_x_f_found) - tempDigits = std::max(static_cast(tempDigits), 1); + tempDigits = std::max(static_cast(tempDigits), 1U); if (digits_string.find('.') != std::string::npos) { const std::string endStr = digits_string.substr(digits_string.find('.') + 1); - unsigned int maxLen = std::max(std::abs(std::atoi(endStr.c_str())), 1); + unsigned int maxLen = std::max(static_cast(std::abs(std::atoi(endStr.c_str()))), 1U); if (input_string[i] == 's') { @@ -1451,7 +1451,7 @@ int CheckBufferOverrun::countSprintfLength(const std::string &input_string, cons return input_string_size; } -void CheckBufferOverrun::checkSprintfCall(const Token *tok, int size) +void CheckBufferOverrun::checkSprintfCall(const Token *tok, const unsigned int size) { const Token *end = tok->next()->link(); @@ -1471,7 +1471,6 @@ void CheckBufferOverrun::checkSprintfCall(const Token *tok, int size) { if (Token::Match(tok2, ", %any% [,)]")) { - if (Token::Match(tok2->next(), "%str%")) parameters.push_back(tok2->next()); @@ -1512,7 +1511,7 @@ void CheckBufferOverrun::checkSprintfCall(const Token *tok, int size) } } - int len = countSprintfLength(tok->tokAt(4 + varc)->strValue(), parameters); + unsigned int len = countSprintfLength(tok->tokAt(4 + varc)->strValue(), parameters); if (len > size) { bufferOverrun(tok); @@ -1920,7 +1919,7 @@ private: CheckBufferOverrun *checkBufferOverrun = dynamic_cast(c->owner); if (checkBufferOverrun) { - std::vector index; + std::vector index; index.push_back(c->value); checkBufferOverrun->arrayIndexOutOfBounds(tok, ai, index); break; diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 1f6a9961e..e6ebaa8cf 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -79,7 +79,7 @@ public: * @param parameters given parameters to sprintf * @return minimum length of resulting string */ - static int countSprintfLength(const std::string &input_string, const std::list ¶meters); + static unsigned int countSprintfLength(const std::string &input_string, const std::list ¶meters); /** * @brief %Check code that matches: "sprintf ( %varid% , %str% [,)]" when varid is not 0, @@ -87,7 +87,7 @@ public: * @param tok The "sprintf" token. * @param size The size of the buffer where sprintf is writing. */ - void checkSprintfCall(const Token *tok, int size); + void checkSprintfCall(const Token *tok, const unsigned int size); /** Check for buffer overruns - locate struct variables and check them with the .._CheckScope function */ void checkStructVariable(); @@ -176,8 +176,8 @@ public: void checkFunctionCall(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo); void arrayIndexOutOfBounds(const Token *tok, int size, int index); - void arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index); - void arrayIndexOutOfBounds(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index); + void arrayIndexOutOfBounds(const Token *tok, const ArrayInfo &arrayInfo, const std::vector &index); + void arrayIndexOutOfBounds(const std::list &callstack, const ArrayInfo &arrayInfo, const std::vector &index); void bufferOverrun(const Token *tok, const std::string &varnames = ""); void strncatUsage(const Token *tok); void outOfBounds(const Token *tok, const std::string &what); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 4805ac006..a54cee103 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -777,7 +777,7 @@ bool CheckClass::argsMatch(const Token *first, const Token *second, const std::s if (Token::Match(second->next(), param.c_str())) { - second = second->tokAt(depth * 2); + second = second->tokAt(int(depth) * 2); } else if (depth > 1) { @@ -794,7 +794,7 @@ bool CheckClass::argsMatch(const Token *first, const Token *second, const std::s if (Token::Match(second->next(), param.c_str())) { - second = second->tokAt((depth - 1) * 2); + second = second->tokAt((int(depth) - 1) * 2); } } } @@ -1892,7 +1892,7 @@ void CheckClass::checkConst() const std::string s(previous->str()); for (std::string::size_type pos = 0; pos < s.size(); ++pos) { - unsigned char ch = s[pos]; + const char ch = s[pos]; if (!(ch == '_' || (ch >= 'A' && ch <= 'Z'))) { allupper = false; diff --git a/lib/filelister.cpp b/lib/filelister.cpp index e8a42a8c6..6a25f256d 100644 --- a/lib/filelister.cpp +++ b/lib/filelister.cpp @@ -71,7 +71,7 @@ std::string FileLister::simplifyPath(const char *originalPath) if (subPath.length() > 0) pathParts.push_back(subPath); - for (std::vector::size_type i = 0; i < pathParts.size(); ++i) + for (unsigned int i = 0; i < pathParts.size(); ++i) { if (pathParts[i] == ".." && i > 1 && pathParts.size() > i + 1) { diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e66f707cc..c8af63768 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -219,7 +219,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri unsigned char previous = 0; std::vector suppressionIDs; - for (std::string::size_type i = static_cast(hasbom(str) ? 3 : 0); i < str.length(); ++i) + for (std::string::size_type i = hasbom(str) ? 3U : 0U; i < str.length(); ++i) { unsigned char ch = static_cast(str[i]); if (ch & 0x80) diff --git a/lib/token.cpp b/lib/token.cpp index c8602c11e..f974114ea 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -684,7 +684,7 @@ std::string Token::stringifyList(bool varid, const char *title, const std::vecto unsigned int lineNumber = 0; int fileInd = -1; - std::map lineNumbers; + std::map lineNumbers; for (const Token *tok = this; tok; tok = tok->next()) { bool fileChange = false; @@ -697,8 +697,8 @@ std::string Token::stringifyList(bool varid, const char *title, const std::vecto fileInd = static_cast(tok->_fileIndex); ret << "\n\n##file "; - if (fileNames.size() > static_cast(fileInd)) - ret << fileNames.at(fileInd); + if (fileNames.size() > tok->_fileIndex) + ret << fileNames.at(tok->_fileIndex); else ret << fileInd; diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 84a8343f5..f447144c2 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -45,7 +45,7 @@ private: * Execute check using n jobs for y files which are have * identical data, given within data. */ - void check(int jobs, int files, int result, const std::string &data) + void check(unsigned int jobs, int files, int result, const std::string &data) { errout.str(""); output.str(""); diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 4ed740e20..ebd1810c8 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -163,6 +163,7 @@ int main(int argc, char **argv) << "-Wno-long-long " << "-Wfloat-equal " << "-Wcast-qual " + << "-Wsign-conversion " << "-g -D_GLIBCXX_DEBUG\n"; } fout << "CXX=g++\n";