Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ZenLib_Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 20 additions & 12 deletions Source/ZenLib/Format/Http/Http_Cookies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions Source/ZenLib/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ZenLib/Utils.h"
#include <cmath>
#include <complex>
#include <limits>
//---------------------------------------------------------------------------

namespace ZenLib
Expand Down Expand Up @@ -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<int32s>::max())
return std::numeric_limits<int32s>::max();
if (F<=(float32)std::numeric_limits<int32s>::min())
return std::numeric_limits<int32s>::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
Expand All @@ -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<int64s>::max())
return std::numeric_limits<int64s>::max();
if (F<=(float32)std::numeric_limits<int64s>::min())
return std::numeric_limits<int64s>::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
Expand All @@ -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<int32s>::max())
return std::numeric_limits<int32s>::max();
if (F<=(float64)std::numeric_limits<int32s>::min())
return std::numeric_limits<int32s>::min();

//Not rounded
if (!Rounded)
Expand All @@ -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<int64s>::max())
return std::numeric_limits<int64s>::max();
if (F<=(float64)std::numeric_limits<int64s>::min())
return std::numeric_limits<int64s>::min();

//Not rounded
if (!Rounded)
Expand Down
62 changes: 40 additions & 22 deletions Source/ZenLib/Ztring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down