Skip to content

Conversation

@cjee21
Copy link
Contributor

@cjee21 cjee21 commented Oct 2, 2025

Fix warnings when building for Android

  • Mostly about implicit conversions

Better select between gmtime, gmtime_r, gmtime_s and localtime, localtime_r, localtime_s as well as _s variants.

  • Fixes "This version of ZenLib is not thread safe" warnings on MinGW

Change MinGW x64 CI to use newer UCRT variant.

@cjee21 cjee21 force-pushed the fix branch 7 times, most recently from 65f4905 to bd93f70 Compare October 5, 2025 06:43
@cjee21 cjee21 changed the title Fix warnings when building for Android Fix warnings when building for Android and MinGW Oct 5, 2025
@cjee21
Copy link
Contributor Author

cjee21 commented Oct 5, 2025

@JeromeMartinez I did not test with C++Builder (license expired). If there are still warnings there then maybe we need to #define __STDC_WANT_LIB_EXT1__ 1 somewhere.


Ran through Cppcheck, seems okay with only false positives

>cppcheck.exe Source\ZenLib\ --check-level=exhaustive --force -q
Source\ZenLib\MemoryDebug.cpp:140:14: error: Memory is allocated but not initialized: Ptr [uninitdata]
    m_Blocks[Ptr]  = NewBlock;
             ^
Source\ZenLib\Ztring.cpp:598:36: error: Memory is allocated but not initialized: WideString [uninitdata]
                    Size=mbsrtowcs(WideString, &S, Size, NULL);
                                   ^
Source\ZenLib\Ztring.cpp:1369:50: error: Uninitialized variable: &Gmt_Temp [uninitvar]
        errno_t localtime_s_Result = localtime_s(&Gmt_Temp, &Time);
                                                 ^

Visual Studio code analysis found no issues.

@cjee21 cjee21 force-pushed the fix branch 2 times, most recently from 923d9e4 to 0bf4c82 Compare October 5, 2025 15:15
Copy link
Member

@JeromeMartinez JeromeMartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your modifications don't do the same thing (signed vs unsigned), I needed to updated it like that for having it working correctly:

 Source/ZenLib/Utils.cpp | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/Source/ZenLib/Utils.cpp b/Source/ZenLib/Utils.cpp
index 452c0f0..4074c70 100644
--- a/Source/ZenLib/Utils.cpp
+++ b/Source/ZenLib/Utils.cpp
@@ -19,6 +19,7 @@
 #include "ZenLib/Utils.h"
 #include <cmath>
 #include <complex>
+#include <limits>
 //---------------------------------------------------------------------------
 
 namespace ZenLib
@@ -972,10 +973,10 @@ void   int64u_int32u (int64u BigInt, int32u &High, int32u &Low)
 int32s float32_int32s (float32 F, bool Rounded)
 {
     //Out of boundaries
-    if (F>=(float32)0x7FFFFFFF)
-        return (int32s)0x7FFFFFFF;
-    if (F<=(float32)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)
@@ -991,10 +992,10 @@ int32s float32_int32s (float32 F, bool Rounded)
 int64s float32_int64s (float32 F, bool Rounded)
 {
     //Out of boundaries
-    if (F>=(float32)0x7FFFFFFFFFFFFFFFLL)
-        return (int64s)0x7FFFFFFFFFFFFFFFLL;
-    if (F<=(float32)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)
@@ -1010,10 +1011,10 @@ int64s float32_int64s (float32 F, bool Rounded)
 int32s float64_int32s (float64 F, bool Rounded)
 {
     //Out of boundaries
-    if (F>=(float64)0x7FFFFFFF)
-        return (int32s)0x7FFFFFFF;
-    if (F<=(float64)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)
@@ -1029,10 +1030,10 @@ int32s float64_int32s (float64 F, bool Rounded)
 int64s float64_int64s (float64 F, bool Rounded)
 {
     //Out of boundaries
-    if (F>=(float64)0x7FFFFFFFFFFFFFFFLL)
-        return (int64s)0x7FFFFFFFFFFFFFFFLL;
-    if (F<=(float64)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)

Please update the corresponding commit.

@JeromeMartinez JeromeMartinez merged commit 490e242 into MediaArea:master Oct 5, 2025
7 checks passed
@JeromeMartinez
Copy link
Member

Thank you.

@cjee21 cjee21 deleted the fix branch October 5, 2025 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants