From 148b11bd33c91c00177d41080ba9c91a700270ae Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 15 Feb 2017 17:33:03 +0100 Subject: [PATCH 1/4] Add countof macro for arrays --- src/blupi.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/blupi.h b/src/blupi.h index 8aa0c52..1be8b96 100644 --- a/src/blupi.h +++ b/src/blupi.h @@ -34,6 +34,12 @@ typedef Sint32 LPARAM; #define LOWORD(l) ((Uint16) (((Uint32) (l)) & 0xffff)) #define HIWORD(l) ((Uint16) ((((Uint32) (l)) >> 16) & 0xffff)) +#ifdef _WIN32 +#define countof(a) _countof (a) +#else /* _WIN32 */ +#define countof(a) (sizeof (a) / sizeof (*a)) +#endif /* !_WIN32 */ + #define MAX_PATH 260 #define VK_END 0x23 From cc106b4d1c496797c384b0ded78de2848da704b5 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 15 Feb 2017 17:33:22 +0100 Subject: [PATCH 2/4] Fix potential leak with file handle --- src/event.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/event.cpp b/src/event.cpp index 45e56bd..32325d8 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -4319,6 +4319,7 @@ bool CEvent::DemoPlayStart() nb = fread (&header, sizeof (DemoHeader), 1, file); if (nb < 1) { + fclose (file); DemoPlayStop(); return false; } From abadbda3d888054442bf68ee92b4b354260cbaa6 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 15 Feb 2017 17:34:03 +0100 Subject: [PATCH 3/4] Fix freeing of cursors list It uses only 14 elements, not 100 like MAXIMAGE. --- src/pixmap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pixmap.cpp b/src/pixmap.cpp index abcf9d3..506f8c7 100644 --- a/src/pixmap.cpp +++ b/src/pixmap.cpp @@ -51,9 +51,9 @@ CPixmap::CPixmap() CPixmap::~CPixmap() { - Sint32 i; + unsigned int i; - for (i = 0; i < MAXIMAGE; i++) + for (i = 0; i < countof (m_lpSDLCursors); i++) { if (m_lpSDLCursors[i]) { From 97850c8def40a9acf3d07d5d2574ee3e29e11368 Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Wed, 15 Feb 2017 17:34:48 +0100 Subject: [PATCH 4/4] Use countof with textures too --- src/pixmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pixmap.cpp b/src/pixmap.cpp index 506f8c7..d4a37fe 100644 --- a/src/pixmap.cpp +++ b/src/pixmap.cpp @@ -62,7 +62,7 @@ CPixmap::~CPixmap() } } - for (i = 0 ; i < MAXIMAGE ; i++) + for (i = 0 ; i < countof (m_lpSDLTexture) ; i++) { if (m_lpSDLTexture[i] != nullptr) {