Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: iwyu_tool
run: |
PWD=$(pwd)
iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log
iwyu_tool -p cmake.output -j $(nproc) -- -w -Xiwyu --max_line_length=1024 -Xiwyu --comment_style=long -Xiwyu --quoted_includes_first -Xiwyu --update_comments -Xiwyu --mapping_file=$PWD/qt5.imp > iwyu.log

- uses: actions/upload-artifact@v3
if: success() || failure()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ test/testsizeof.o: test/testsizeof.cpp lib/addoninfo.h lib/check.h lib/checksize
test/teststl.o: test/teststl.cpp lib/addoninfo.h lib/check.h lib/checkstl.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststl.cpp

test/teststring.o: test/teststring.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
test/teststring.o: test/teststring.cpp lib/addoninfo.h lib/check.h lib/checkstring.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/teststring.cpp

test/testsummaries.o: test/testsummaries.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h
Expand Down
7 changes: 7 additions & 0 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ def getEssentialTypeCategory(expr):
return 'char'
return expr.valueType.sign

if (expr.isCast and expr.str == "("):
castTok = expr.next
while castTok.isName or castTok.str == "*":
if castTok.str == 'char' and not castTok.isSigned and not castTok.isUnsigned:
return 'char'
castTok = castTok.next

if expr.valueType:
return expr.valueType.sign
return None
Expand Down
6 changes: 6 additions & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ static void misra_10_4(u32 x, s32 y) {
if ('\0' == cmd.buf[0]) //no-warning
{
}

// #10652
char c;
if ((char)'1' == c) {} // no warning
if ((unsigned char)'1' == c) {} //10.4
if ((signed char)'1' == c) {} //10.4
}

