From e2ac013cbb12350bd21fefdbe5a6aa251e171fe8 Mon Sep 17 00:00:00 2001 From: harry Date: Sat, 24 Feb 2024 08:46:06 -0500 Subject: [PATCH] Run cppcheck static analyzer against code base. Fixed a few warnings. --- scripts/runCppCheck.sh | 16 ++++++++++++++++ src/CMakeLists.txt | 8 -------- src/drivers/Qt/NetPlay.cpp | 2 +- src/filter.cpp | 8 ++++---- src/input/shadow.cpp | 9 +-------- src/input/zapper.h | 2 +- src/palettes/{conv.c => conv.cpp} | 3 ++- src/types.h | 14 +++++++++++--- 8 files changed, 36 insertions(+), 26 deletions(-) create mode 100755 scripts/runCppCheck.sh rename src/palettes/{conv.c => conv.cpp} (96%) diff --git a/scripts/runCppCheck.sh b/scripts/runCppCheck.sh new file mode 100755 index 00000000..60ec935f --- /dev/null +++ b/scripts/runCppCheck.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +PROJECT_ROOT=$( cd "$(dirname ${BASH_SOURCE[0]})"/.. && pwd ) +echo $PROJECT_ROOT; + +SRC_DIR=$PROJECT_ROOT/src + +cd $SRC_DIR; + +cppcheck --version + +IGNORE_DIRS=" -i ./attic " +IGNORE_DIRS+="-i ./drivers/sdl " +#IGNORE_DIRS+="-i ./drivers/win " + +cppcheck --force $IGNORE_DIRS . diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bca9391c..c1f1dbc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -364,14 +364,6 @@ endif() include_directories( ${CMAKE_SOURCE_DIR}/src ) include_directories( ${CMAKE_SOURCE_DIR}/src/drivers ) -if(APPLE) - add_definitions( -DPSS_STYLE=1 ) -else(APPLE) - if(UNIX) - add_definitions( -DPSS_STYLE=1 ) - endif(UNIX) -endif(APPLE) - set(SRC_CORE ${CMAKE_CURRENT_SOURCE_DIR}/asm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cart.cpp diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index b06fee32..158c37ae 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -168,12 +168,12 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client ) filepath = GameInfo->filename; } } - printf("Prep ROM Load Request: %s \n", filepath ); if (filepath == nullptr) { return -1; } + printf("Prep ROM Load Request: %s \n", filepath ); FILE *fp = ::fopen( filepath, "r"); if (fp == nullptr) diff --git a/src/filter.cpp b/src/filter.cpp index 650f8c43..d0e7a625 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -167,10 +167,10 @@ int32 NeoFilterSound(int32 *in, int32 *out, uint32 inlen, int32 *leftover) void MakeFilters(int32 rate) { - const int32 *tabs[6]={C44100NTSC,C44100PAL,C48000NTSC,C48000PAL,C96000NTSC, - C96000PAL}; - const int32 *sq2tabs[6]={SQ2C44100NTSC,SQ2C44100PAL,SQ2C48000NTSC,SQ2C48000PAL, - SQ2C96000NTSC,SQ2C96000PAL}; + const int32 *tabs[8]={C44100NTSC,C44100PAL,C48000NTSC,C48000PAL,C96000NTSC, + C96000PAL, nullptr, nullptr}; + const int32 *sq2tabs[8]={SQ2C44100NTSC,SQ2C44100PAL,SQ2C48000NTSC,SQ2C48000PAL, + SQ2C96000NTSC,SQ2C96000PAL, nullptr, nullptr}; const int32 *tmp; int32 x; diff --git a/src/input/shadow.cpp b/src/input/shadow.cpp index 85fa44e7..b5628e22 100644 --- a/src/input/shadow.cpp +++ b/src/input/shadow.cpp @@ -22,14 +22,7 @@ #include #include "share.h" - -typedef struct { - uint32 mzx,mzy,mzb; - int zap_readbit; - int bogo; - int zappo; - uint64 zaphit; -} ZAPPER; +#include "zapper.h" static ZAPPER ZD; diff --git a/src/input/zapper.h b/src/input/zapper.h index a106294f..b2faaf7d 100644 --- a/src/input/zapper.h +++ b/src/input/zapper.h @@ -10,7 +10,7 @@ struct ZAPPER uint8 bogo; int zappo; uint64 zaphit; - uint32 lastInput; + uint32 lastInput; }; #endif diff --git a/src/palettes/conv.c b/src/palettes/conv.cpp similarity index 96% rename from src/palettes/conv.c rename to src/palettes/conv.cpp index 13e4d8f0..05db839a 100644 --- a/src/palettes/conv.c +++ b/src/palettes/conv.cpp @@ -60,7 +60,7 @@ static uint8 rp2c05004_colortable[] = }; -main() +int main(int argc, char *argv[]) { int x; for(x=0;x<64;x++) @@ -71,4 +71,5 @@ main() palette[rp2c04001_colortable[x]&0x3F].g, palette[rp2c04001_colortable[x]&0x3F].b); } + return 0; } diff --git a/src/types.h b/src/types.h index 3c8f751e..df530bc7 100644 --- a/src/types.h +++ b/src/types.h @@ -96,9 +96,6 @@ typedef uint32_t uint32; #define GINLINE /* Can't declare a function INLINE and global in MSVC. Bummer. */ - #define PSS_STYLE 2 /* Does MSVC compile for anything - other than Windows/DOS targets? - */ #if _MSC_VER >= 1300 #pragma warning(disable:4244) //warning C4244: '=' : conversion from 'uint32' to 'uint8', possible loss of data @@ -110,6 +107,17 @@ typedef uint32_t uint32; #endif #endif +#if defined(__linux__) || defined(__APPLE__) || defined(__unix__) + + #define PSS_STYLE 1 + +#elif defined(MSVC) + + #define PSS_STYLE 2 /* Does MSVC compile for anything + other than Windows/DOS targets? + */ +#endif + #if PSS_STYLE==2 #define PSS "\\"