From df3b285b87b7b2b8914763d5cc06f681f567b897 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Thu, 2 Oct 2025 20:11:11 +0800 Subject: [PATCH 1/3] Fix warnings when building for Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Jérôme Martinez --- Source/ZenLib/Utils.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/ZenLib/Utils.cpp b/Source/ZenLib/Utils.cpp index 7f6daf43..4074c708 100644 --- a/Source/ZenLib/Utils.cpp +++ b/Source/ZenLib/Utils.cpp @@ -19,6 +19,7 @@ #include "ZenLib/Utils.h" #include #include +#include //--------------------------------------------------------------------------- namespace ZenLib @@ -972,16 +973,16 @@ void int64u_int32u (int64u BigInt, int32u &High, int32u &Low) int32s float32_int32s (float32 F, bool Rounded) { //Out of boundaries - if (F>=(int32s)0x7FFFFFFF) - return (int32s)0x7FFFFFFF; - if (F<=(int32s)0x80000000) - return (int32s)0x80000000; + if (F>=(float32)std::numeric_limits::max()) + return std::numeric_limits::max(); + if (F<=(float32)std::numeric_limits::min()) + return std::numeric_limits::min(); //Not rounded if (!Rounded) return (int32s)F; //Rounded - int I1=(int)F; + int32s I1=(int32s)F; if (F-I1>=0.5f) return I1+1; else @@ -991,16 +992,16 @@ int32s float32_int32s (float32 F, bool Rounded) int64s float32_int64s (float32 F, bool Rounded) { //Out of boundaries - if (F>=(int64s)0x7FFFFFFFFFFFFFFFLL) - return (int64s)0x7FFFFFFFFFFFFFFFLL; - if (F<=(int64s)0x8000000000000000LL) - return (int64s)0x8000000000000000LL; + if (F>=(float32)std::numeric_limits::max()) + return std::numeric_limits::max(); + if (F<=(float32)std::numeric_limits::min()) + return std::numeric_limits::min(); //Not rounded if (!Rounded) return (int64s)F; //Rounded - int I1=(int)F; + int64s I1=(int64s)F; if (F-I1>=0.5f) return I1+1; else @@ -1010,10 +1011,10 @@ int64s float32_int64s (float32 F, bool Rounded) int32s float64_int32s (float64 F, bool Rounded) { //Out of boundaries - if (F>=(int32s)0x7FFFFFFF) - return (int32s)0x7FFFFFFF; - if (F<=(int32s)0x80000000) - return (int32s)0x80000000; + if (F>=(float64)std::numeric_limits::max()) + return std::numeric_limits::max(); + if (F<=(float64)std::numeric_limits::min()) + return std::numeric_limits::min(); //Not rounded if (!Rounded) @@ -1029,10 +1030,10 @@ int32s float64_int32s (float64 F, bool Rounded) int64s float64_int64s (float64 F, bool Rounded) { //Out of boundaries - if (F>=(int64s)0x7FFFFFFFFFFFFFFFLL) - return (int64s)0x7FFFFFFFFFFFFFFFLL; - if (F<=(int64s)0x8000000000000000LL) - return (int64s)0x8000000000000000LL; + if (F>=(float64)std::numeric_limits::max()) + return std::numeric_limits::max(); + if (F<=(float64)std::numeric_limits::min()) + return std::numeric_limits::min(); //Not rounded if (!Rounded) From c8413523c1e0595eb2b9a63a4c22c155152c8883 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Sun, 5 Oct 2025 14:43:45 +0800 Subject: [PATCH 2/3] Improve gmtime/localtime usage --- .github/workflows/ZenLib_Checks.yml | 1 + Source/ZenLib/Format/Http/Http_Cookies.cpp | 32 ++++++----- Source/ZenLib/Ztring.cpp | 62 ++++++++++++++-------- 3 files changed, 61 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ZenLib_Checks.yml b/.github/workflows/ZenLib_Checks.yml index ab69b90c..c3470fff 100644 --- a/.github/workflows/ZenLib_Checks.yml +++ b/.github/workflows/ZenLib_Checks.yml @@ -68,6 +68,7 @@ jobs: env: GENERATOR: "Unix Makefiles" CONFIGURATION: "Release" + CXXFLAGS: -Werror steps: - name: Checkout ZenLib uses: actions/checkout@v5 diff --git a/Source/ZenLib/Format/Http/Http_Cookies.cpp b/Source/ZenLib/Format/Http/Http_Cookies.cpp index 207f8eeb..4867cd19 100644 --- a/Source/ZenLib/Format/Http/Http_Cookies.cpp +++ b/Source/ZenLib/Format/Http/Http_Cookies.cpp @@ -86,20 +86,28 @@ void Cookies::Create_Lines(std::ostream& Out) if (Cookie->second.Expires!=(time_t)-1) { char Temp[200]; - #if defined(HAVE_GMTIME_R) - struct tm Gmt_Temp; - struct tm *Gmt=gmtime_r(&Cookie->second.Expires, &Gmt_Temp); - #elif defined(_MSC_VER) - struct tm Gmt_Temp; - errno_t gmtime_s_Result=gmtime_s(&Gmt_Temp , &Cookie->second.Expires); - struct tm* Gmt=gmtime_s_Result?NULL:&Gmt_Temp; + #if defined(_WIN32) + #if _CRT_USE_CONFORMING_ANNEX_K_TIME || (__STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) + // C11 standard version on MSVC or other compilers + tm Gmt_Temp; + tm* Gmt = gmtime_s(&Cookie->second.Expires, &Gmt_Temp); + #else + // MSVC and MinGW-w64 argument order and return value differs from C11 standard + tm Gmt_Temp; + errno_t gmtime_s_Result = gmtime_s(&Gmt_Temp, &Cookie->second.Expires); + tm* Gmt = gmtime_s_Result ? nullptr : &Gmt_Temp; + #endif + #elif defined(HAVE_GMTIME_R) + // POSIX or C23 + tm Gmt_Temp; + tm *Gmt = gmtime_r(&Cookie->second.Expires, &Gmt_Temp); #else - #ifdef __GNUC__ - #warning "This version of ZenLib is not thread safe" + // Fallback: not thread-safe, but prevents compile errors + #ifdef __GNUC__ + #warning "This version of ZenLib is not thread safe" + #endif + tm *Gmt = gmtime(&Cookie->second.Expires); #endif - struct tm *Gmt=gmtime(&Cookie->second.Expires); - #endif - if (Gmt) if (strftime(Temp, 200, "%a, %d-%b-%Y %H:%M:%S GMT", Gmt)) Out << "; expires=" << Temp; diff --git a/Source/ZenLib/Ztring.cpp b/Source/ZenLib/Ztring.cpp index 22a39bbd..87760bb1 100644 --- a/Source/ZenLib/Ztring.cpp +++ b/Source/ZenLib/Ztring.cpp @@ -1306,18 +1306,27 @@ Ztring& Ztring::Date_From_Seconds_1970 (const int32s Value) Ztring& Ztring::Date_From_Seconds_1970 (const int64s Value) { time_t Time=(time_t)Value; - #if defined(HAVE_GMTIME_R) - struct tm Gmt_Temp; - struct tm *Gmt=gmtime_r(&Time, &Gmt_Temp); - #elif defined(_MSC_VER) - struct tm Gmt_Temp; - errno_t gmtime_s_Result=gmtime_s(&Gmt_Temp , &Time); - struct tm* Gmt=gmtime_s_Result?NULL:&Gmt_Temp; + #if defined(_WIN32) + #if _CRT_USE_CONFORMING_ANNEX_K_TIME || (__STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) + // C11 standard version on MSVC or other compilers + tm Gmt_Temp; + tm* Gmt = gmtime_s(&Time, &Gmt_Temp); + #else + // MSVC and MinGW-w64 argument order and return value differs from C11 standard + tm Gmt_Temp; + errno_t gmtime_s_Result = gmtime_s(&Gmt_Temp, &Time); + tm* Gmt = gmtime_s_Result ? nullptr : &Gmt_Temp; + #endif + #elif defined(HAVE_GMTIME_R) + // POSIX or C23 + tm Gmt_Temp; + tm *Gmt = gmtime_r(&Time, &Gmt_Temp); #else - #ifdef __GNUC__ - #warning "This version of ZenLib is not thread safe" - #endif - struct tm *Gmt=gmtime(&Time); + // Fallback: not thread-safe, but prevents compile errors + #ifdef __GNUC__ + #warning "This version of ZenLib is not thread safe" + #endif + tm *Gmt = gmtime(&Time); #endif if (!Gmt) { @@ -1349,18 +1358,27 @@ Ztring& Ztring::Date_From_Seconds_1970 (const int64s Value) Ztring& Ztring::Date_From_Seconds_1970_Local (const int32u Value) { time_t Time=(time_t)Value; - #if defined(HAVE_LOCALTIME_R) - struct tm Gmt_Temp; - struct tm *Gmt=localtime_r(&Time, &Gmt_Temp); - #elif defined(_MSC_VER) - struct tm Gmt_Temp; - errno_t localtime_s_Result=localtime_s(&Gmt_Temp , &Time); - struct tm* Gmt=localtime_s_Result?NULL:&Gmt_Temp; + #if defined(_WIN32) + #if _CRT_USE_CONFORMING_ANNEX_K_TIME || (__STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) + // C11 standard version on MSVC or other compilers + tm Gmt_Temp; + tm* Gmt = localtime_s(&Time, &Gmt_Temp); + #else + // MSVC and MinGW-w64 argument order and return value differs from C11 standard + tm Gmt_Temp; + errno_t localtime_s_Result = localtime_s(&Gmt_Temp, &Time); + tm* Gmt = localtime_s_Result ? nullptr : &Gmt_Temp; + #endif + #elif defined(HAVE_GMTIME_R) + // POSIX or C23 + tm Gmt_Temp; + tm *Gmt = localtime_r(&Time, &Gmt_Temp); #else - #ifdef __GNUC__ - #warning "This version of ZenLib is not thread safe" - #endif - struct tm *Gmt=localtime(&Time); + // Fallback: not thread-safe, but prevents compile errors + #ifdef __GNUC__ + #warning "This version of ZenLib is not thread safe" + #endif + tm *Gmt = localtime(&Time); #endif Ztring DateT; Ztring Date; From e786cebf2c878c0ddecd89af68eb46020cb97ce3 Mon Sep 17 00:00:00 2001 From: cjee21 <77721854+cjee21@users.noreply.github.com> Date: Sun, 5 Oct 2025 23:15:26 +0800 Subject: [PATCH 3/3] CI: Use UCRT for MinGW x64 build --- .github/workflows/ZenLib_Checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ZenLib_Checks.yml b/.github/workflows/ZenLib_Checks.yml index c3470fff..1ed58bcd 100644 --- a/.github/workflows/ZenLib_Checks.yml +++ b/.github/workflows/ZenLib_Checks.yml @@ -63,7 +63,7 @@ jobs: - platform: Win32 msystem: MINGW32 - platform: x64 - msystem: MINGW64 + msystem: UCRT64 fail-fast: false env: GENERATOR: "Unix Makefiles"