diff --git a/Framework/Crystal/src/LoadIsawPeaks.cpp b/Framework/Crystal/src/LoadIsawPeaks.cpp index a5dfeb4278dc536886acf0e8a5b705a03bae30f4..dce2c0b5ff8dfe9e0a6cbe3422c34d0f6d8094cf 100644 --- a/Framework/Crystal/src/LoadIsawPeaks.cpp +++ b/Framework/Crystal/src/LoadIsawPeaks.cpp @@ -68,7 +68,7 @@ int LoadIsawPeaks::confidence(Kernel::FileDescriptor &descriptor) const { throw std::logic_error(std::string("No Version for Peaks file")); getWord(in, false); // tag - std::string C_Facility = getWord(in, false); + getWord(in, false); // C_Facility getWord(in, false); // tag std::string C_Instrument = getWord(in, false); @@ -142,7 +142,7 @@ std::string LoadIsawPeaks::readHeader(const PeaksWorkspace_sptr &outWS, throw std::logic_error(std::string("No Version for Peaks file")); getWord(in, false); // tag - std::string C_Facility = getWord(in, false); + getWord(in, false); // C_Facility getWord(in, false); // tag std::string C_Instrument = getWord(in, false); diff --git a/Framework/DataHandling/src/LoadRaw/isisraw.cpp b/Framework/DataHandling/src/LoadRaw/isisraw.cpp index 60ed63f04b248c1f47b97bec4858b1089fa28c07..4f583929f01245a5ec2bea5a8cde64a08f63934f 100644 --- a/Framework/DataHandling/src/LoadRaw/isisraw.cpp +++ b/Framework/DataHandling/src/LoadRaw/isisraw.cpp @@ -715,10 +715,10 @@ int ISISRAW::ioRAW(FILE *file, LOG_STRUCT *s, int len, bool from_file) { int ISISRAW::ioRAW(FILE *file, LOG_LINE *s, int len, bool from_file) { char padding[5]; memset(padding, ' ', sizeof(padding)); - int i, nbytes_rounded; + int i; for (i = 0; i < len; i++) { ioRAW(file, &(s[i].len), 1, from_file); - nbytes_rounded = 4 * (1 + (s[i].len - 1) / 4); + int nbytes_rounded = 4 * (1 + (s[i].len - 1) / 4); ioRAW(file, &(s[i].data), s[i].len, from_file); ioRAW(file, padding, nbytes_rounded - s[i].len, from_file); } @@ -731,12 +731,11 @@ int ISISRAW::ioRAW(FILE *file, char *s, int len, bool from_file) { return 0; } - size_t n; if (from_file) { - n = fread(s, sizeof(char), len, file); + size_t n = fread(s, sizeof(char), len, file); return static_cast<int>(n - len); } else { - n = fwrite(s, sizeof(char), len, file); + fwrite(s, sizeof(char), len, file); } return 0; @@ -748,12 +747,11 @@ int ISISRAW::ioRAW(FILE *file, int *s, int len, bool from_file) { return 0; } - size_t n; if (from_file) { - n = fread(s, sizeof(int), len, file); + size_t n = fread(s, sizeof(int), len, file); return static_cast<int>(n - len); } else { - n = fwrite(s, sizeof(int), len, file); + fwrite(s, sizeof(int), len, file); } return 0; @@ -765,12 +763,11 @@ int ISISRAW::ioRAW(FILE *file, uint32_t *s, int len, bool from_file) { return 0; } - size_t n; if (from_file) { - n = fread(s, sizeof(uint32_t), len, file); + size_t n = fread(s, sizeof(uint32_t), len, file); return static_cast<int>(n - len); } else { - n = fwrite(s, sizeof(uint32_t), len, file); + fwrite(s, sizeof(uint32_t), len, file); } return 0; } @@ -782,14 +779,13 @@ int ISISRAW::ioRAW(FILE *file, float *s, int len, bool from_file) { return 0; } - size_t n; if (from_file) { - n = fread(s, sizeof(float), len, file); + size_t n = fread(s, sizeof(float), len, file); vaxf_to_local(s, &len, &errcode); return static_cast<int>(n - len); } else { local_to_vaxf(s, &len, &errcode); - n = fwrite(s, sizeof(float), len, file); + fwrite(s, sizeof(float), len, file); vaxf_to_local(s, &len, &errcode); } return 0; @@ -942,6 +938,7 @@ int ISISRAW::vmstime(char *timbuf, int len, time_t time_value) { * get time in VMS format 01-JAN-1970 00:00:00 */ size_t i, n; + // cppcheck-suppress redundantAssignment struct tm *tmstruct = nullptr; #ifdef MS_VISUAL_STUDIO errno_t err = localtime_s(tmstruct, &time_value); diff --git a/Framework/ICat/inc/MantidICat/ICat4/ICat4Catalog.h b/Framework/ICat/inc/MantidICat/ICat4/ICat4Catalog.h index 0fdc12b12153a8d69a31963c7674e7107fdd4e8d..b0e5ac59b1e0141b8f07ab7aa184325b4f68c525 100644 --- a/Framework/ICat/inc/MantidICat/ICat4/ICat4Catalog.h +++ b/Framework/ICat/inc/MantidICat/ICat4/ICat4Catalog.h @@ -79,7 +79,7 @@ private: void saveDataFiles(std::vector<ICat4::xsd__anyType *> response, API::ITableWorkspace_sptr &outputws); // Saves "DataSets" information to the output workspace. - void saveDataSets(const std::vector<ICat4::xsd__anyType *> &response, + void saveDataSets(std::vector<ICat4::xsd__anyType *> response, API::ITableWorkspace_sptr &outputws); // Convert a file size to human readable file format. std::string bytesToString(int64_t &fileSize); diff --git a/Framework/ICat/src/CatalogLogin.cpp b/Framework/ICat/src/CatalogLogin.cpp index bb03ee258fee8a9bec243e812e4cff8c608ac864..d40247dda008c5d46a99962ee2a0cc7deb62cb73 100644 --- a/Framework/ICat/src/CatalogLogin.cpp +++ b/Framework/ICat/src/CatalogLogin.cpp @@ -24,7 +24,7 @@ namespace { std::vector<std::string> namesOfFacilitiesWithICAT() { const auto &config = Kernel::ConfigService::Instance(); - const auto facilityDoesNotHaveICAT = [&](const std::string &name) { + const auto facilityDoesNotHaveICAT = [&](std::string name) { return config.getFacility(name).catalogInfo().soapEndPoint().empty(); }; diff --git a/Framework/ICat/src/ICat4/ICat4Catalog.cpp b/Framework/ICat/src/ICat4/ICat4Catalog.cpp index babd68ba9aa7c503430eb3003f8846a0d1c1ed86..baf14af9cfee7395918b2bf1378203520fcfcdd8 100644 --- a/Framework/ICat/src/ICat4/ICat4Catalog.cpp +++ b/Framework/ICat/src/ICat4/ICat4Catalog.cpp @@ -435,7 +435,7 @@ void ICat4Catalog::getDataSets(const std::string &investigationId, * @param response :: A vector containing the results of the search query. * @param outputws :: Shared pointer to output workspace. */ -void ICat4Catalog::saveDataSets(const std::vector<xsd__anyType *> &response, +void ICat4Catalog::saveDataSets(std::vector<xsd__anyType *> response, API::ITableWorkspace_sptr &outputws) { if (outputws->getColumnNames().empty()) { // Add rows headers to the output workspace. diff --git a/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp b/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp index 3ac632ce22bc2cb6f4a5f2157a91c00455eecddc..0a1d994f055b40da16b6730c209c505b265a3bf9 100644 --- a/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp +++ b/Framework/LiveData/src/ISIS/DAE/isisds_command.cpp @@ -86,10 +86,10 @@ typedef struct { /* wait until read len bytes, return <=0 on error */ static int recv_all(SOCKET s, void *buffer, int len, int flags) { auto *cbuffer = reinterpret_cast<char *>(buffer); - int n, ntot; + int ntot; ntot = 0; while (len > 0) { - n = recv(s, cbuffer, len, flags); + int n = recv(s, cbuffer, len, flags); if (n <= 0) { return n; /* error */ } @@ -283,7 +283,7 @@ int isisds_send_command(SOCKET s, const char *command, const void *data, static int isisds_recv_command_helper(SOCKET s, char **command, void **data, ISISDSDataType *type, int dims_array[], int *ndims, int do_alloc) { - int n, len_data, size_in, i; + int n, len_data, i; isisds_command_header_t comm; n = recv_all(s, reinterpret_cast<char *>(&comm), sizeof(comm), 0); if (n != sizeof(comm)) { @@ -308,7 +308,7 @@ static int isisds_recv_command_helper(SOCKET s, char **command, void **data, *data = malloc(len_data + 1); (reinterpret_cast<char *>(*data))[len_data] = '\0'; } else { - size_in = 1; + int size_in = 1; for (i = 0; i < *ndims; i++) { size_in *= dims_array[i]; } diff --git a/buildconfig/CMake/CppCheckSetup.cmake b/buildconfig/CMake/CppCheckSetup.cmake index b825a1086b1f1f0569d34df41f0c47d72c40ccd5..cf1df3315898c12266a409d1cb05b766c0bf4780 100644 --- a/buildconfig/CMake/CppCheckSetup.cmake +++ b/buildconfig/CMake/CppCheckSetup.cmake @@ -11,8 +11,10 @@ if ( CPPCHECK_EXECUTABLE ) # setup the standard arguments set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120 --suppressions-list=${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt - --suppress=*:*${CMAKE_BINARY_DIR}/* --project=${CMAKE_BINARY_DIR}/compile_commands.json + # Force cppcheck to check when we use project-wide macros + -DDLLExport= + -DMANTID_ALGORITHMS_DLL= ) set (_cppcheck_args "${CPPCHECK_ARGS}") diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index 9f17522e55dd072704235bea17bb93ad3ca2c270..ed2ac5eb001b00f7453cbb1aeaf63182d8424d48 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -1,8 +1,93 @@ // suppress specific rule in specific files // NOTE this needs the full path to the file, so would need this file to be generated by cmake // as different build servers have different starts to the file path -// Example: -// memsetClassFloat:/Users/builder/Jenkins/workspace/cppcheck-1.72/ + + + +// -------- Project Wide ------------------ // Hide warnings about using explicit keyword constructors as we have "too many" -noExplicitConstructor \ No newline at end of file +// and automated clang-tidy breaks a couple of implicit conversions we use widely +noExplicitConstructor + +// Hide warnings about shadowed members for inheritance. Typically "m_log" with Algorithm +duplInheritedMember + +// We have some potentially uninitialized member vars but too many to fix at the moment +uninitMemberVar + +// Cppcheck struggles with some inheritance chains, some of these might be true though +unusedPrivateFunction + +// Nice to have, not need to have at the moment +useInitializationList + +// A large number of copying instead of pass by ref were picked up by clang-tidy, but around 200 remain +passedByValue + +// Around 100 of these exist where noConstructor is present +noConstructor + +// Pre-processor Directives, such as #error, which are upstream anyway +preprocessorErrorDirective + +// ---------- cppcheck 1.90 Transition ------- +// If-init not supported +syntaxError:${CMAKE_SOURCE_DIR}/Framework/API/src/MatrixWorkspace.cpp + +// ---------- Individual suppressions ----------------- + +// Mantid Plot specific ones we probably won't fix before removal +cstyleCase:*${CMAKE_SOURCE_DIR}/MantidPlot +*:${CMAKE_SOURCE_DIR}/MantidPlot/src/origin/tree.hh +*:${CMAKE_SOURCE_DIR}/MantidPlot/src/nrutil.cpp + +// Macro expansion means this is incorrectly flagged on Unix +redundantAssignment:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadRaw/isisraw.cpp + +// Ones below was beyond the Cppcheck 1.90 migration scope +pureVirtualCall:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/Indirect/IndirectBayesTab.cpp + +// Ref binding means Cppcheck can't see these are used +unreadVariable:${CMAKE_SOURCE_DIR}/Framework/Algorithms/src/MaskBinsIf.cpp + +// --------- Missing copy assignment / constructors ------------------- +// We don't want more creeping in so just mark these one by one + +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/BoxController.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/ExperimentInfo.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/IFunction.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MDGeometry.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/MultipleExperimentInfos.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/SingleValueParameter.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/API/inc/MantidAPI/VectorParameter.h + +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/Catalog/inc/MantidCatalog/ONCat.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/Catalog/inc/MantidCatalog/ONCatEntity.h + +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/Crystal/inc/MantidCrystal/IndexSXPeaks.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/Framework/Crystal/inc/MantidCrystal/IntegratePeakTimeSlices.h + +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/qt/widgets/plotting/inc/MantidQtWidgets/Plotting/Qwt/QwtWorkspaceBinData.h +copyCtorAndEqOperator:${CMAKE_SOURCE_DIR}/qt/widgets/plotting/inc/MantidQtWidgets/Plotting/Qwt/QwtWorkspaceSpectrumData.h + +noCopyConstructor:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/BankPulseTimes.h +noCopyConstructor:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadRaw/isisraw.h + +// ----------------- Upstream libs --------------- + +// Always ignore bin dir +*:*${CMAKE_BINARY_DIR}/* + +// For some reason upstream libs sometimes end up in the check results +*:*/usr/include/* + +// All ANN files as they are upstream anyway +*:*${CMAKE_SOURCE_DIR}/Framework/Kernel/src/ANN/* + +// Libs we have in-source +*:*${CMAKE_SOURCE_DIR}/Framework/DataObjects/inc/MantidDataObjects/MortonIndex/* +*:*${CMAKE_SOURCE_DIR}/Framework/ICat/src/GSoap/* +*:*${CMAKE_SOURCE_DIR}/ICat/src/ICat3/GSoapGenerated/* +*:*${CMAKE_SOURCE_DIR}/ICat/src/ICat4/GSoapGenerated/* +*:*${CMAKE_SOURCE_DIR}/MantidPlot/src/zlib123/* diff --git a/qt/scientific_interfaces/Indirect/IndirectBayesTab.cpp b/qt/scientific_interfaces/Indirect/IndirectBayesTab.cpp index 050001f810f021eeaa47d54d14015cf47e2eb011..07d99f46148827fc4a9d268a6f461e22401d2ace 100644 --- a/qt/scientific_interfaces/Indirect/IndirectBayesTab.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectBayesTab.cpp @@ -13,7 +13,9 @@ IndirectBayesTab::IndirectBayesTab(QWidget *parent) : IndirectTab(parent), m_propTree(new QtTreePropertyBrowser()) { m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac); + // cppcheck-suppress pureVirtualCall connect(m_dblManager, SIGNAL(valueChanged(QtProperty *, double)), this, + // cppcheck-suppress pureVirtualCall SLOT(updateProperties(QtProperty *, double))); } diff --git a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp index eafa0818ac2602c7720bc0e980956fd4a3c0cc5c..3039804bcef9a0a3ee99b0f86988a388e6616e3e 100644 --- a/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp +++ b/qt/scientific_interfaces/Indirect/IndirectDataTablePresenter.cpp @@ -216,11 +216,11 @@ IndirectDataTablePresenter::getSpectra(TableRowIndex start, while (start < end) { WorkspaceIndex minimum = getWorkspaceIndex(start); WorkspaceIndex maximum = minimum; - start++; + ++start; while (start < end && getWorkspaceIndex(start) == maximum + WorkspaceIndex{1}) { ++maximum; - start++; + ++start; } spectraPairs.emplace_back(minimum, maximum); } diff --git a/qt/widgets/common/src/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp b/qt/widgets/common/src/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp index bf89eb4fde6cc877dc10e35056ac6412ecf239a6..5d38e2237fa91442f937470c362504f6aae4bcb6 100644 --- a/qt/widgets/common/src/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp +++ b/qt/widgets/common/src/QtPropertyBrowser/qtgroupboxpropertybrowser.cpp @@ -308,15 +308,12 @@ void QtGroupBoxPropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index) { } else { WidgetItem *par = parentItem->parent; QGridLayout *l = nullptr; - int oldRow = -1; if (!par) { l = m_mainLayout; - oldRow = m_children.indexOf(parentItem); + m_children.indexOf(parentItem); } else { l = par->layout; - oldRow = par->children.indexOf(parentItem); - if (hasHeader(par)) - oldRow += 2; + par->children.indexOf(parentItem); } if (parentItem->widget) {