Skip to content

Commit

Permalink
Merge branch 'danmar:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Oct 8, 2023
2 parents 247b2ae + cc44966 commit cc69147
Show file tree
Hide file tree
Showing 80 changed files with 651 additions and 454 deletions.
32 changes: 16 additions & 16 deletions Makefile

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ static void misra_10_3(uint32_t u32a, uint32_t u32b) {
res = 2U + 3U; // no warning, utlr=unsigned char
res = 0.1f; // 10.3
const char c = '0'; // no-warning
uint32_t u = UINT32_C(10); // no-warning
}

static void misra_10_4(u32 x, s32 y) {
Expand Down
14 changes: 0 additions & 14 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0"?>
<def format="2">
<!-- helpers -->
<define name="__CONCATenate(left, right)" value="left ## right"/>
<define name="__CONCAT(left, right)" value="__CONCATenate(left, right)"/>
<!-- stdint.h -->
<define name="INT8_MIN" value="-128"/>
<define name="INT16_MIN" value="-32768"/>
Expand Down Expand Up @@ -40,17 +37,6 @@
<define name="UINT_LEAST16_MAX" value="65535U"/>
<define name="UINT_LEAST32_MAX" value="4294967295U"/>
<define name="UINT_LEAST64_MAX" value="18446744073709551615U"/>
<!-- Macros for integer constants -->
<define name="INT8_C(value)" value="((int8_t) value)"/>
<define name="UINT8_C(value)" value="((uint8_t) __CONCAT(value, U))"/>
<define name="INT16_C(value)" value="value"/>
<define name="UINT16_C(value)" value="__CONCAT(value, U)"/>
<define name="INT32_C(value)" value="__CONCAT(value, L)"/>
<define name="UINT32_C(value)" value="__CONCAT(value, UL)"/>
<define name="INT64_C(value)" value="__CONCAT(value, LL)"/>
<define name="UINT64_C(value)" value="__CONCAT(value, ULL)"/>
<define name="INTMAX_C(value)" value="__CONCAT(value, LL)"/>
<define name="UINTMAX_C(value)" value="__CONCAT(value, ULL)"/>
<!-- math.h -->
<define name="M_E" value="2.7182818284590452354"/>
<define name="M_LOG2E" value="1.4426950408889634074"/>
Expand Down
4 changes: 2 additions & 2 deletions cfg/windows.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4791,7 +4791,7 @@ HFONT CreateFont(
</function>
<!--BOOL WINAPI FlushConsoleInputBuffer(_In_ HANDLE hConsoleInput);-->
<function name="FlushConsoleInputBuffer">
<noreturn>true</noreturn>
<noreturn>false</noreturn>
<returnValue type="BOOL"/>
<leak-ignore/>
<arg nr="1" direction="in">
Expand Down Expand Up @@ -4825,7 +4825,7 @@ HFONT CreateFont(
<not-uninit/>
<not-bool/>
</arg>
<arg nr="2" direction="in">
<arg nr="2" direction="out">
<not-uninit/>
<strz/>
<minsize type="argvalue" arg="3"/>
Expand Down
17 changes: 15 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,17 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])

// --project
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
if (mSettings.project.projectType != ImportProject::Type::NONE)
{
mLogger.printError("multiple --project options are not supported.");
return false;
}

mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force
std::string projectFile = argv[i]+10;
ImportProject::Type projType = mSettings.project.import(projectFile, &mSettings);
mSettings.project.projectType = projType;
if (projType == ImportProject::Type::CPPCHECK_GUI) {
mPathNames = mSettings.project.guiProject.pathNames;
for (const std::string &lib : mSettings.project.guiProject.libraries)
mSettings.libraries.emplace_back(lib);

Expand Down Expand Up @@ -1026,12 +1031,20 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
return true;
}

if (!mPathNames.empty() && mSettings.project.projectType != ImportProject::Type::NONE) {
mLogger.printError("--project cannot be used in conjunction with source files.");
return false;
}

// Print error only if we have "real" command and expect files
if (!mExitAfterPrint && mPathNames.empty() && mSettings.project.fileSettings.empty()) {
if (!mExitAfterPrint && mPathNames.empty() && mSettings.project.guiProject.pathNames.empty() && mSettings.project.fileSettings.empty()) {
mLogger.printError("no C or C++ source files found.");
return false;
}

if (!mSettings.project.guiProject.pathNames.empty())
mPathNames = mSettings.project.guiProject.pathNames;

// Use paths _pathnames if no base paths for relative path output are given
if (mSettings.basePaths.empty() && mSettings.relativePaths)
mSettings.basePaths = mPathNames;
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
returnValue = executor.check();
} else {
#if defined(THREADING_MODEL_THREAD)
ThreadExecutor executor(mFiles, settings, settings.nomsg, *this);
ThreadExecutor executor(mFiles, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
#elif defined(THREADING_MODEL_FORK)
ProcessExecutor executor(mFiles, settings, settings.nomsg, *this);
ProcessExecutor executor(mFiles, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
#endif
returnValue = executor.check();
}
Expand Down
2 changes: 1 addition & 1 deletion cli/filelister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
std::string new_path = path;
new_path += '/';

while (const struct dirent* dir_result = readdir(dir)) {
while (const dirent* dir_result = readdir(dir)) {
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
(std::strcmp(dir_result->d_name, "..") == 0))
continue;
Expand Down
7 changes: 4 additions & 3 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ enum class Color;
using std::memset;


ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
assert(mSettings.jobs > 1);
}
Expand Down Expand Up @@ -272,7 +273,7 @@ unsigned int ProcessExecutor::check()
close(pipes[0]);

PipeWriter pipewriter(pipes[1]);
CppCheck fileChecker(pipewriter, false, CppCheckExecutor::executeCommand);
CppCheck fileChecker(pipewriter, false, mExecuteCommand);
fileChecker.settings() = mSettings;
unsigned int resultOfCheck = 0;

Expand Down Expand Up @@ -306,7 +307,7 @@ unsigned int ProcessExecutor::check()
FD_ZERO(&rfds);
for (std::list<int>::const_iterator rp = rpipes.cbegin(); rp != rpipes.cend(); ++rp)
FD_SET(*rp, &rfds);
struct timeval tv; // for every second polling of load average condition
timeval tv; // for every second polling of load average condition
tv.tv_sec = 1;
tv.tv_usec = 0;
const int r = select(*std::max_element(rpipes.cbegin(), rpipes.cend()) + 1, &rfds, nullptr, nullptr, &tv);
Expand Down
5 changes: 4 additions & 1 deletion cli/processexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef PROCESSEXECUTOR_H
#define PROCESSEXECUTOR_H

#include "cppcheck.h"
#include "executor.h"

#include <cstddef>
Expand All @@ -38,7 +39,7 @@ class Suppressions;
*/
class ProcessExecutor : public Executor {
public:
ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
ProcessExecutor(const ProcessExecutor &) = delete;
void operator=(const ProcessExecutor &) = delete;

Expand All @@ -63,6 +64,8 @@ class ProcessExecutor : public Executor {
* @param msg The error message
*/
void reportInternalChildErr(const std::string &childname, const std::string &msg);

CppCheck::ExecuteCmdFn mExecuteCommand;
};

/// @}
Expand Down
12 changes: 7 additions & 5 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

enum class Color;

ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
assert(mSettings.jobs > 1);
}
Expand Down Expand Up @@ -82,8 +83,8 @@ class SyncLogForwarder : public ErrorLogger
class ThreadData
{
public:
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::map<std::string, std::size_t> &files, const std::list<ImportProject::FileSettings> &fileSettings)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), logForwarder(threadExecutor, errorLogger)
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::map<std::string, std::size_t> &files, const std::list<ImportProject::FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
{
mItNextFile = mFiles.begin();
mItNextFileSettings = mFileSettings.begin();
Expand Down Expand Up @@ -115,7 +116,7 @@ class ThreadData
}

unsigned int check(ErrorLogger &errorLogger, const std::string *file, const ImportProject::FileSettings *fs) const {
CppCheck fileChecker(errorLogger, false, CppCheckExecutor::executeCommand);
CppCheck fileChecker(errorLogger, false, mExecuteCommand);
fileChecker.settings() = mSettings; // this is a copy

unsigned int result;
Expand Down Expand Up @@ -153,6 +154,7 @@ class ThreadData

std::mutex mFileSync;
const Settings &mSettings;
CppCheck::ExecuteCmdFn mExecuteCommand;

public:
SyncLogForwarder logForwarder;
Expand Down Expand Up @@ -180,7 +182,7 @@ unsigned int ThreadExecutor::check()
std::vector<std::future<unsigned int>> threadFutures;
threadFutures.reserve(mSettings.jobs);

ThreadData data(*this, mErrorLogger, mSettings, mFiles, mSettings.project.fileSettings);
ThreadData data(*this, mErrorLogger, mSettings, mFiles, mSettings.project.fileSettings, mExecuteCommand);

for (unsigned int i = 0; i < mSettings.jobs; ++i) {
try {
Expand Down
7 changes: 5 additions & 2 deletions cli/threadexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef THREADEXECUTOR_H
#define THREADEXECUTOR_H

#include "cppcheck.h"
#include "executor.h"

#include <cstddef>
Expand All @@ -37,14 +38,16 @@ class Suppressions;
* all files using threads.
*/
class ThreadExecutor : public Executor {
friend class SyncLogForwarder;

public:
ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
ThreadExecutor(const ThreadExecutor &) = delete;
void operator=(const ThreadExecutor &) = delete;

unsigned int check() override;

friend class SyncLogForwarder;
CppCheck::ExecuteCmdFn mExecuteCommand;
};

/// @}
Expand Down
8 changes: 4 additions & 4 deletions gui/cppchecklibrarydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)
break;
if (type != QXmlStreamReader::StartElement)
continue;
struct CppcheckLibraryData::Container::Function function;
CppcheckLibraryData::Container::Function function;
function.name = xmlReader.attributes().value("name").toString();
function.action = xmlReader.attributes().value("action").toString();
function.yields = xmlReader.attributes().value("yields").toString();
Expand All @@ -91,7 +91,7 @@ static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)
else if (elementName == "access")
container.accessFunctions.append(function);
else if (elementName == "rangeItemRecordType") {
struct CppcheckLibraryData::Container::RangeItemRecordType rangeItemRecordType;
CppcheckLibraryData::Container::RangeItemRecordType rangeItemRecordType;
rangeItemRecordType.name = xmlReader.attributes().value("name").toString();
rangeItemRecordType.templateParameter = xmlReader.attributes().value("templateParameter").toString();
container.rangeItemRecordTypeList.append(rangeItemRecordType);
Expand Down Expand Up @@ -518,7 +518,7 @@ QString CppcheckLibraryData::open(QIODevice &file)
return QString();
}

static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString &name, int extra, const QList<struct CppcheckLibraryData::Container::Function> &functions)
static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString &name, int extra, const QList<CppcheckLibraryData::Container::Function> &functions)
{
if (functions.isEmpty() && extra < 0)
return;
Expand All @@ -541,7 +541,7 @@ static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString &
xmlWriter.writeEndElement();
}

static void writeContainerRangeItemRecords(QXmlStreamWriter &xmlWriter, const QList<struct CppcheckLibraryData::Container::RangeItemRecordType> &rangeItemRecords)
static void writeContainerRangeItemRecords(QXmlStreamWriter &xmlWriter, const QList<CppcheckLibraryData::Container::RangeItemRecordType> &rangeItemRecords)
{
if (rangeItemRecords.isEmpty())
return;
Expand Down
38 changes: 19 additions & 19 deletions gui/cppchecklibrarydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class CppcheckLibraryData {
QString yields;
QString action;
};
QList<struct Function> accessFunctions;
QList<struct Function> otherFunctions;
QList<struct Function> sizeFunctions;
QList<struct RangeItemRecordType> rangeItemRecordTypeList;
QList<Function> accessFunctions;
QList<Function> otherFunctions;
QList<Function> sizeFunctions;
QList<RangeItemRecordType> rangeItemRecordTypeList;
};

struct Define {
Expand Down Expand Up @@ -106,13 +106,13 @@ class CppcheckLibraryData {
QString arg;
QString arg2;
};
QList<struct MinSize> minsizes;
QList<MinSize> minsizes;
struct Iterator {
int container = -1;
QString type;
} iterator;
};
QList<struct Arg> args;
QList<Arg> args;

struct {
QString severity;
Expand Down Expand Up @@ -149,8 +149,8 @@ class CppcheckLibraryData {
QString name;
};

QList<struct Alloc> alloc;
QList<struct Dealloc> dealloc;
QList<Alloc> alloc;
QList<Dealloc> dealloc;
QStringList use;
};

Expand All @@ -176,7 +176,7 @@ class CppcheckLibraryData {
QString name;
};

QList<struct Call> calls;
QList<Call> calls;
};

