From fd5596085491cbd450d27503df78d3f8549c3707 Mon Sep 17 00:00:00 2001 From: Nyq <623434+nyq@users.noreply.github.com> Date: Tue, 15 Aug 2023 05:39:55 -0400 Subject: [PATCH 1/2] Update miniz_zip.c to prevent compilation warning when compiling for Windows in straight C mode Summary: Added conditional macro definition to prevent MSVC compiler warning C5105 when compiling for Windows in straight C mode Details: Since version 3.0.0 miniz_zip.c includes windows.h header file when compiling for Windows using MSVC. However, when compiling miniz_zip.c using MSVC17 in straight-C mode (no C++), this inclusion causes warning C5105: winbase.h(9531,5): warning C5105: macro expansion producing 'defined' has undefined behavior This warning is not produced when compiling in C++ mode. In order to prevent the warning, any straight-C code that wants to include windows.h should make an additional define before including: #ifndef __cplusplus #define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 #endif #include --- miniz_zip.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/miniz_zip.c b/miniz_zip.c index 3ed6a67..5fe8ddf 100644 --- a/miniz_zip.c +++ b/miniz_zip.c @@ -42,6 +42,9 @@ extern "C" { #if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__) #define WIN32_LEAN_AND_MEAN +#ifndef __cplusplus +#define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 +#endif #include static WCHAR* mz_utf8z_to_widechar(const char* str) From 90a5b2f89b27945bcc2d12159bfa72f9fe522b5a Mon Sep 17 00:00:00 2001 From: Nyq <623434+nyq@users.noreply.github.com> Date: Tue, 15 Aug 2023 07:21:03 -0400 Subject: [PATCH 2/2] Prevent min/max conflicts between windows.h and std namespace Miniz started including windows.h from version 3.0.0 and on when compiling for Windows using MSVC. windows.h header file is known to conflict with C++ std namespace by defining its own min/max macros. It is a common practice to disable these ancient macros in windows.h by declaring NOMINMAX macro prior to including windows.h in code. While this issue does not affect miniz directly due to the fact that it is straight-C code and it does not use min/max from C++ std namespace, it does affect other projects like miniz-cpp which wrap and amalgamate miniz and then both compile in C++ mode and use min/max from std namespace. It is therefore proposed to prefix inclusion of windows.h in miniz_zip.c by the following lines: #ifndef NOMINMAX #define NOMINMAX #endif --- miniz_zip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/miniz_zip.c b/miniz_zip.c index 5fe8ddf..c58b39e 100644 --- a/miniz_zip.c +++ b/miniz_zip.c @@ -43,7 +43,10 @@ extern "C" { #define WIN32_LEAN_AND_MEAN #ifndef __cplusplus -#define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 + #define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0 +#endif +#ifndef NOMINMAX + #define NOMINMAX #endif #include