Skip to content

[models] UBSAN flags 0 offset to NULL in DrawMesh #1891

@rcorre

Description

@rcorre

WARNING: Please, read this note carefully before submitting a new issue:

It is important to realise that this is NOT A SUPPORT FORUM, this is for reproducible BUGS with raylib ONLY.

There are lots of generous and helpful people ready to help you out on raylib Discord forum or raylib reddit.

Remember that asking for support questions here actively takes developer time away from improving raylib.


Please, before submitting a new issue verify and check:

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • My code has no errors or misuse of raylib

Issue description

Briefly describe the issue you are experiencing (or the feature you want to see added to raylib). Tell us what you were trying to do and what happened instead. Remember, this is not the best place to ask questions. For questions, go to raylib Discord server.

UBSAN flags

if (mesh.indices != NULL) rlDrawVertexArrayElements(0, mesh.triangleCount*3, 0);
as undefined behavior (adding an offset to a NULL pointer, which happens at

raylib/src/rlgl.h

Line 3124 in 87b5420

glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (unsigned short*)buffer + offset);
)

rlgl.h:3124:84: runtime error: applying zero offset to null pointer

From some reading around (e.g. https://patchwork.kernel.org/project/git/patch/20200125053834.GB744673@coredump.intra.peff.net/), it sounds like adding any offset (even 0) to NULL is technically undefined behavior.

This was introduced sometime between raylib 3.5.0 and raylib 3.7.0, and still exists on master.

Environment

Linux, desktop.

Issue Screenshot

If possible, provide a screenshot that illustrates the issue. Usually an image is better than a thousand words.

Code Example

Provide minimal reproduction code to test the issue. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced issue.

  1. Compile raylib with the undefined behavior sanitizer
  2. Run shaders_basic_lighting example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions