Skip to content

Commit

Permalink
Added UBSAN complaint fix to rLoadTexture #1891
Browse files Browse the repository at this point in the history
  • Loading branch information
Codom committed Sep 17, 2023
1 parent 33cc18e commit fcec400
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 short *)data;
if (mipOffset > 0) dataPtr += 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)
Expand Down

0 comments on commit fcec400

Please sign in to comment.