Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 3, 2023
2 parents 60666f1 + faf8047 commit 3f73305
Show file tree
Hide file tree
Showing 117 changed files with 2,227 additions and 586 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ jobs:
sudo apt-get update
sudo apt-get install libxml2-utils qtbase5-dev qttools5-dev libqt5charts5-dev qtchooser
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
if: matrix.os == 'ubuntu-22.04'
with:
version: 13
platform: x64

- name: Select compiler
run: |
echo "CXX=g++-13" >> $GITHUB_ENV
if: matrix.os == 'ubuntu-22.04'

# coreutils contains "nproc"
- name: Install missing software on macos
if: contains(matrix.os, 'macos')
Expand Down Expand Up @@ -380,6 +392,7 @@ jobs:
run: |
./cppcheck --error-exitcode=1 --inline-suppr --addon=threadsafety addons/test/threadsafety
./cppcheck --error-exitcode=1 --inline-suppr --addon=threadsafety --std=c++03 addons/test/threadsafety
./cppcheck --error-exitcode=1 --inline-suppr --addon=misra addons/test/misra/crash*.c
./cppcheck --addon=misra --enable=style --inline-suppr --enable=information --error-exitcode=1 addons/test/misra/misra-ctu-*-test.c
pushd addons/test
# We'll force C89 standard to enable an additional verification for
Expand All @@ -403,11 +416,6 @@ jobs:
../../cppcheck --dump namingng_test.c
python3 ../namingng.py --configfile ../naming.json --verify namingng_test.c.dump
- name: Ensure misra addon does not crash
if: contains(matrix.os, 'ubuntu')
run: |
./cppcheck --addon=misra addons/test/misra/crash1.c | ( ! grep 'Bailing out from checking' )
- name: Build democlient
if: matrix.os == 'ubuntu-22.04'
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Install clang
run: |
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Install clang
run: |
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-22.04

container:
image: "archlinux:latest"
image: "fedora:latest"

steps:
- uses: actions/checkout@v3
Expand All @@ -34,15 +34,23 @@ jobs:
pacman -Sy
pacman -S cmake make gcc qt5-base qt5-tools qt5-charts pcre wget --noconfirm
pacman-key --init
pacman-key --recv-key FBA220DFC880C036 --keyserver keyserver.ubuntu.com
pacman-key --lsign-key FBA220DFC880C036
pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
pacman-key --lsign-key 3056513887B78AEB
pacman -U 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst' 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst' --noconfirm
echo "[chaotic-aur]" >> /etc/pacman.conf
echo "Include = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf
pacman -Sy
pacman -S include-what-you-use --noconfirm
ln -s iwyu-tool /usr/sbin/iwyu_tool
# TODO: the necessary packages are excessive - mostly because of Qt - use a pre-built image
- name: Install missing software on Fedora
run: |
dnf install -y cmake gcc-c++ qt5-qtbase-devel qt5-linguist qt5-qttools-devel qt5-qtcharts-devel pcre-devel
dnf install -y wget iwyu
ln -s iwyu_tool.py /usr/bin/iwyu_tool
ln -s qt5 /usr/include/qt
- name: Prepare CMake
run: |
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=On -DWITH_QCHART=On -DENABLE_CHECK_INTERNAL=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCPPCHK_GLIBCXX_DEBUG=Off -DUSE_MATCHCOMPILER=Off
Expand Down Expand Up @@ -107,6 +115,7 @@ jobs:
- name: Install clang
run: |
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ jobs:

needs: build
# 'ubuntu-22.04' removes Python 2.7, 3.5 and 3.6 so keep the previous LTS version
# 'ubutunu-20.04' no longer works on 2.7 - TODO: re-added in a different way or remove support for it?
runs-on: ubuntu-20.04
container:
image: python:2.7.18-buster
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', '3.11']
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, '3.10', '3.11']
fail-fast: false

steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Install clang
run: |
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Install clang
run: |
sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Ryan Pavlik
Samir Aguiar
Sam Truscott
Samuel Degrande
Samuel Poláček
Sandeep Dutta
Savvas Etairidis
Scott Furry
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h
cli/threadexecutor.o: cli/threadexecutor.cpp cli/cppcheckexecutor.h cli/executor.h cli/threadexecutor.h lib/analyzerinfo.h lib/check.h lib/color.h lib/config.h lib/cppcheck.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/utils.h
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp

