diff options
| author | Ray <[email protected]> | 2023-09-07 18:00:10 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-09-07 18:00:10 +0200 |
| commit | 30a9a24db9d2561335a2a42d423cf9cfeab6e769 (patch) | |
| tree | 9022eda103d55b51408019ce3bc86e17f8a4e628 /src | |
| parent | 18e9784c6d2f05ea82d5be0b86913b870e4fcf88 (diff) | |
| download | raylib-30a9a24db9d2561335a2a42d423cf9cfeab6e769.tar.gz raylib-30a9a24db9d2561335a2a42d423cf9cfeab6e769.zip | |
Review to avoid UBSAN complaining #1891
Diffstat (limited to 'src')
| -rw-r--r-- | src/rlgl.h | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -3687,7 +3687,11 @@ void rlDrawVertexArray(int offset, int count) // Draw vertex array elements void rlDrawVertexArrayElements(int offset, int count, const void *buffer) { - glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset); + // NOTE: Added pointer math separately from function to avoid UBSAN complaining + unsigned short *bufferPtr = (unsigned short *)buffer; + if (offset > 0) bufferPtr += offset; + + glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)bufferPtr); } // Draw vertex array instanced @@ -3702,7 +3706,11 @@ void rlDrawVertexArrayInstanced(int offset, int count, int instances) void rlDrawVertexArrayElementsInstanced(int offset, int count, const void *buffer, int instances) { #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) - glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset, instances); + // NOTE: Added pointer math separately from function to avoid UBSAN complaining + unsigned short *bufferPtr = (unsigned short *)buffer; + if (offset > 0) bufferPtr += offset; + + glDrawElementsInstanced(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)bufferPtr, instances); #endif } |