struct Markup {
Expand Down Expand Up @@ -244,18 +244,18 @@ class CppcheckLibraryData {
QString open(QIODevice &file);
QString toString() const;

QList<struct Container> containers;
QList<struct Define> defines;
QList<struct Function> functions;
QList<struct MemoryResource> memoryresource;
QList<struct PodType> podtypes;
QList<Container> containers;
QList<Define> defines;
QList<Function> functions;
QList<MemoryResource> memoryresource;
QList<PodType> podtypes;
QList<TypeChecks> typeChecks;
QList<struct PlatformType> platformTypes;
QList<PlatformType> platformTypes;
QStringList undefines;
QList<struct SmartPointer> smartPointers;
QList<struct Reflection> reflections;
QList<struct Markup> markups;
QList<struct Entrypoint> entrypoints;
QList<SmartPointer> smartPointers;
QList<Reflection> reflections;
QList<Markup> markups;
QList<Entrypoint> entrypoints;
};

#endif // CPPCHECKLIBRARYDATA_H
3 changes: 3 additions & 0 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,9 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
case ImportProject::Type::FAILURE:
errorMessage = tr("Failed to import project file");
break;
case ImportProject::Type::NONE:
// can never happen
break;
}

if (!errorMessage.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ bool ProjectFile::read(const QString &filename)
return projectTagFound;
}

void ProjectFile::readRootPath(QXmlStreamReader &reader)
void ProjectFile::readRootPath(const QXmlStreamReader &reader)
{
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), CppcheckXml::RootPathNameAttrib).toString();
Expand Down
2 changes: 1 addition & 1 deletion gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class ProjectFile : public QObject {
* @brief Read optional root path from XML.
* @param reader XML stream reader.
*/
void readRootPath(QXmlStreamReader &reader);
void readRootPath(const QXmlStreamReader &reader);

void readBuildDir(QXmlStreamReader &reader);

Expand Down
Loading

0 comments on commit cc69147

Please sign in to comment.