From 1f957567a657cc66b0a43490554eb2d7cbc5e124 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Wed, 29 May 2024 18:07:46 +0700 Subject: [PATCH] use `compile_commands.json` for Cppcheck (#1716) * suppress memleak warnings only for u_scanner.c --- .github/workflows/main.yml | 37 +++++++++++++++++++++++++++++++------ opl/opl3.c | 2 +- src/m_config.c | 6 ++++-- src/r_draw.c | 4 ++-- src/u_mapinfo.c | 1 - textscreen/txt_fileselect.c | 1 + win32/win_opendir.c | 4 ---- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0554cc04..f15fa7b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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__ diff --git a/opl/opl3.c b/opl/opl3.c index 247f44f6..927bda30 100644 --- a/opl/opl3.c +++ b/opl/opl3.c @@ -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) diff --git a/src/m_config.c b/src/m_config.c index 0079346b..518ea391 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -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); diff --git a/src/r_draw.c b/src/r_draw.c index 85f5efee..283b8336 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -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); diff --git a/src/u_mapinfo.c b/src/u_mapinfo.c index 1089caeb..4729785f 100644 --- a/src/u_mapinfo.c +++ b/src/u_mapinfo.c @@ -18,7 +18,6 @@ // //----------------------------------------------------------------------------- -#include #include #include diff --git a/textscreen/txt_fileselect.c b/textscreen/txt_fileselect.c index ec1ff44c..858c2c17 100644 --- a/textscreen/txt_fileselect.c +++ b/textscreen/txt_fileselect.c @@ -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; diff --git a/win32/win_opendir.c b/win32/win_opendir.c index b2f67805..f6cab233 100644 --- a/win32/win_opendir.c +++ b/win32/win_opendir.c @@ -29,10 +29,6 @@ // * Peters // -#ifndef _MSC_VER -#error i_opndir.c is for Microsoft Visual C++ only -#endif - #include #include #include