some small cleanups and refactorings (#4488)
* moved `plistFile` from `ErrorLogger` to `CppCheck` * got rid of global CWE objects * lib/CMakeLists.txt: suppress some `-Wfloat-equal` clang warning in matchcompiled builds as well * lib/CMakeLists.txt: moved a loop into proper block * test/CMakeLists.txt: simplified `add_fixture` * test/CMakeLists.txt: moved `fixture_cost` * fixed `naming-privateMemberVariable` selfcheck warning
This commit is contained in:
parent
872be6564b
commit
dc03a50414
|
@ -37,6 +37,7 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib> // EXIT_FAILURE
|
#include <cstdlib> // EXIT_FAILURE
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
|
@ -22,11 +22,11 @@ function(build_src output filename)
|
||||||
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
|
||||||
foreach(file ${srcs})
|
foreach(file ${srcs})
|
||||||
build_src(srcs_build ${file})
|
build_src(srcs_build ${file})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
|
|
||||||
set(srcs_lib ${srcs_build})
|
set(srcs_lib ${srcs_build})
|
||||||
else()
|
else()
|
||||||
set(srcs_lib ${srcs})
|
set(srcs_lib ${srcs})
|
||||||
|
@ -53,7 +53,13 @@ endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
# -Wfloat-equal is generated by picojson.h
|
# -Wfloat-equal is generated by picojson.h
|
||||||
|
if (NOT USE_MATCHCOMPILER_OPT STREQUAL "Off")
|
||||||
|
set_source_files_properties(mc_cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
|
set_source_files_properties(mc_importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
|
set_source_files_properties(mc_settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
|
else()
|
||||||
set_source_files_properties(cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
set_source_files_properties(cppcheck.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
set_source_files_properties(importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
set_source_files_properties(importproject.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
set_source_files_properties(settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
set_source_files_properties(settings.cpp PROPERTIES COMPILE_FLAGS -Wno-float-equal)
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// CWE ids used:
|
||||||
|
static const struct CWE CWE_NULL_POINTER_DEREFERENCE(476U);
|
||||||
|
static const struct CWE CWE_INCORRECT_CALCULATION(682U);
|
||||||
|
|
||||||
// Register this check class (by creating a static instance of it)
|
// Register this check class (by creating a static instance of it)
|
||||||
namespace {
|
namespace {
|
||||||
CheckNullPointer instance;
|
CheckNullPointer instance;
|
||||||
|
|
|
@ -49,6 +49,10 @@ namespace tinyxml2 {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// CWE ids used:
|
||||||
|
static const struct CWE CWE_USE_OF_UNINITIALIZED_VARIABLE(457U);
|
||||||
|
static const struct CWE CWE_USE_OF_POTENTIALLY_DANGEROUS_FUNCTION(676U);
|
||||||
|
|
||||||
// Register this check class (by creating a static instance of it)
|
// Register this check class (by creating a static instance of it)
|
||||||
namespace {
|
namespace {
|
||||||
CheckUninitVar instance;
|
CheckUninitVar instance;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <fstream> // IWYU pragma: keep
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream> // IWYU pragma: keep
|
#include <sstream> // IWYU pragma: keep
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream> // <- TEMPORARY
|
#include <iostream> // <- TEMPORARY
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
@ -365,6 +366,11 @@ CppCheck::~CppCheck()
|
||||||
mFileInfo.pop_back();
|
mFileInfo.pop_back();
|
||||||
}
|
}
|
||||||
s_timerResults.showResults(mSettings.showtime);
|
s_timerResults.showResults(mSettings.showtime);
|
||||||
|
|
||||||
|
if (mPlistFile.is_open()) {
|
||||||
|
mPlistFile << ErrorLogger::plistFooter();
|
||||||
|
mPlistFile.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * CppCheck::version()
|
const char * CppCheck::version()
|
||||||
|
@ -606,9 +612,9 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plistFile.is_open()) {
|
if (mPlistFile.is_open()) {
|
||||||
plistFile << ErrorLogger::plistFooter();
|
mPlistFile << ErrorLogger::plistFooter();
|
||||||
plistFile.close();
|
mPlistFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr);
|
CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr);
|
||||||
|
@ -669,8 +675,8 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
||||||
filename2 = filename;
|
filename2 = filename;
|
||||||
std::size_t fileNameHash = std::hash<std::string> {}(filename);
|
std::size_t fileNameHash = std::hash<std::string> {}(filename);
|
||||||
filename2 = mSettings.plistOutput + filename2.substr(0, filename2.find('.')) + "_" + std::to_string(fileNameHash) + ".plist";
|
filename2 = mSettings.plistOutput + filename2.substr(0, filename2.find('.')) + "_" + std::to_string(fileNameHash) + ".plist";
|
||||||
plistFile.open(filename2);
|
mPlistFile.open(filename2);
|
||||||
plistFile << ErrorLogger::plistHeader(version(), files);
|
mPlistFile << ErrorLogger::plistHeader(version(), files);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream dumpProlog;
|
std::ostringstream dumpProlog;
|
||||||
|
@ -1551,9 +1557,9 @@ void CppCheck::reportErr(const ErrorMessage &msg)
|
||||||
|
|
||||||
mErrorLogger.reportErr(msg);
|
mErrorLogger.reportErr(msg);
|
||||||
// check if plistOutput should be populated and the current output file is open and the error is not suppressed
|
// check if plistOutput should be populated and the current output file is open and the error is not suppressed
|
||||||
if (!mSettings.plistOutput.empty() && plistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) {
|
if (!mSettings.plistOutput.empty() && mPlistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) {
|
||||||
// add error to plist output file
|
// add error to plist output file
|
||||||
plistFile << ErrorLogger::plistData(msg);
|
mPlistFile << ErrorLogger::plistData(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <fstream> // IWYU pragma: keep
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -238,6 +239,8 @@ private:
|
||||||
|
|
||||||
/** Callback for executing a shell command (exe, args, output) */
|
/** Callback for executing a shell command (exe, args, output) */
|
||||||
std::function<bool(std::string,std::vector<std::string>,std::string,std::string*)> mExecuteCommand;
|
std::function<bool(std::string,std::vector<std::string>,std::string,std::string*)> mExecuteCommand;
|
||||||
|
|
||||||
|
std::ofstream mPlistFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -27,24 +27,11 @@
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <fstream>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
|
||||||
* CWE id (Common Weakness Enumeration)
|
|
||||||
* See https://cwe.mitre.org/ for further reference.
|
|
||||||
* */
|
|
||||||
// CWE list: https://cwe.mitre.org/data/published/cwe_v3.4.1.pdf
|
|
||||||
static const struct CWE CWE_USE_OF_UNINITIALIZED_VARIABLE(457U);
|
|
||||||
static const struct CWE CWE_NULL_POINTER_DEREFERENCE(476U);
|
|
||||||
static const struct CWE CWE_USE_OF_POTENTIALLY_DANGEROUS_FUNCTION(676U);
|
|
||||||
static const struct CWE CWE_INCORRECT_CALCULATION(682U);
|
|
||||||
static const struct CWE CWE_EXPIRED_POINTER_DEREFERENCE(825U);
|
|
||||||
|
|
||||||
|
|
||||||
class Token;
|
class Token;
|
||||||
class TokenList;
|
class TokenList;
|
||||||
|
|
||||||
|
@ -231,16 +218,9 @@ private:
|
||||||
* should implement.
|
* should implement.
|
||||||
*/
|
*/
|
||||||
class CPPCHECKLIB ErrorLogger {
|
class CPPCHECKLIB ErrorLogger {
|
||||||
protected:
|
|
||||||
std::ofstream plistFile;
|
|
||||||
public:
|
public:
|
||||||
ErrorLogger() {}
|
ErrorLogger() {}
|
||||||
virtual ~ErrorLogger() {
|
virtual ~ErrorLogger() {}
|
||||||
if (plistFile.is_open()) {
|
|
||||||
plistFile << ErrorLogger::plistFooter();
|
|
||||||
plistFile.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about progress is directed here.
|
* Information about progress is directed here.
|
||||||
|
|
|
@ -63,26 +63,10 @@ if (BUILD_TESTS)
|
||||||
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
|
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
|
||||||
|
|
||||||
function(add_fixture NAME)
|
function(add_fixture NAME)
|
||||||
set(options)
|
|
||||||
set(oneValueArgs WORKING_DIRECTORY)
|
|
||||||
set(multiValueArgs)
|
|
||||||
|
|
||||||
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
||||||
|
|
||||||
if (${NAME} IN_LIST SKIP_TESTS)
|
if (${NAME} IN_LIST SKIP_TESTS)
|
||||||
elseif(TEST ${NAME})
|
elseif(TEST ${NAME})
|
||||||
else()
|
else()
|
||||||
set(WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
add_test(NAME ${NAME} COMMAND testrunner ${NAME} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
if (PARSE_WORKING_DIRECTORY)
|
|
||||||
set(WORKING_DIRECTORY ${PARSE_WORKING_DIRECTORY})
|
|
||||||
endif()
|
|
||||||
add_test(NAME ${NAME} COMMAND testrunner ${NAME} WORKING_DIRECTORY ${WORKING_DIRECTORY})
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(fixture_cost NAME COST)
|
|
||||||
if(TEST ${NAME})
|
|
||||||
set_tests_properties(${NAME} PROPERTIES COST ${COST})
|
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
@ -162,6 +146,12 @@ if (BUILD_TESTS)
|
||||||
add_cfg(windows.cpp INCONCLUSIVE NAME windows64 PLATFORM win64)
|
add_cfg(windows.cpp INCONCLUSIVE NAME windows64 PLATFORM win64)
|
||||||
add_cfg(wxwidgets.cpp INCONCLUSIVE)
|
add_cfg(wxwidgets.cpp INCONCLUSIVE)
|
||||||
|
|
||||||
|
function(fixture_cost NAME COST)
|
||||||
|
if(TEST ${NAME})
|
||||||
|
set_tests_properties(${NAME} PROPERTIES COST ${COST})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Set cost of the more expensive tests to help improve parallel scheduling
|
# Set cost of the more expensive tests to help improve parallel scheduling
|
||||||
# of tests
|
# of tests
|
||||||
fixture_cost(TestIO 20)
|
fixture_cost(TestIO 20)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "tokenlist.h"
|
#include "tokenlist.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sstream> // IWYU pragma: keep
|
#include <sstream> // IWYU pragma: keep
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
Loading…
Reference in New Issue