static void misra_10_5(uint16_t x) {
Expand Down
5 changes: 3 additions & 2 deletions cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <features.h> // __USE_DYNAMIC_STACK_SIZE
#include <map>
#include <string>
#include <unistd.h>
Expand All @@ -48,7 +49,7 @@
# include <ucontext.h>
#endif


// TODO: __USE_DYNAMIC_STACK_SIZE is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it
#ifdef __USE_DYNAMIC_STACK_SIZE
static const size_t MYSTACKSIZE = 16*1024+32768; // wild guess about a reasonable buffer
#else
Expand Down Expand Up @@ -320,7 +321,7 @@ int check_wrapper_sig(CppCheckExecutor& executor, int (CppCheckExecutor::*f)(Cpp
for (std::map<int, std::string>::const_iterator sig=listofsignals.cbegin(); sig!=listofsignals.cend(); ++sig) {
sigaction(sig->first, &act, nullptr);
}
return (&executor->*f)(cppcheck);
return (executor.*f)(cppcheck);
}

#endif
2 changes: 1 addition & 1 deletion cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Executor::Executor(const std::map<std::string, std::size_t> &files, const Settin

bool Executor::hasToLog(const ErrorMessage &msg)
{
if (!mSuppressions.isSuppressed(msg))
if (!mSuppressions.isSuppressed(msg, {}))
{
std::string errmsg = msg.toString(mSettings.verbose);

Expand Down
2 changes: 1 addition & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
"cppcheckError",
Certainty::normal);

if (!mSuppressions.isSuppressed(errmsg))
if (!mSuppressions.isSuppressed(errmsg, {}))
mErrorLogger.reportErr(errmsg);
}

Expand Down
2 changes: 1 addition & 1 deletion gui/platforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ PlatformData& Platforms::get(Platform::Type platform)
{
QList<PlatformData>::iterator iter = mPlatforms.begin();
while (iter != mPlatforms.end()) {
if ((*iter).mType == platform) {
if (iter->mType == platform) {
return *iter;
}
++iter;
Expand Down
1 change: 1 addition & 0 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "common.h"
#include "config.h"
#include "erroritem.h"
#include "errortypes.h"
#include "path.h"
#include "projectfile.h"
#include "report.h"
Expand Down
2 changes: 1 addition & 1 deletion gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef RESULTSTREE_H
#define RESULTSTREE_H

#include "errortypes.h"
#include "showtypes.h"

#include <QObject>
Expand All @@ -40,6 +39,7 @@ class ThreadHandler;
class QContextMenuEvent;
class QKeyEvent;
class QSettings;
enum class Severity;

/// @addtogroup GUI
/// @{
Expand Down
1 change: 1 addition & 0 deletions gui/showtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "showtypes.h"

#include "common.h"
#include "errortypes.h"

#include <QSettings>

Expand Down
4 changes: 2 additions & 2 deletions gui/showtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef SHOWTYPES_H
#define SHOWTYPES_H

#include "errortypes.h"

#include <QVariant>

enum class Severity;

/// @addtogroup GUI
/// @{

Expand Down
1 change: 1 addition & 0 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//---------------------------------------------------------------------------

#include <functional>
#include <list>
#include <stack>
#include <string>
#include <type_traits>
Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)

const std::map<std::string, Type*>::const_iterator end = scope->definedTypesMap.cend();
for (std::map<std::string, Type*>::const_iterator iter = scope->definedTypesMap.cbegin(); iter != end; ++iter) {
const Type *type = (*iter).second;
const Type *type = iter->second;
if (type->enclosingScope == scope && checkFunctionUsage(privfunc, type->classScope))
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checkinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void CheckInternal::checkMissingPercentCharacter()

std::set<std::string>::const_iterator knownPattern, knownPatternsEnd = knownPatterns.cend();
for (knownPattern = knownPatterns.cbegin(); knownPattern != knownPatternsEnd; ++knownPattern) {
const std::string brokenPattern = (*knownPattern).substr(0, (*knownPattern).size() - 1);
const std::string brokenPattern = knownPattern->substr(0, knownPattern->size() - 1);

std::string::size_type pos = 0;
while ((pos = pattern.find(brokenPattern, pos)) != std::string::npos) {
Expand Down
1 change: 1 addition & 0 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//---------------------------------------------------------------------------
#include "checkio.h"

#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <ostream>
Expand All @@ -34,6 +33,7 @@ class Settings;
class Token;
class Variable;
class ErrorLogger;
enum class Severity;

/// @addtogroup Checks
/// @{
Expand Down
1 change: 1 addition & 0 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "astutils.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
Expand Down
3 changes: 2 additions & 1 deletion lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include "check.h"
#include "config.h"
#include "errortypes.h"
#include "tokenize.h"

#include <list>
Expand All @@ -46,6 +45,8 @@ class Settings;
class Token;
class Variable;
class ErrorLogger;
struct CWE;
enum class Severity;

/// @addtogroup Core
/// @{
Expand Down
1 change: 0 additions & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <set>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static const std::string emptyString;
#define USE_WINDOWS_SEH
#endif

// TODO: __GLIBC__ is depedent on the features.h include and not a built-in compiler define, so it might be problematic to depedent on it
#if !defined(NO_UNIX_BACKTRACE_SUPPORT) && defined(__GNUC__) && defined(__GLIBC__) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__NetBSD__) && !defined(__SVR4) && !defined(__QNX__)
#define USE_UNIX_BACKTRACE_SUPPORT
#endif
Expand Down
18 changes: 17 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,13 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
}
hasValidConfig = true;

// locations macros
mLocationMacros.clear();
for (const Token* tok = tokenizer.tokens(); tok; tok = tok->next()) {
if (!tok->getMacroName().empty())
mLocationMacros[Location(files[tok->fileIndex()], tok->linenr())].emplace(tok->getMacroName());
}

// If only errors are printed, print filename after the check
if (!mSettings.quiet && (!mCurrentConfig.empty() || checkCount > 1)) {
std::string fixedpath = Path::simplifyPath(filename);
Expand Down Expand Up @@ -1556,8 +1563,17 @@ void CppCheck::reportErr(const ErrorMessage &msg)
if (!mSettings.buildDir.empty())
mAnalyzerInformation.reportErr(msg);

std::set<std::string> macroNames;
if (!msg.callStack.empty()) {
const std::string &file = msg.callStack.back().getfile(false);
int lineNumber = msg.callStack.back().line;
const auto it = mLocationMacros.find(Location(file, lineNumber));
if (it != mLocationMacros.cend())
macroNames = it->second;
}

// TODO: only convert if necessary
const auto errorMessage = Suppressions::ErrorMessage::fromErrorMessage(msg);
const auto errorMessage = Suppressions::ErrorMessage::fromErrorMessage(msg, macroNames);

if (mSettings.nomsg.isSuppressed(errorMessage, mUseGlobalSuppressions)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <functional>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -223,6 +224,9 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
/** @brief Current preprocessor configuration */
std::string mCurrentConfig;

using Location = std::pair<std::string, int>;
std::map<Location, std::set<std::string>> mLocationMacros; // What macros are used on a location?

unsigned int mExitCode{};

bool mUseGlobalSuppressions;
Expand Down
12 changes: 6 additions & 6 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ std::string ErrorMessage::serialize() const

for (std::list<ErrorMessage::FileLocation>::const_iterator loc = callStack.cbegin(); loc != callStack.cend(); ++loc) {
std::string frame;
frame += std::to_string((*loc).line);
frame += std::to_string(loc->line);
frame += '\t';
frame += std::to_string((*loc).column);
frame += std::to_string(loc->column);
frame += '\t';
frame += (*loc).getfile(false);
frame += loc->getfile(false);
frame += '\t';
frame += loc->getOrigFile(false);
frame += '\t';
Expand Down Expand Up @@ -498,9 +498,9 @@ std::string ErrorMessage::toXML() const

for (std::list<FileLocation>::const_reverse_iterator it = callStack.crbegin(); it != callStack.crend(); ++it) {
printer.OpenElement("location", false);
printer.PushAttribute("file", (*it).getfile().c_str());
printer.PushAttribute("line", std::max((*it).line,0));
printer.PushAttribute("column", (*it).column);
printer.PushAttribute("file", it->getfile().c_str());
printer.PushAttribute("line", std::max(it->line,0));
printer.PushAttribute("column", it->column);
if (!it->getinfo().empty())
printer.PushAttribute("info", fixInvalidChars(it->getinfo()).c_str());
printer.CloseElement(false);
Expand Down
2 changes: 0 additions & 2 deletions lib/keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include "utils.h"

#include <cassert>

// see https://en.cppreference.com/w/c/keyword

#define C90_KEYWORDS \
Expand Down
2 changes: 1 addition & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "library.h"

#include "astutils.h"
#include "errortypes.h"
#include "mathlib.h"
#include "path.h"
#include "symboldatabase.h"
Expand All @@ -31,7 +32,6 @@
#include <algorithm>
#include <cctype>
#include <climits>
#include <cstddef>
#include <cstring>
#include <list>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "config.h"
#include "mathlib.h"
#include "errortypes.h"
#include "standards.h"

#include <map>
Expand All @@ -37,6 +36,7 @@

class Token;
class Settings;
enum class Severity;

namespace tinyxml2 {
class XMLDocument;
Expand Down
1 change: 0 additions & 1 deletion lib/pathanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <algorithm>
#include <string>
#include <tuple>
#include <type_traits>

const Scope* PathAnalysis::findOuterScope(const Scope * scope)
{
Expand Down
Loading