Merge branch 'master' of git://github.com/danmar/cppcheck
This commit is contained in:
commit
0d76d87770
|
@ -1,24 +1,29 @@
|
|||
# Minimal CMake build file to build cppcheck command line executable
|
||||
|
||||
include_directories("${CPPCHECK_SOURCE_DIR}/lib")
|
||||
|
||||
if(PCRE_FOUND)
|
||||
add_definitions(-DHAVE_RULES)
|
||||
include_directories("${PCRE_INCLUDE_DIR}")
|
||||
set(TINYXML_INCLUDE_DIR "${CPPCHECK_SOURCE_DIR}/externals/tinyxml/")
|
||||
include_directories("${PCRE_INCLUDE_DIR}" "${TINYXML_INCLUDE_DIR}")
|
||||
set(CHECK_LIBS ${PCRE_LIBRARIES})
|
||||
endif()
|
||||
|
||||
set(TINYXML_INCLUDE_DIR "${CPPCHECK_SOURCE_DIR}/externals/tinyxml/")
|
||||
|
||||
SET(CHECKCLI_SRCS
|
||||
cmdlineparser.cpp
|
||||
cppcheckexecutor.cpp
|
||||
filelister.cpp
|
||||
main.cpp
|
||||
threadexecutor.cpp
|
||||
pathmatch.cpp
|
||||
"${TINYXML_INCLUDE_DIR}tinystr.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxml.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxmlerror.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxmlparser.cpp")
|
||||
threadexecutor.cpp)
|
||||
|
||||
if(PCRE_FOUND)
|
||||
set(CHECKCLI_SRCS ${CHECKCLI_SRCS}
|
||||
"${TINYXML_INCLUDE_DIR}tinystr.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxml.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxmlerror.cpp"
|
||||
"${TINYXML_INCLUDE_DIR}tinyxmlparser.cpp")
|
||||
endif()
|
||||
|
||||
set(CPPCHECK_LIB_DIR "${CPPCHECK_SOURCE_DIR}/lib/")
|
||||
include("${CPPCHECK_LIB_DIR}library_sources.cmake")
|
||||
|
@ -37,7 +42,5 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wshadow -Wno-long-long -Wfloat-equal -Wcast-qual")
|
||||
endif (CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
include_directories("${CPPCHECK_SOURCE_DIR}/lib"
|
||||
"${TINYXML_INCLUDE_DIR}")
|
||||
add_executable(cppcheck ${CHECKCLI_SRCS} ${CPPCHECK_LIB_SOURCES})
|
||||
TARGET_LINK_LIBRARIES(cppcheck ${CHECK_LIBS})
|
||||
|
|
31
gui/main.cpp
31
gui/main.cpp
|
@ -21,12 +21,21 @@
|
|||
#include <QTextCodec>
|
||||
#include <QTranslator>
|
||||
#include <QMetaType>
|
||||
#include <QStringList>
|
||||
#include <iostream>
|
||||
#include "mainwindow.h"
|
||||
#include "erroritem.h"
|
||||
|
||||
void ShowUsage();
|
||||
bool CheckArgs(const QStringList &args);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
if (!CheckArgs(app.arguments()))
|
||||
return 0;
|
||||
|
||||
app.setWindowIcon(QIcon(":icon.png"));
|
||||
|
||||
// Register this metatype that is used to transfer error info
|
||||
|
@ -40,3 +49,25 @@ int main(int argc, char *argv[])
|
|||
window.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
// Check only arguments needing action before GUI is shown.
|
||||
// Rest of the arguments are handled in MainWindow::HandleCLIParams()
|
||||
bool CheckArgs(const QStringList &args)
|
||||
{
|
||||
if (args.contains("-h") || args.contains("--help"))
|
||||
{
|
||||
ShowUsage();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShowUsage()
|
||||
{
|
||||
std::cout << "Cppcheck GUI.\n\n";
|
||||
std::cout << "Syntax:\n";
|
||||
std::cout << " cppcheck-gui [OPTIONS] [files or paths]\n\n";
|
||||
std::cout << "Options:\n";
|
||||
std::cout << " -h, --help Print this help\n";
|
||||
std::cout << " -p <file> Open given project file and start checking it\n";
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ MainWindow::MainWindow() :
|
|||
args.removeFirst();
|
||||
if (!args.isEmpty())
|
||||
{
|
||||
DoCheckFiles(args);
|
||||
HandleCLIParams(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,21 @@ MainWindow::~MainWindow()
|
|||
delete mProject;
|
||||
}
|
||||
|
||||
void MainWindow::HandleCLIParams(const QStringList ¶ms)
|
||||
{
|
||||
if (params.contains("-p"))
|
||||
{
|
||||
QString projFile;
|
||||
const int ind = params.indexOf("-p");
|
||||
if ((ind + 1) < params.length())
|
||||
projFile = params[ind + 1];
|
||||
|
||||
LoadProjectFile(projFile);
|
||||
}
|
||||
else
|
||||
DoCheckFiles(params);
|
||||
}
|
||||
|
||||
void MainWindow::LoadSettings()
|
||||
{
|
||||
if (mSettings->value(SETTINGS_WINDOW_MAXIMIZED, false).toBool())
|
||||
|
@ -730,39 +745,43 @@ void MainWindow::OpenProjectFile()
|
|||
|
||||
if (!filepath.isEmpty())
|
||||
{
|
||||
QFileInfo inf(filepath);
|
||||
const QString filename = inf.fileName();
|
||||
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
|
||||
LoadProjectFile(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
mUI.mActionCloseProjectFile->setEnabled(true);
|
||||
mUI.mActionEditProjectFile->setEnabled(true);
|
||||
delete mProject;
|
||||
mProject = new Project(filepath, this);
|
||||
mProject->Open();
|
||||
QString rootpath = mProject->GetProjectFile()->GetRootPath();
|
||||
void MainWindow::LoadProjectFile(const QString &filePath)
|
||||
{
|
||||
QFileInfo inf(filePath);
|
||||
const QString filename = inf.fileName();
|
||||
FormatAndSetTitle(tr("Project: ") + QString(" ") + filename);
|
||||
|
||||
// If root path not give or "current dir" then use project file's directory
|
||||
// as check path
|
||||
if (rootpath.isEmpty() || rootpath == ".")
|
||||
mCurrentDirectory = inf.canonicalPath();
|
||||
else
|
||||
mCurrentDirectory = rootpath;
|
||||
mUI.mActionCloseProjectFile->setEnabled(true);
|
||||
mUI.mActionEditProjectFile->setEnabled(true);
|
||||
delete mProject;
|
||||
mProject = new Project(filePath, this);
|
||||
mProject->Open();
|
||||
QString rootpath = mProject->GetProjectFile()->GetRootPath();
|
||||
|
||||
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
|
||||
if (!paths.isEmpty())
|
||||
// If root path not give or "current dir" then use project file's directory
|
||||
// as check path
|
||||
if (rootpath.isEmpty() || rootpath == ".")
|
||||
mCurrentDirectory = inf.canonicalPath();
|
||||
else
|
||||
mCurrentDirectory = rootpath;
|
||||
|
||||
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
|
||||
if (!paths.isEmpty())
|
||||
{
|
||||
for (int i = 0; i < paths.size(); i++)
|
||||
{
|
||||
for (int i = 0; i < paths.size(); i++)
|
||||
if (!QDir::isAbsolutePath(paths[i]))
|
||||
{
|
||||
if (!QDir::isAbsolutePath(paths[i]))
|
||||
{
|
||||
QString path = mCurrentDirectory + "/";
|
||||
path += paths[i];
|
||||
paths[i] = QDir::cleanPath(path);
|
||||
}
|
||||
QString path = mCurrentDirectory + "/";
|
||||
path += paths[i];
|
||||
paths[i] = QDir::cleanPath(path);
|
||||
}
|
||||
|
||||
DoCheckFiles(paths);
|
||||
}
|
||||
DoCheckFiles(paths);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -360,6 +360,18 @@ protected:
|
|||
*/
|
||||
void AddIncludeDirs(const QStringList &includeDirs, Settings &result);
|
||||
|
||||
/**
|
||||
* @brief Handle command line parameters given to GUI.
|
||||
* @param params List of string given to command line.
|
||||
*/
|
||||
void HandleCLIParams(const QStringList ¶ms);
|
||||
|
||||
/**
|
||||
* @brief Load project file to the GUI.
|
||||
* @param filePath Filename (inc. path) of project file to load.
|
||||
*/
|
||||
void LoadProjectFile(const QString &filePath);
|
||||
|
||||
/**
|
||||
* @brief Program settings
|
||||
*
|
||||
|
|
|
@ -68,8 +68,8 @@ private:
|
|||
{
|
||||
_obsoleteFunctions.push_back(std::make_pair("bsd_signal","Found obsolete function 'bsd_signal'. It is recommended that new applications use the 'sigaction' function"));
|
||||
|
||||
_obsoleteFunctions.push_back(std::make_pair("gethostbyaddr","Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getaddrinfo' function"));
|
||||
_obsoleteFunctions.push_back(std::make_pair("gethostbyname","Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getnameinfo' function"));
|
||||
_obsoleteFunctions.push_back(std::make_pair("gethostbyaddr","Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getnameinfo' function"));
|
||||
_obsoleteFunctions.push_back(std::make_pair("gethostbyname","Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function"));
|
||||
|
||||
_obsoleteFunctions.push_back(std::make_pair("usleep","Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function\n"
|
||||
"Found obsolete function 'usleep'. POSIX.1-2001 declares usleep() function obsolete and POSIX.1-2008 removes it. It is recommended that new applications use the 'nanosleep' or 'setitimer' function."));
|
||||
|
|
|
@ -1910,13 +1910,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
|||
}
|
||||
else if (!fileOpened)
|
||||
{
|
||||
// TODO: Fix the handling of system includes and then
|
||||
// remove the "headerType == UserHeader"
|
||||
#ifdef NDEBUG
|
||||
if (headerType == UserHeader && _errorLogger && _settings && _settings->isEnabled("missingInclude"))
|
||||
#else
|
||||
if (_errorLogger && _settings && _settings->isEnabled("missingInclude"))
|
||||
#endif
|
||||
if (_errorLogger && _settings && ((headerType == UserHeader && _settings->isEnabled("missingInclude")) || _settings->debugwarnings))
|
||||
{
|
||||
std::string f = filePath;
|
||||
|
||||
|
@ -2384,14 +2378,17 @@ public:
|
|||
}
|
||||
|
||||
// expand nopar macro
|
||||
const std::map<std::string, PreprocessorMacro *>::const_iterator it = macros.find(str);
|
||||
if (it != macros.end() && it->second->_macro.find("(") == std::string::npos)
|
||||
if (tok->strAt(-1) != "##")
|
||||
{
|
||||
str = it->second->_macro;
|
||||
if (str.find(" ") != std::string::npos)
|
||||
str.erase(0, str.find(" "));
|
||||
else
|
||||
str = "";
|
||||
const std::map<std::string, PreprocessorMacro *>::const_iterator it = macros.find(str);
|
||||
if (it != macros.end() && it->second->_macro.find("(") == std::string::npos)
|
||||
{
|
||||
str = it->second->_macro;
|
||||
if (str.find(" ") != std::string::npos)
|
||||
str.erase(0, str.find(" "));
|
||||
else
|
||||
str = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_variadic && tok->str() == "," && tok->next() && tok->next()->str() == "##")
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
" exit(1);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getnameinfo' function\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getaddrinfo' function\n", errout.str());
|
||||
}
|
||||
|
||||
void testgethostbyaddr()
|
||||
|
@ -116,7 +116,7 @@ private:
|
|||
" exit(1);\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getaddrinfo' function\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getnameinfo' function\n", errout.str());
|
||||
}
|
||||
|
||||
void testusleep()
|
||||
|
|
|
@ -159,7 +159,8 @@ private:
|
|||
TEST_CASE(macro_simple13);
|
||||
TEST_CASE(macro_simple14);
|
||||
TEST_CASE(macro_simple15);
|
||||
TEST_CASE(macroInMacro);
|
||||
TEST_CASE(macroInMacro1);
|
||||
TEST_CASE(macroInMacro2);
|
||||
TEST_CASE(macro_mismatch);
|
||||
TEST_CASE(macro_linenumbers);
|
||||
TEST_CASE(macro_nopar);
|
||||
|
@ -1692,7 +1693,7 @@ private:
|
|||
ASSERT_EQUALS("\n\"foo\"\n", OurPreprocessor::expandMacros(filedata));
|
||||
}
|
||||
|
||||
void macroInMacro()
|
||||
void macroInMacro1()
|
||||
{
|
||||
{
|
||||
const char filedata[] = "#define A(m) long n = m; n++;\n"
|
||||
|
@ -1793,6 +1794,14 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void macroInMacro2()
|
||||
{
|
||||
const char filedata[] = "#define A(x) a##x\n"
|
||||
"#define B 0\n"
|
||||
"A(B)\n";
|
||||
ASSERT_EQUALS("\n\naB\n", OurPreprocessor::expandMacros(filedata));
|
||||
}
|
||||
|
||||
void macro_mismatch()
|
||||
{
|
||||
const char filedata[] = "#define AAA(aa,bb) f(aa)\n"
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
<Component Id='GuiTranslations' Guid='$(var.guiTranslationsGUID)'>
|
||||
<File Id='cppcheck_de.qm' Name='cppcheck_de.qm' Source='$(var.TranslationsDir)\cppcheck_de.qm' />
|
||||
<File Id='cppcheck_en.qm' Name='cppcheck_en.qm' Source='$(var.TranslationsDir)\cppcheck_en.qm' />
|
||||
<File Id='cppcheck_es.qm' Name='cppcheck_es.qm' Source='$(var.TranslationsDir)\cppcheck_es.qm' />
|
||||
<File Id='cppcheck_fi.qm' Name='cppcheck_fi.qm' Source='$(var.TranslationsDir)\cppcheck_fi.qm' />
|
||||
<File Id='cppcheck_fr.qm' Name='cppcheck_fr.qm' Source='$(var.TranslationsDir)\cppcheck_fr.qm' />
|
||||
<File Id='cppcheck_ja.qm' Name='cppcheck_ja.qm' Source='$(var.TranslationsDir)\cppcheck_ja.qm' />
|
||||
|
|
Loading…
Reference in New Issue