summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorChristopher Odom <[email protected]>2023-09-18 13:39:12 -0400
committerGitHub <[email protected]>2023-09-18 19:39:12 +0200
commiteb461512a7191896acda33330e643b0dd60365b3 (patch)
tree31efd218b2833a6dc026cd0a125e85f92742cca8 /src
parent4d2906b0a5766823cbd9808431656140dae881b9 (diff)
downloadraylib-eb461512a7191896acda33330e643b0dd60365b3.tar.gz
raylib-eb461512a7191896acda33330e643b0dd60365b3.zip
Added UBSAN complaint fix to rLoadTexture #1891 (#3321)
Diffstat (limited to 'src')
-rw-r--r--src/rlgl.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/rlgl.h b/src/rlgl.h
index 6dee60f9..bef4fdc2 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -3009,11 +3009,15 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,
TRACELOGD("TEXTURE: Load mipmap level %i (%i x %i), size: %i, offset: %i", i, mipWidth, mipHeight, mipSize, mipOffset);
+ // NOTE: Added pointer math separately from function to avoid UBSAN complaining
+ unsigned char *dataPtr = (unsigned char*)data;
+ if (mipOffset > 0) dataPtr = (unsigned char*)data + mipOffset;
+
if (glInternalFormat != -1)
{
- if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, glFormat, glType, (unsigned char *)data + mipOffset);
+ if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, glFormat, glType, dataPtr);
#if !defined(GRAPHICS_API_OPENGL_11)
- else glCompressedTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, mipSize, (unsigned char *)data + mipOffset);
+ else glCompressedTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, mipSize, dataPtr);
#endif
#if defined(GRAPHICS_API_OPENGL_33)