From f6f31a9f216c54fe8bf661e042a4cfc9a6892e33 Mon Sep 17 00:00:00 2001 From: Asdqwe Date: Sun, 26 Jan 2025 17:26:18 -0300 Subject: [PATCH 1/3] [rtextures] Fix `HalfToFloat()` and `FloatToHalf()` dereferencing issues with an union (#4729) * Fix HalfToFloat() and FloatToHalf() dereferencing issues with an union * Remove unnecessary initialization * Moved the union to inside the functions --- src/rtextures.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/rtextures.c b/src/rtextures.c index 9d3f51f34..0317f0385 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -5390,13 +5390,19 @@ static float HalfToFloat(unsigned short x) { float result = 0.0f; + union + { + float fm; + unsigned int ui; + } uni; + const unsigned int e = (x & 0x7C00) >> 10; // Exponent const unsigned int m = (x & 0x03FF) << 13; // Mantissa - const float fm = (float)m; - const unsigned int v = (*(unsigned int *)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format - const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized + uni.fm = (float)m; + const unsigned int v = uni.ui >> 23; // Evil log2 bit hack to count leading zeros in denormalized format + uni.ui = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized - result = *(float *)&r; + result = uni.fm; return result; } @@ -5406,7 +5412,14 @@ static unsigned short FloatToHalf(float x) { unsigned short result = 0; - const unsigned int b = (*(unsigned int *) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa + union + { + float fm; + unsigned int ui; + } uni; + uni.fm = x; + + const unsigned int b = uni.ui + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa const unsigned int e = (b & 0x7F800000) >> 23; // Exponent const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding From 5504983c91f90df0e2f5acbc0545dd2dc28cbd80 Mon Sep 17 00:00:00 2001 From: elite0OG Date: Mon, 27 Jan 2025 13:50:10 +0530 Subject: [PATCH 2/3] Update CMakeLists.txt (#4727) Cmake warn remove --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9905ba144..af4444e07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.25) +#this change avoid the warning that appear when we include raylib using Cmake fatch content project(raylib) # Avoid excessive expansion of variables in conditionals. In particular, if From 2492dd3d0a69efe77185daf708f9f8aa458113a8 Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Mon, 27 Jan 2025 22:15:09 +0000 Subject: [PATCH 3/3] [build] [Makefile]: Undefine _GNU_SOURCE for rglfw.c (#4732) Currently, a warning about _GNU_SOURCE being redefined is emitted when compiling rglfw.c In file included from rglfw.c:99: external/glfw/src/posix_poll.c:27:9: warning: "_GNU_SOURCE" redefined 27 | #define _GNU_SOURCE | ^~~~~~~~~~~ : note: this is the location of the previous definition This can be avoided by not defining _GNU_SOURCE on the command line for this file. Defining feature test macros in source code is not really good practice so this should probably reviewed in glfw itself, at least to maybe check #ifdef _GNU_SOURCE first. But for now this change will suffice. Fixes #4725 --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index b05b257d3..1b7562da4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -742,7 +742,7 @@ rcore.o : rcore.c raylib.h rlgl.h utils.h raymath.h rcamera.h rgestures.h # Compile rglfw module rglfw.o : rglfw.c - $(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) + $(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) -U_GNU_SOURCE # Compile shapes module rshapes.o : rshapes.c raylib.h rlgl.h