use compile_commands.json for Cppcheck (#1716)

* suppress memleak warnings only for u_scanner.c
This commit is contained in:
Roman Fomin 2024-05-29 18:07:46 +07:00 committed by GitHub
parent 605289f161
commit 1f957567a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 16 deletions

View File

@ -132,16 +132,41 @@ jobs:
cppcheck:
name: Cppcheck
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install cppcheck
run: |
sudo apt-get update
sudo apt-get install \
cppcheck \
ninja-build \
libsdl2-dev \
libsdl2-net-dev \
libopenal-dev \
libsndfile1-dev \
libfluidsynth-dev \
libxmp-dev
- uses: actions/checkout@v4
- name: Run cppcheck
shell: bash
- name: Configure
run: |
cppcheck --version
cppcheck --error-exitcode=1 -j4 -q --force -D__GNUC__ -U_MSC_VER -U_WIN32 -Isrc opl src setup textscreen
cmake -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=OFF
- name: Run Cppcheck
run: |
mkdir cppcheck_cache
cppcheck -j4 --cppcheck-build-dir="cppcheck_cache" \
--quiet \
--error-exitcode=1 \
--check-level=exhaustive \
--inconclusive \
--inline-suppr \
--std=c99 \
--suppress="memleak:${{ github.workspace }}/src/u_scanner.c" \
--project="${{ github.workspace }}/build/compile_commands.json" \
-i"${{ github.workspace }}/miniz" \
-i"${{ github.workspace }}/spng" \
-D__GNUC__

View File

@ -185,7 +185,7 @@ static Bit16s OPL3_EnvelopeCalcExp(Bit32u level)
{
level = 0x1fff;
}
return (exprom[level & 0xff] << 1) >> (level >> 8);
return ((unsigned)(exprom[level & 0xff] << 1)) >> (level >> 8);
}
static Bit16s OPL3_EnvelopeCalcSin0(Bit16u phase, Bit16u envelope)

View File

@ -591,7 +591,8 @@ void M_LoadOptions(void)
if (!M_CheckParm("-nooptions"))
{
if ((lump = W_CheckNumForName("OPTIONS")) != -1)
lump = W_CheckNumForName("OPTIONS");
if (lump != -1)
{
int size = W_LumpLength(lump), buflen = 0;
char *buf = NULL, *p,
@ -605,7 +606,8 @@ void M_LoadOptions(void)
{
buf = I_Realloc(buf, buflen = len + 1);
}
strncpy(buf, p, len)[len] = 0;
strncpy(buf, p, len);
buf[len] = 0;
p += len;
size -= len;
M_ParseOption(buf, true);

View File

@ -520,7 +520,7 @@ static void R_DrawFuzzColumn_orig(void)
dest += linesize; // killough 11/98
// Clamp table lookup index.
fuzzpos &= (fuzzpos - FUZZTABLE) >> (8*sizeof fuzzpos-1); //killough 1/99
fuzzpos &= ((unsigned)(fuzzpos - FUZZTABLE)) >> (8*sizeof fuzzpos-1); //killough 1/99
}
while (--count);
@ -590,7 +590,7 @@ static void R_DrawFuzzColumn_block(void)
}
fuzzpos++;
fuzzpos &= (fuzzpos - FUZZTABLE) >> (8 * sizeof(fuzzpos) - 1);
fuzzpos &= ((unsigned)(fuzzpos - FUZZTABLE)) >> (8 * sizeof(fuzzpos) - 1);
}
while ((count -= ny) > 0);

View File

@ -18,7 +18,6 @@
//
//-----------------------------------------------------------------------------
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

View File

@ -74,6 +74,7 @@ static char *ExecReadOutput(char **argv)
// Wait until the program has completed and (if it was successful)
// a full line has been read.
status = 0;
result = NULL;
result_len = 0;
completed = 0;

View File

@ -29,10 +29,6 @@
// * Peters <colin@fu.is.saga-u.ac.jp>
//
#ifndef _MSC_VER
#error i_opndir.c is for Microsoft Visual C++ only
#endif
#include <stdlib.h>
#include <errno.h>
#include <string.h>