Fixed UBSan trip in GLFW OpenGL3 demo backend

This resolves a false UBSan trip caused by treating the element offset
in `glDrawElements` as a pointer
This parameter is effectively an offset but is taken as a `void*`
By not storing the offset as a pointer, UBSan no longer tools the offset
to check for null pointer overflow
This commit is contained in:
Th3T3chn0G1t 2022-11-24 10:21:37 +00:00
parent 3a0aafb9cc
commit 637b5e198d
No known key found for this signature in database
GPG Key ID: 0DE26D459CC044BC
1 changed files with 3 additions and 3 deletions

View File

@ -240,7 +240,7 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b
/* convert from command queue into draw list and draw to screen */
const struct nk_draw_command *cmd;
void *vertices, *elements;
const nk_draw_index *offset = NULL;
nk_size offset = 0;
/* allocate vertex and element buffer */
glBindVertexArray(dev->vao);
@ -292,8 +292,8 @@ nk_glfw3_render(struct nk_glfw* glfw, enum nk_anti_aliasing AA, int max_vertex_b
(GLint)((glfw->height - (GLint)(cmd->clip_rect.y + cmd->clip_rect.h)) * glfw->fb_scale.y),
(GLint)(cmd->clip_rect.w * glfw->fb_scale.x),
(GLint)(cmd->clip_rect.h * glfw->fb_scale.y));
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, offset);
offset += cmd->elem_count;
glDrawElements(GL_TRIANGLES, (GLsizei)cmd->elem_count, GL_UNSIGNED_SHORT, (const void*) offset);
offset += cmd->elem_count * sizeof(nk_draw_index);
}
nk_clear(&glfw->ctx);
nk_buffer_clear(&dev->cmds);