diff --git a/Makefile b/Makefile index ba9251e74..655fd19a2 100644 --- a/Makefile +++ b/Makefile @@ -4,33 +4,33 @@ TESTS=testbufferoverrun.o testcharvar.o testclass.o testconstructors.o testdivis BIN = ${DESTDIR}/usr/bin all: ${OBJS} main.o - g++ -Wall -g -o cppcheck $^ + g++ -Wall -g -pg -o cppcheck $^ test: ${OBJS} testrunner.o testsuite.o ${TESTS} g++ -Wall -g -o testrunner $^ cppcheckexecutor.o: cppcheckexecutor.cpp cppcheckexecutor.h cppcheck.h errorlogger.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp cppcheck.o: cppcheck.cpp cppcheck.h settings.h errorlogger.h preprocessor.h tokenize.h token.h checkmemoryleak.h checkbufferoverrun.h checkclass.h checkheaders.h checkother.h checkfunctionusage.h filelister.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp main.o: main.cpp cppcheck.h settings.h errorlogger.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkbufferoverrun.o: checkbufferoverrun.cpp checkbufferoverrun.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkclass.o: checkclass.cpp checkclass.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkfunctionusage.o: checkfunctionusage.cpp checkfunctionusage.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkheaders.o: checkheaders.cpp checkheaders.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkmemoryleak.o: checkmemoryleak.cpp checkmemoryleak.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp checkother.o: checkother.cpp checkother.h tokenize.h settings.h errorlogger.h token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp filelister.o: filelister.cpp filelister.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp preprocessor.o: preprocessor.cpp preprocessor.h errorlogger.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp settings.o: settings.cpp settings.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp testbufferoverrun.o: testbufferoverrun.cpp tokenize.h settings.h errorlogger.h token.h checkbufferoverrun.h testsuite.h g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp testcharvar.o: testcharvar.cpp tokenize.h settings.h errorlogger.h token.h checkother.h testsuite.h @@ -72,9 +72,9 @@ testunusedvar.o: testunusedvar.cpp testsuite.h errorlogger.h tokenize.h settings testfilelister.o: testfilelister.cpp filelister.h g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp token.o: token.cpp token.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp tokenize.o: tokenize.cpp tokenize.h settings.h errorlogger.h token.h filelister.h - g++ -Wall -pedantic -g -I. -o $@ -c $*.cpp + g++ -Wall -pedantic -pg -g -I. -o $@ -c $*.cpp clean: rm -f *.o testrunner cppcheck diff --git a/tokenize.cpp b/tokenize.cpp index 90039e1b9..98f90b1d8 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -638,14 +638,18 @@ void Tokenizer::setVarId() ++_varId; int indentlevel = 0; int parlevel = 0; - for ( tok2 = tok->next(); tok2 && indentlevel >= 0; tok2 = tok2->next() ) + for ( tok2 = tok->next(); tok2; tok2 = tok2->next() ) { if ( tok2->str() == varname ) tok2->varId( _varId ); else if ( tok2->str() == "{" ) ++indentlevel; else if ( tok2->str() == "}" ) + { --indentlevel; + if ( indentlevel < 0 ) + break; + } else if ( tok2->str() == "(" ) ++parlevel; else if ( tok2->str() == ")" ) @@ -659,8 +663,8 @@ void Tokenizer::setVarId() // Struct/Class members for ( TOKEN *tok = _tokens; tok; tok = tok->next() ) { - if ( TOKEN::Match(tok, "%var% . %var%") && - tok->varId() != 0 && + if ( tok->varId() != 0 && + TOKEN::Match(tok, "%var% . %var%") && tok->tokAt(2)->varId() == 0 ) { ++_varId;