Fix bad pointer arithmetic in SetBufferData #33

Merged
cosmonaut merged 1 commits from TheSpydog/MoonWorks:pointerfix into main 2022-11-12 03:42:35 +00:00

Fixes a bug where SetBufferData was writing garbage to the buffer if startElement was non-zero.

Rather than fixing the pointer addition (it should have been ptr + startElement) I opted to remove it and instead pass the index explicitly when grabbing the address of the array element. I think that's a little easier to understand, and it's slightly safer too -- if you pass a startElement beyond the array bounds it will now throw an IndexOutOfRangeException instead of silently reading from outside the array bounds.

Fixes a bug where SetBufferData was writing garbage to the buffer if `startElement` was non-zero. Rather than fixing the pointer addition (it should have been `ptr + startElement`) I opted to remove it and instead pass the index explicitly when grabbing the address of the array element. I think that's a little easier to understand, and it's slightly safer too -- if you pass a startElement beyond the array bounds it will now throw an IndexOutOfRangeException instead of silently reading from outside the array bounds.
TheSpydog added 1 commit 2022-11-12 03:41:28 +00:00
cosmonaut merged commit 5533eeb2fd into main 2022-11-12 03:42:35 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: MoonsideGames/MoonWorks#33
There is no content yet.