diff --git a/.github/workflows/ZenLib_Checks.yml b/.github/workflows/ZenLib_Checks.yml index ab69b90..1ed58bc 100644 --- a/.github/workflows/ZenLib_Checks.yml +++ b/.github/workflows/ZenLib_Checks.yml @@ -63,11 +63,12 @@ jobs: - platform: Win32 msystem: MINGW32 - platform: x64 - msystem: MINGW64 + msystem: UCRT64 fail-fast: false 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 207f8ee..4867cd1 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/Utils.cpp b/Source/ZenLib/Utils.cpp index 7f6daf4..4074c70 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) diff --git a/Source/ZenLib/Ztring.cpp b/Source/ZenLib/Ztring.cpp index 22a39bb..87760bb 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;