diff --git a/Makefile b/Makefile
index de50b8d09..09aadde1c 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ MAN_SOURCE=man/cppcheck.1.xml
###### Object Files
-LIBOBJ = lib/checkautovariables.o \
+LIBOBJ = lib/checkautovariables.o \
lib/checkbufferoverrun.o \
lib/checkclass.o \
lib/checkexceptionsafety.o \
@@ -46,7 +46,7 @@ LIBOBJ = lib/checkautovariables.o \
lib/token.o \
lib/tokenize.o
-CLIOBJ = cli/cmdlineparser.o \
+CLIOBJ = cli/cmdlineparser.o \
cli/cppcheckexecutor.o \
cli/filelister.o \
cli/filelister_unix.o \
@@ -90,7 +90,7 @@ TESTOBJ = test/options.o \
test/testunusedprivfunc.o \
test/testunusedvar.o
-EXTOBJ = externals/tinyxml/tinystr.o \
+EXTOBJ = externals/tinyxml/tinystr.o \
externals/tinyxml/tinyxml.o \
externals/tinyxml/tinyxmlerror.o \
externals/tinyxml/tinyxmlparser.o
@@ -98,13 +98,13 @@ EXTOBJ = externals/tinyxml/tinystr.o \
###### Targets
-cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
+cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)
-all: cppcheck testrunner
+all: cppcheck testrunner
-testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o
- $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)
+testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)
test: all
./testrunner
@@ -127,7 +127,7 @@ man/cppcheck.1: $(MAN_SOURCE)
tags:
ctags -R --exclude=doxyoutput .
-install: cppcheck
+install: cppcheck
install -d ${BIN}
install cppcheck ${BIN}
diff --git a/cli/filelister_win32.cpp b/cli/filelister_win32.cpp
index 776e0245a..041613331 100644
--- a/cli/filelister_win32.cpp
+++ b/cli/filelister_win32.cpp
@@ -88,7 +88,7 @@ static BOOL MyIsDirectory(std::string path)
return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
#else
// See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
- return PathIsDirectory(path.c_str());
+return PathIsDirectory(path.c_str());
#endif
}
diff --git a/cppcheck.cppcheck b/cppcheck.cppcheck
index a76e7db2a..188043b4f 100644
--- a/cppcheck.cppcheck
+++ b/cppcheck.cppcheck
@@ -3,10 +3,14 @@
+
+
+
+
diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts
index 9b3ff31ea..3c7b047a7 100644
--- a/gui/cppcheck_de.ts
+++ b/gui/cppcheck_de.ts
@@ -222,10 +222,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -552,28 +552,28 @@ kate -l(line) (file)
Kein passenden Dateien zum Überprüfen gefunden!
-
+
Lizenz
-
+
Autoren
-
+
XML-Dateien (*.xml);;Textdateien (*.txt);;CSV-Dateien (*.csv)
-
+
Speichert die Berichtdatei
-
-
+
+
XML-Dateien (*.xml)
@@ -584,40 +584,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Textdateien (*.txt)
-
+
CSV-Dateien (*.csv)
-
+
Cppcheck - %1
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1018,8 +1018,9 @@ Legen Sie unter dem Menü Ansicht fest, welche Art von Fehlern angezeigt werden
-
- Alle #ifdef-Konfigurationen überprüfen
+
+ Check all #ifdef configurations
+ Alle #ifdef-Konfigurationen überprüfen
diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts
index 3a96b3c94..9ee278852 100644
--- a/gui/cppcheck_en.ts
+++ b/gui/cppcheck_en.ts
@@ -224,10 +224,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -554,28 +554,28 @@ kate -l(line) (file)
No suitable files found to check!
-
+
License
-
+
Authors
-
+
XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)
-
+
Save the report file
-
-
+
+
XML files (*.xml)
@@ -586,40 +586,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Text files (*.txt)
-
+
-
+
Cppcheck - %1
-
+
%1
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1018,8 +1018,9 @@ To toggle what kind of errors are shown, open view menu.
-
- Check all #ifdef configurations
+
+ Check all #ifdef configurations
+ Check all #ifdef configurations
diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts
index 57924099c..303d349e6 100644
--- a/gui/cppcheck_fi.ts
+++ b/gui/cppcheck_fi.ts
@@ -226,10 +226,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -556,28 +556,28 @@ kate -l(line) (file)
Tarkistettavaksi sopivia tiedostoja ei löytynyt!
-
+
Lisenssi
-
+
Tekijät
-
+
XML-tiedostot (*.xml);;Tekstitiedostot (*.txt);;CSV-tiedostot (*.csv)
-
+
Tallenna raportti
-
-
+
+
XML-tiedostot (*xml)
@@ -588,40 +588,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Tekstitiedostot (*.txt)
-
+
-
+
Cppcheck - %1
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1022,8 +1022,9 @@ Määrittääksesi minkä tyyppisiä virheitä näytetään, avaa näkymä valik
-
- Tarkista kaikki #ifdef kombinaatiot
+
+ Check all #ifdef configurations
+ Tarkista kaikki #ifdef kombinaatiot
diff --git a/gui/cppcheck_ja.ts b/gui/cppcheck_ja.ts
index 911b32756..222900f08 100644
--- a/gui/cppcheck_ja.ts
+++ b/gui/cppcheck_ja.ts
@@ -210,10 +210,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -546,24 +546,24 @@ kate -l(line) (file)
-
-
+
+
プロジェクト:
-
-
+
+
XML ファイル (*.xml)
-
+
レポートを開く
-
+
@@ -572,42 +572,42 @@ Do you want to stop the checking and exit Cppcheck?.
解析を停止してCppcheckを終了しますか?.
-
+
ライセンス
-
+
作者
-
+
XML ファイル (*.xml);;テキストファイル (*.txt);;CSV形式ファイル (*.csv)
-
+
レポートを保存
-
+
テキストファイル (*.txt)
-
+
CSV形式ファイル (*.csv)
-
+
Cppcheck - %1
-
+
-
-
+
+
Cppcheck ヘルプ
-
+
ヘルプファイルが見つかりませんでした
-
+
ヘルプファイルの読み込みに失敗しました
-
-
+
+
プロジェクトファイル (*.cppcheck);;All files(*.*)
-
+
プロジェクトファイルを選択
-
+
プロジェクトファイル名を選択
-
+
プロジェクトファイルが読み込まれていません
@@ -1003,8 +1003,9 @@ To toggle what kind of errors are shown, open view menu.
-
- すべての #ifdef をチェックする
+
+ Check all #ifdef configurations
+ すべての #ifdef をチェックする
diff --git a/gui/cppcheck_nl.ts b/gui/cppcheck_nl.ts
index c5e5e6747..a5ac7b33f 100644
--- a/gui/cppcheck_nl.ts
+++ b/gui/cppcheck_nl.ts
@@ -224,10 +224,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -554,28 +554,28 @@ kate -l(line) (file)
Geen geschikte bestanden gevonden om te controleren!
-
+
Licentie
-
+
Auteurs
-
+
XML bestanden (*.xml);;Tekst bestanden (*.txt);;CSV bestanden (*.csv)
-
+
Rapport opslaan
-
-
+
+
XML bestanden (*.xml)
@@ -586,40 +586,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Tekst bestanden (*.txt)
-
+
-
+
Cppcheck - %1
-
+
%1
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1018,8 +1018,9 @@ Gebruik het uitzicht menu om te selecteren welke fouten getoond worden.
-
- Controleer alle #ifdef combinaties
+
+ Check all #ifdef configurations
+ Controleer alle #ifdef combinaties
diff --git a/gui/cppcheck_pl.ts b/gui/cppcheck_pl.ts
index c35ddefb1..79013cad9 100644
--- a/gui/cppcheck_pl.ts
+++ b/gui/cppcheck_pl.ts
@@ -211,10 +211,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
@@ -547,92 +547,92 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
@@ -994,7 +994,8 @@ To toggle what kind of errors are shown, open view menu.
-
+
+ Check all #ifdef configurations
diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts
index 6c3d6d407..56e10c928 100644
--- a/gui/cppcheck_ru.ts
+++ b/gui/cppcheck_ru.ts
@@ -214,10 +214,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -544,28 +544,28 @@ kate -l(line) (file)
-
+
Лицензия
-
+
Авторы
-
+
-
+
-
-
+
+
@@ -576,40 +576,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Текстовые файлы (*.txt)
-
+
-
+
Cppcheck - %1
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1007,8 +1007,9 @@ To toggle what kind of errors are shown, open view menu.
-
- Проверять все варианты #ifdef конфигураций
+
+ Check all #ifdef configurations
+ Проверять все варианты #ifdef конфигураций
diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts
index 278a2de3f..0fec2db9a 100644
--- a/gui/cppcheck_se.ts
+++ b/gui/cppcheck_se.ts
@@ -224,10 +224,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -555,28 +555,28 @@ kate -l(line) (file)
Inga lämpliga filer hittades!
-
+
Licens
-
+
Utvecklare
-
+
XML filer (*.xml);;Text filer (*.txt);;CSV filer (*.csv)
-
+
Spara rapport
-
-
+
+
XML filer (*.xml)
@@ -587,40 +587,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Text filer (*.txt)
-
+
CSV filer (*.csv)
-
+
Cppcheck - %1
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1021,8 +1021,9 @@ För att ställa in vilka fel som skall visas använd visa menyn.
-
- Kontrollera alla #ifdef konfigurationer
+
+ Check all #ifdef configurations
+ Kontrollera alla #ifdef konfigurationer
diff --git a/gui/cppcheck_sr.ts b/gui/cppcheck_sr.ts
index 4beb61085..8710dd855 100644
--- a/gui/cppcheck_sr.ts
+++ b/gui/cppcheck_sr.ts
@@ -224,10 +224,10 @@ kate -l(line) (file)
-
-
-
-
+
+
+
+
Cppcheck
@@ -554,28 +554,28 @@ kate -l(line) (file)
No suitable files found to check!
-
+
License
-
+
Authors
-
+
XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)
-
+
Save the report file
-
-
+
+
XML files (*.xml)
@@ -586,40 +586,40 @@ kate -l(line) (file)
-
-
+
+
-
+
-
+
-
+
Text files (*.txt)
-
+
-
+
Cppcheck - %1
-
+
%1
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -1018,8 +1018,9 @@ To toggle what kind of errors are shown, open view menu.
-
- Check all #ifdef configurations
+
+ Check all #ifdef configurations
+ Check all #ifdef configurations
diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp
index a9016e42e..0080f1434 100644
--- a/gui/csvreport.cpp
+++ b/gui/csvreport.cpp
@@ -65,7 +65,7 @@ void CsvReport::WriteError(const ErrorItem &error)
QString line;
const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]);
line += QString("%1,%2,").arg(file).arg(error.lines[error.lines.size() - 1]);
- line += QString("%1,%2").arg(error.severity).arg(error.message);
+ line += QString("%1,%2").arg(error.severity).arg(error.summary);
mTxtWriter << line << endl;
}
diff --git a/gui/gui.cppcheck b/gui/gui.cppcheck
index 632b61115..7c87003bd 100644
--- a/gui/gui.cppcheck
+++ b/gui/gui.cppcheck
@@ -1,6 +1,7 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/gui/settings.ui b/gui/settings.ui
index ac5f19f33..8d6fc2e3d 100644
--- a/gui/settings.ui
+++ b/gui/settings.ui
@@ -7,7 +7,7 @@
0
0
589
- 281
+ 313
@@ -135,7 +135,7 @@
-
- Check all #ifdef configurations
+ Force checking all #ifdef configurations
diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp
index a6f8dbe4b..20c34d7b7 100644
--- a/gui/txtreport.cpp
+++ b/gui/txtreport.cpp
@@ -76,7 +76,7 @@ void TxtReport::WriteError(const ErrorItem &error)
}
}
- line += QString("(%1) %2").arg(error.severity).arg(error.message);
+ line += QString("(%1) %2").arg(error.severity).arg(error.summary);
mTxtWriter << line << endl;
}
diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp
index c82478055..f481f3615 100644
--- a/gui/xmlreport.cpp
+++ b/gui/xmlreport.cpp
@@ -159,6 +159,16 @@ ErrorLine XmlReport::ReadError(QXmlStreamReader *reader)
line.line = attribs.value("", LineAttribute).toString().toUInt();
line.id = attribs.value("", IdAttribute).toString();
line.severity = attribs.value("", SeverityAttribute).toString();
+
+ // NOTE: This dublicates the message to Summary-field. But since
+ // old XML format doesn't have separate summary and verbose messages
+ // we must add same message to both data so it shows up in GUI.
+ // Check if there is full stop and cut the summary to it.
+ QString summary = attribs.value("", MsgAttribute).toString();
+ const int ind = summary.indexOf('.');
+ if (ind != -1)
+ summary = summary.left(ind + 1);
+ line.summary = summary;
line.message = attribs.value("", MsgAttribute).toString();
}
return line;
diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp
index e9b1467bd..bd36a4e37 100644
--- a/lib/checknullpointer.cpp
+++ b/lib/checknullpointer.cpp
@@ -485,6 +485,12 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
break;
}
+ if (tok1->str() == ")" && Token::simpleMatch(tok1->link()->previous(), "sizeof ("))
+ {
+ tok1 = tok1->link()->previous();
+ continue;
+ }
+
if (tok1->str() == "break")
break;
diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp
index ddf0b6128..4cdd5f729 100644
--- a/lib/preprocessor.cpp
+++ b/lib/preprocessor.cpp
@@ -713,21 +713,36 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
// Get the DEF in this line: "#ifdef DEF"
std::string Preprocessor::getdef(std::string line, bool def)
{
+ if (line.empty() || line[0] != '#')
+ return "";
+
// If def is true, the line must start with "#ifdef"
- if (def && line.find("#ifdef ") != 0 && line.find("#if ") != 0 && line.find("#elif ") != 0 && line.find("#if defined ") != 0)
+ if (def && line.compare(0, 7, "#ifdef ") != 0 && line.compare(0, 4, "#if ") != 0
+ && (line.compare(0, 6, "#elif ") != 0 || line.compare(0, 7, "#elif !") == 0))
{
return "";
}
// If def is false, the line must start with "#ifndef"
- if (!def && line.find("#ifndef ") != 0)
+ if (!def && line.compare(0, 8, "#ifndef ") != 0 && line.compare(0, 7, "#elif !") != 0)
{
return "";
}
// Remove the "#ifdef" or "#ifndef"
- if (line.find("#if defined ") == 0)
+ if (line.compare(0, 12, "#if defined ") == 0)
line.erase(0, 11);
+ else if (line.compare(0, 15, "#elif !defined(") == 0)
+ {
+ std::string::size_type pos = 0;
+
+ line.erase(0, 15);
+ pos = line.find(")");
+ // if pos == ::npos then another part of the code will complain
+ // about the mismatch
+ if (pos != std::string::npos)
+ line.erase(pos, 1);
+ }
else
line.erase(0, line.find(" "));
@@ -775,6 +790,8 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
if (_errorLogger)
_errorLogger->reportProgress(filename, "Preprocessing (get configurations 1)", 0);
+ if (line.empty())
+ continue;
if (line.compare(0, 6, "#file ") == 0)
{
@@ -806,6 +823,9 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
if (!line.empty() && line.compare(0, 3, "#if") != 0)
includeguard = false;
+ if (line[0] != '#')
+ continue;
+
if (includeguard)
continue;
@@ -868,7 +888,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
simplifyCondition(varmap, def, false);
}
- if (! deflist.empty() && line.find("#elif ") == 0)
+ if (! deflist.empty() && line.compare(0, 6, "#elif ") == 0)
deflist.pop_back();
deflist.push_back(def);
def = "";
@@ -888,6 +908,21 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
def += ";";
def += *it;
}
+ else
+ {
+ std::ostringstream lineStream;
+ lineStream << __LINE__;
+
+ ErrorLogger::ErrorMessage errmsg;
+ ErrorLogger::ErrorMessage::FileLocation loc;
+ loc.setfile(filename);
+ loc.line = linenr;
+ errmsg._callStack.push_back(loc);
+ errmsg._severity = Severity::fromString("error");
+ errmsg.setmsg(*it+" is already guaranteed to be defined");
+ errmsg._id = "preprocessor" + lineStream.str();
+ _errorLogger->reportErr(errmsg);
+ }
}
if (from_negation)
{
@@ -903,7 +938,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
}
}
- else if (line.find("#else") == 0 && ! deflist.empty())
+ else if (line.compare(0, 5, "#else") == 0 && ! deflist.empty())
{
if (deflist.back() == "!")
{
@@ -919,7 +954,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const
}
}
- else if (line.find("#endif") == 0 && ! deflist.empty())
+ else if (line.compare(0, 6, "#endif") == 0 && ! deflist.empty())
{
if (deflist.back() == "!")
ndeflist.pop_back();
@@ -1345,7 +1380,23 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
}
}
- else if (line.find("#elif ") == 0)
+ else if (line.compare(0, 7, "#elif !") == 0)
+ {
+ if (matched_ifdef.back())
+ {
+ matching_ifdef.back() = false;
+ }
+ else
+ {
+ if (!match_cfg_def(cfgmap, ndef))
+ {
+ matching_ifdef.back() = true;
+ matched_ifdef.back() = true;
+ }
+ }
+ }
+
+ else if (line.compare(0, 6, "#elif ") == 0)
{
if (matched_ifdef.back())
{
diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp
index c63094fde..4966231ba 100644
--- a/test/testbufferoverrun.cpp
+++ b/test/testbufferoverrun.cpp
@@ -106,6 +106,7 @@ private:
TEST_CASE(array_index_29); // ticket #1734
TEST_CASE(array_index_30); // ticket #2086 - out of bounds when type is unknown
TEST_CASE(array_index_31); // ticket #2120 - out of bounds in subfunction when type is unknown
+ TEST_CASE(array_index_32);
TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_calculation);
@@ -1067,6 +1068,21 @@ private:
ASSERT_EQUALS("", errout.str());
}
+ void array_index_32()
+ {
+ check("class X\n"
+ "{\n"
+ " public:\n"
+ " X()\n"
+ " {\n"
+ " m_x[0] = 0;\n"
+ " m_x[1] = 0;\n"
+ " }\n"
+ " int m_x[1];\n"
+ "};\n");
+ TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' index 1 out of bounds\n","", errout.str());
+ }
+
void array_index_multidim()
{
check("void f()\n"
diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp
index 53198703c..0c9e09a1f 100644
--- a/test/testnullpointer.cpp
+++ b/test/testnullpointer.cpp
@@ -437,6 +437,15 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
+
+ // #2525 - sizeof
+ check("void f() {\n"
+ " int *test = NULL;\n"
+ " int c = sizeof(test[0]);\n"
+ " if (!test)\n"
+ " ;\n"
+ "}\n");
+ ASSERT_EQUALS("", errout.str());
}
void nullpointer5()
diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp
index 0cd5fb4ab..2d9486d49 100644
--- a/test/testpreprocessor.cpp
+++ b/test/testpreprocessor.cpp
@@ -429,13 +429,118 @@ private:
preprocessor.preprocess(istr, actual, "file.c");
// Make sure an error message is written..
- TODO_ASSERT_EQUALS("[test.cpp:3]: this preprocessor condition is always true",
- "", errout.str());
+ ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n",
+ errout.str());
// Compare results..
ASSERT_EQUALS("\n\n\n\n\n\n", actual[""]);
ASSERT_EQUALS("\nA\n\nB\n\n\n", actual["ABC"]);
ASSERT_EQUALS(2, static_cast(actual.size()));
+
+ test7a();
+ test7b();
+ test7c();
+ test7d();
+ }
+
+ void test7a()
+ {
+ const char filedata[] = "#ifndef ABC\n"
+ "A\n"
+ "#ifndef ABC\n"
+ "B\n"
+ "#endif\n"
+ "#endif\n";
+
+ // Preprocess => actual result..
+ std::istringstream istr(filedata);
+ std::map actual;
+ Settings settings;
+ Preprocessor preprocessor(&settings, this);
+ errout.str("");
+ preprocessor.preprocess(istr, actual, "file.c");
+
+ // Make sure an error message is written..
+ TODO_ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed NOT to be defined\n",
+ "", errout.str());
+
+ // Compare results..
+ ASSERT_EQUALS(2, static_cast(actual.size()));
+ }
+
+ void test7b()
+ {
+ const char filedata[] = "#ifndef ABC\n"
+ "A\n"
+ "#ifdef ABC\n"
+ "B\n"
+ "#endif\n"
+ "#endif\n";
+
+ // Preprocess => actual result..
+ std::istringstream istr(filedata);
+ std::map actual;
+ Settings settings;
+ Preprocessor preprocessor(&settings, this);
+ errout.str("");
+ preprocessor.preprocess(istr, actual, "file.c");
+
+ // Make sure an error message is written..
+ TODO_ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed NOT to be defined\n",
+ "", errout.str());
+
+ // Compare results..
+ ASSERT_EQUALS(2, static_cast(actual.size()));
+ }
+
+ void test7c()
+ {
+ const char filedata[] = "#ifdef ABC\n"
+ "A\n"
+ "#ifndef ABC\n"
+ "B\n"
+ "#endif\n"
+ "#endif\n";
+
+ // Preprocess => actual result..
+ std::istringstream istr(filedata);
+ std::map actual;
+ Settings settings;
+ Preprocessor preprocessor(&settings, this);
+ errout.str("");
+ preprocessor.preprocess(istr, actual, "file.c");
+
+ // Make sure an error message is written..
+ ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n",
+ errout.str());
+
+ // Compare results..
+ ASSERT_EQUALS(2, static_cast(actual.size()));
+ }
+
+ void test7d()
+ {
+ const char filedata[] = "#if defined(ABC)\n"
+ "A\n"
+ "#if defined(ABC)\n"
+ "B\n"
+ "#endif\n"
+ "#endif\n";
+
+ // Preprocess => actual result..
+ std::istringstream istr(filedata);
+ std::map actual;
+ Settings settings;
+ Preprocessor preprocessor(&settings, this);
+ errout.str("");
+ preprocessor.preprocess(istr, actual, "file.c");
+
+ // Make sure an error message is written..
+ ASSERT_EQUALS("[file.c:3]: (error) ABC is already guaranteed to be defined\n",
+ errout.str());
+
+ // Compare results..
+ ASSERT_EQUALS(2, static_cast(actual.size()));
}
@@ -806,6 +911,7 @@ private:
if_cond2b();
if_cond2c();
if_cond2d();
+ if_cond2e();
}
void if_cond2b()
@@ -893,6 +999,31 @@ private:
ASSERT_EQUALS("\n!a\n\nb\n\n\n\n\n\n\n\n\n\n\n\n", actual["B"]);
}
+ void if_cond2e()
+ {
+ const char filedata[] = "#if !defined(A)\n"
+ "!a\n"
+ "#elif !defined(B)\n"
+ "!b\n"
+ "#endif\n";
+
+ // Preprocess => actual result..
+ errout.str("");
+ std::istringstream istr(filedata);
+ std::map actual;
+ Settings settings;
+ settings.debug = settings.debugwarnings = true;
+ Preprocessor preprocessor(&settings, this);
+ preprocessor.preprocess(istr, actual, "file.c");
+
+ // Compare results..
+ ASSERT_EQUALS(3, static_cast(actual.size()));
+ ASSERT_EQUALS("\n!a\n\n\n\n", actual[""]);
+ ASSERT_EQUALS("\n\n\n!b\n\n", actual["A"]);
+ TODO_ASSERT_EQUALS("\n\n\n\n\n", "", actual["A;B"]);
+ ASSERT_EQUALS("", errout.str());
+ }
+
void if_cond3()
{
const char filedata[] = "#ifdef A\n"
diff --git a/tools/dmake.cpp b/tools/dmake.cpp
index 0ff33c099..434a4128c 100644
--- a/tools/dmake.cpp
+++ b/tools/dmake.cpp
@@ -208,11 +208,11 @@ int main(int argc, char **argv)
fout << "MAN_SOURCE=man/cppcheck.1.xml\n\n";
fout << "\n###### Object Files\n\n";
- fout << "LIBOBJ = " << objfile(libfiles[0]);
+ fout << "LIBOBJ = " << objfile(libfiles[0]);
for (unsigned int i = 1; i < libfiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(libfiles[i]);
fout << "\n\n";
- fout << "CLIOBJ = " << objfile(clifiles[0]);
+ fout << "CLIOBJ = " << objfile(clifiles[0]);
for (unsigned int i = 1; i < clifiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(clifiles[i]);
fout << "\n\n";
@@ -220,18 +220,18 @@ int main(int argc, char **argv)
for (unsigned int i = 1; i < testfiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(testfiles[i]);
fout << "\n\n";
- fout << "EXTOBJ = " << objfile(externalfiles[0]);
+ fout << "EXTOBJ = " << objfile(externalfiles[0]);
for (unsigned int i = 1; i < externalfiles.size(); ++i)
fout << " \\" << std::endl << std::string(14, ' ') << objfile(externalfiles[i]);
fout << "\n\n";
fout << "\n###### Targets\n\n";
- fout << "cppcheck:\t$(LIBOBJ)\t$(CLIOBJ)\t$(EXTOBJ)\n";
+ fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n";
fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o cppcheck $(CLIOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre $(LDFLAGS)\n\n";
- fout << "all:\tcppcheck\ttestrunner\n\n";
- fout << "testrunner:\t$(TESTOBJ)\t$(LIBOBJ)\t$(EXTOBJ)\tcli/threadexecutor.o\tcli/cmdlineparser.o\tcli/cppcheckexecutor.o\tcli/filelister.o\tcli/filelister_unix.o\n";
- fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o\tcli/filelister.o\tcli/filelister_unix.o $(LDFLAGS)\n\n";
+ fout << "all:\tcppcheck testrunner\n\n";
+ fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/filelister.o cli/filelister_unix.o\n";
+ fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o testrunner $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) -lpcre cli/threadexecutor.o cli/cmdlineparser.o cli/filelister.o cli/filelister_unix.o $(LDFLAGS)\n\n";
fout << "test:\tall\n";
fout << "\t./testrunner\n\n";
fout << "check:\tall\n";
@@ -248,7 +248,7 @@ int main(int argc, char **argv)
fout << "\t$(XP) $(DB2MAN) $(MAN_SOURCE)\n\n";
fout << "tags:\n";
fout << "\tctags -R --exclude=doxyoutput .\n\n";
- fout << "install:\tcppcheck\n";
+ fout << "install: cppcheck\n";
fout << "\tinstall -d ${BIN}\n";
fout << "\tinstall cppcheck ${BIN}\n\n";
#endif