test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.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/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.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/suppressions.h lib/utils.h test/fixture.h test/options.h test/redirect.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp

test/helpers.o: test/helpers.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.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/helpers.h
Expand Down Expand Up @@ -862,7 +862,7 @@ test/testunusedprivfunc.o: test/testunusedprivfunc.cpp externals/simplecpp/simpl
test/testunusedvar.o: test/testunusedvar.cpp externals/simplecpp/simplecpp.h lib/check.h lib/checkunusedvar.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/preprocessor.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/testunusedvar.cpp

test/testutils.o: test/testutils.cpp 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/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/testutils.o: test/testutils.cpp 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/suppressions.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testutils.cpp

test/testvaarg.o: test/testvaarg.cpp lib/check.h lib/checkvaarg.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
Expand Down
62 changes: 59 additions & 3 deletions addons/misra_9.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import cppcheckdata

# Holds information about an array, struct or union's element definition.
class ElementDef:
def __init__(self, elementType, name, valueType, dimensions = None):
Expand Down Expand Up @@ -30,7 +32,7 @@ def __repr__(self):

attrs = ["childIndex", "elementType", "valueType"]
return "{}({}, {}, {})".format(
"ED",
"ElementDef",
self.getLongName(),
inits,
", ".join(("{}={}".format(a, repr(getattr(self, a))) for a in attrs))
Expand Down Expand Up @@ -253,6 +255,16 @@ def parseInitializer(self, root, token):
isFirstElement = False
isDesignated = True

elif self.token.isString and self.ed and self.ed.isArray:
self.ed.setInitialized(isDesignated)
if self.token == self.token.astParent.astOperand1 and self.token.astParent.astOperand2:
self.token = self.token.astParent.astOperand2
self.ed.markAsCurrent()
self.ed = self.root.getNextChild()
else:
self.unwindAndContinue()
continue

elif self.token.str == '{':
nextChild = self.root.getNextChild() if self.root is not None else None

Expand Down Expand Up @@ -314,6 +326,7 @@ def parseInitializer(self, root, token):
else:
self.ed.parent.setInitialized(isDesignated)
self.ed.parent.initializeChildren()

else:
if self.ed.parent != self.root:
# Check if token is correct value type for self.root.children[?]
Expand All @@ -333,6 +346,8 @@ def parseInitializer(self, root, token):
parent = parent.parent
isDesignated = False

if self.token.isString and self.ed.parent.isArray:
self.ed = self.ed.parent
self.unwindAndContinue()

def pushToRootStackAndMarkAsDesignated(self):
Expand Down Expand Up @@ -381,6 +396,39 @@ def unwindAndContinue(self):
break

def misra_9_x(self, data, rule, rawTokens = None):
# If there are arrays with unknown size constants then we need to warn about missing configuration
# and bailout
has_config_errors = False
for var in data.variables:
if not var.isArray or var.nameToken is None or not cppcheckdata.simpleMatch(var.nameToken.next,'['):
continue
tok = var.nameToken.next
while tok.str == '[':
sz = tok.astOperand2
if sz and sz.getKnownIntValue() is None:
has_var = False
unknown_constant = False
tokens = [sz]
while len(tokens) > 0:
t = tokens[-1]
tokens = tokens[:-1]
if t:
if t.isName and t.getKnownIntValue() is None:
if t.varId or t.variable:
has_var = True
continue
unknown_constant = True
cppcheckdata.reportError(sz, 'error', 'Unknown constant {}, please review configuration'.format(t.str), 'misra', 'config')
has_config_errors = True
if t.isArithmeticalOp:
tokens += [t.astOperand1, t.astOperand2]
if not unknown_constant and not has_var:
cppcheckdata.reportError(sz, 'error', 'Unknown array size, please review configuration', 'misra', 'config')
has_config_errors = True
tok = tok.link.next
if has_config_errors:
return

parser = InitializerParser()

for variable in data.variables:
Expand Down Expand Up @@ -441,7 +489,7 @@ def getElementDef(nameToken, rawTokens = None):
return ed

def createArrayChildrenDefs(ed, token, var, rawTokens = None):
if token.str == '[':
if token and token.str == '[':
if rawTokens is not None:
foundToken = next((rawToken for rawToken in rawTokens
if rawToken.file == token.file
Expand Down Expand Up @@ -476,7 +524,15 @@ def createRecordChildrenDefs(ed, var):
valueType = ed.valueType
if not valueType or not valueType.typeScope:
return

if var is None:
return
typeToken = var.typeEndToken
while typeToken and typeToken.isName:
typeToken = typeToken.previous
if typeToken and typeToken.str == '*':
child = ElementDef("pointer", var.nameToken, var.nameToken.valueType)
ed.addChild(child)
return
for variable in valueType.typeScope.varlist:
if variable is var:
continue
Expand Down
9 changes: 9 additions & 0 deletions addons/test/misra/crash2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

// #11793

typedef struct pfmlib_pmu {
int flags ;
int (*get_event_encoding[10])(void* this, pfmlib_event_desc_t* e);
} pfmlib_pmu_t ;

pfmlib_pmu_t sparc_ultra3_support = { .flags = 0 };
30 changes: 30 additions & 0 deletions addons/test/misra/crash3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@




/* This is the representation of the expressions to determine the
plural form. */
struct expression
{
int nargs; /* Number of arguments. */
union
{
unsigned long int num; /* Number value for `num'. */
struct expression *args[3]; /* Up to three arguments. */
} val;
};


struct expression GERMANIC_PLURAL =
{
.nargs = 2,
.val =
{
.args =
{
[0] = (struct expression *) &plvar,
[1] = (struct expression *) &plone
}
}
};

11 changes: 11 additions & 0 deletions addons/test/misra/crash4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

struct ConDesDesc {
unsigned Order;
unsigned Import;
};

// cppcheck-suppress misra-config
static ConDesDesc ConDes[CD_TYPE_COUNT] = {
{ 0, 0 },
{ 0, 0 },
};
23 changes: 23 additions & 0 deletions addons/test/misra/crash5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

struct _boardcnf_ch {
// cppcheck-suppress misra-config
uint8_t ddr_density[CS_CNT];
uint64_t ca_swap;
};

struct _boardcnf {

uint16_t dqdm_dly_r;
// cppcheck-suppress misra-config
struct _boardcnf_ch ch[DRAM_CH_CNT];
};

static const struct _boardcnf boardcnfs[1] = {
{
0x0a0,
{
{ {0x02, 0x02}, 0x00345201 },
{ {0x02, 0x02}, 0x00302154 }
}
},
};
17 changes: 17 additions & 0 deletions addons/test/misra/crash6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


typedef struct _tGames
{
char magicdirname[10];
unsigned int expectedmask;
unsigned char pictureorder[3];
} tGames;

static const tGames games[1]={
{"Pawn", 1, {0,1,2}}
};





8 changes: 8 additions & 0 deletions addons/test/misra/crash7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


static const struct id3_frametype wordlist[] =
{
{0, "Encryption method registration"},
{1, "Popularimeter"},
};

10 changes: 10 additions & 0 deletions addons/test/misra/crash8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

struct three_d_filter_t {
char name[16];
double elem[2];
};

static three_d_filter_t base_filters[] = {
{"Identity", { 1.0, 0.0 } },
{"Echo", { 0.4, 0.0 } }
};
3 changes: 3 additions & 0 deletions addons/test/misra/crash9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#line 3 "<stdout>"
typedef int8_t flex_int8_t;
4 changes: 0 additions & 4 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,6 @@ static void misra_9_struct_initializers(void) {
struct1 os1 = { i1: 1, i2: 2 }; // 10.4 13.4
}

static void misra_9_broken_initializers(void) {
char a[UNKNOWN_MACRO] = { 19, 23, 0 }; // 18.8
}

static void misra_9_2(void) {
union misra_9_2_union { // 19.2
char c;
Expand Down
Loading

0 comments on commit 3f73305

Please sign in to comment.