From 3252710eb77b3115f73ffb4f2f8f9450a5d18ac0 Mon Sep 17 00:00:00 2001 From: bladeoner Date: Thu, 25 Jun 2020 06:01:32 +0200 Subject: [PATCH] Snes9x - Fix some warnings. / Remove out-of-bounds access with macs rifle data. (#925) * Snes9x - Fix some warnings. * Snes9x - Remove out-of-bounds access with macs rifle data. --- source/snes9x/controls.cpp | 14 ++++++++++++-- source/snes9x/memmap.cpp | 2 +- source/snes9x/movie.cpp | 2 +- source/snes9x/port.h | 6 ------ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/source/snes9x/controls.cpp b/source/snes9x/controls.cpp index 58364ea..f791815 100644 --- a/source/snes9x/controls.cpp +++ b/source/snes9x/controls.cpp @@ -3515,11 +3515,17 @@ void S9xControlPreSaveState (struct SControlSnapshot *s) for (int k = 0; k < 2; k++) COPY(mp5[j].pads[k]); + assert(i == sizeof(s->internal)); + + #undef COPY + #define COPY(x) { memcpy((char *) s->internal_macs + i, &(x), sizeof(x)); i += sizeof(x); } + i = 0; + COPY(macsrifle.x); COPY(macsrifle.y); COPY(macsrifle.buttons); - assert(i == sizeof(s->internal) + sizeof(s->internal_macs)); + assert(i == sizeof(s->internal_macs)); #undef COPY @@ -3594,11 +3600,15 @@ void S9xControlPostLoadState (struct SControlSnapshot *s) if (s->ver > 3) { + #undef COPY + #define COPY(x) { memcpy(&(x), (char *) s->internal_macs + i, sizeof(x)); i += sizeof(x); } + i = 0; + COPY(macsrifle.x); COPY(macsrifle.y); COPY(macsrifle.buttons); - assert(i == sizeof(s->internal) + sizeof(s->internal_macs)); + assert(i == sizeof(s->internal_macs)); } #undef COPY diff --git a/source/snes9x/memmap.cpp b/source/snes9x/memmap.cpp index f7c5841..96167bd 100644 --- a/source/snes9x/memmap.cpp +++ b/source/snes9x/memmap.cpp @@ -2562,7 +2562,7 @@ void CMemory::InitROM (void) if (Settings.ForcePAL) Settings.PAL = TRUE; else - if (!Settings.BS && ((ROMRegion >= 2) && (ROMRegion <= 12) || ROMRegion == 18)) // 18 is used by "Tintin in Tibet (Europe) (En,Es,Sv)" + if (!Settings.BS && (((ROMRegion >= 2) && (ROMRegion <= 12)) || ROMRegion == 18)) // 18 is used by "Tintin in Tibet (Europe) (En,Es,Sv)" Settings.PAL = TRUE; else Settings.PAL = FALSE; diff --git a/source/snes9x/movie.cpp b/source/snes9x/movie.cpp index dcb1bf6..32829bb 100644 --- a/source/snes9x/movie.cpp +++ b/source/snes9x/movie.cpp @@ -460,7 +460,7 @@ static int read_movie_extrarominfo (FILE *fd, SMovie *movie) ptr += 3; // zero bytes movie->ROMCRC32 = Read32(ptr); - sstrncpy(movie->ROMName, (char *) ptr, 23); + memcpy(movie->ROMName, (char *) ptr, 23); return (SUCCESS); } diff --git a/source/snes9x/port.h b/source/snes9x/port.h index 95704b8..dd701f3 100644 --- a/source/snes9x/port.h +++ b/source/snes9x/port.h @@ -151,12 +151,6 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char); #endif // __LIBRETRO__ #endif // __WIN32__ -inline void sstrncpy(char *dst, const char *src, size_t size) -{ - strncpy(dst, src, size - 1); - dst[size - 1] = '\0'; -} - #if defined(__DJGPP) || defined(__WIN32__) #define SLASH_STR "\\" #define SLASH_CHAR '\\'