Skip to content

Commit

Permalink
Merge pull request #30 from visuve/master
Browse files Browse the repository at this point in the history
Try to prevent bugs by introducing Cppcheck
  • Loading branch information
hasherezade authored Apr 6, 2024
2 parents 8339763 + 929adce commit 9014b9e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 27 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Static analysis

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Cppcheck
run: |
sudo apt update
sudo apt --yes install cppcheck
- name: Static analysis
run: |
cppcheck --project=bearparser.cppcheck --error-exitcode=1 --enable=warning
19 changes: 3 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
# This is a basic workflow to help you get started with Actions
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions

name: Doxygen Action

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: push

permissions:
contents: write

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Doxygen Action
uses: mattnotmitt/doxygen-action@v1.1.0
with:
# Path to Doxyfile
doxyfile-path: "./Doxyfile" # default is ./Doxyfile
# Working directory
working-directory: "." # default is .

- name: Deploy
Expand Down
24 changes: 24 additions & 0 deletions bearparser.cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>build/cppcheck</builddir>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>true</check-unused-templates>
<max-ctu-depth>10</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<paths>
<dir name="commander"/>
<dir name="parser"/>
</paths>
<libraries>
<library>posix</library>
<library>qt</library>
<library>windows</library>
</libraries>
<suppressions>
<suppression>noExplicitConstructor</suppression>
<suppression>useStlAlgorithm</suppression>
<suppression>cstyleCast</suppression>
<suppression>constVariablePointer</suppression>
</suppressions>
</project>
2 changes: 1 addition & 1 deletion commander/Commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Commander;
class CmdException : public CustomException
{
public:
CmdException(const QString info) : CustomException(info) {}
CmdException(const QString& info) : CustomException(info) {}
};

class CmdParams
Expand Down
2 changes: 1 addition & 1 deletion commander/ExeCommander.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ExeCommander : public Commander
ExeCommander(ExeCmdContext *v_context)
: Commander(v_context), exeContext(v_context)
{
initCommands();
ExeCommander::initCommands();
}

void setExe(Executable *exe) { exeContext->setExe(exe); }
Expand Down
2 changes: 1 addition & 1 deletion commander/PECommander.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PECommander : public ExeCommander
PECommander(ExeCmdContext *v_context)
: ExeCommander(v_context)
{
initCommands();
PECommander::initCommands();
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion parser/ByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool ByteBuffer::resize(bufsize_t newSize)
BYTE *newContent = NULL;
try {
newContent = allocContent(newSize, this->padding);
} catch(BufferException &e) {
} catch(BufferException) {
newContent = NULL;
}
if (!newContent) return false;
Expand Down
4 changes: 2 additions & 2 deletions parser/Executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ offset_t Executable::toRaw(offset_t offset, addr_type aT, bool allowExceptions)
if (aT == Executable::RVA){
try {
convertedOffset = this->rvaToRaw(offset);
} catch (CustomException &e) {
if (allowExceptions) throw e;
} catch (CustomException) {
if (allowExceptions) throw;
}
}
//---
Expand Down
2 changes: 1 addition & 1 deletion parser/FileBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ByteBuffer* AbstractFileBuffer::read(QFile &fIn, bufsize_t minBufSize, const boo
try {
bufferedFile = new ByteBuffer(allocSize); //throws exceptions
}
catch (CustomException &e)
catch (CustomException)
{
if (!allowTruncate) throw;
allocSize /= 2;
Expand Down
3 changes: 2 additions & 1 deletion parser/pe/DOSExe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Executable* DOSExeBuilder::build(AbstractByteBuffer *buf)

try {
exe = new DOSExe(buf);
} catch (ExeException &e) {
} catch (ExeException) {
//
}

return exe;
}

Expand Down
2 changes: 1 addition & 1 deletion parser/pe/LdConfigDirWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bufsize_t LdConfigDirWrapper::getHdrDefinedSize()
offset_t raw = INVALID_ADDR;
try {
raw = m_Exe->rvaToRaw(rva);
} catch (CustomException &e) {
} catch (CustomException) {
raw = INVALID_ADDR;
}
if (raw == INVALID_ADDR) return 0;
Expand Down
4 changes: 2 additions & 2 deletions parser/pe/PEFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Executable* PEFileBuilder::build(AbstractByteBuffer *buf)

try {
exe = new PEFile(buf);
} catch (ExeException &e) {
} catch (ExeException) {
exe = NULL;
}
return exe;
Expand Down Expand Up @@ -518,7 +518,7 @@ SectionHdrWrapper* PEFile::addNewSection(QString name, bufsize_t r_size, bufsize
if (!_canAddNewSection()) {
return nullptr;
}
ExeNodeWrapper* sec = dynamic_cast<ExeNodeWrapper*>(getWrapper(PEFile::WR_SECTIONS));

if (!v_size) {
v_size = r_size;
}
Expand Down

0 comments on commit 9014b9e

Please sign in to comment.