Skip to content

Commit

Permalink
Add an assert to fix a Coverity warning in SDL Sound
Browse files Browse the repository at this point in the history
Part of issue #2996

Coverity is reporting a use after free bug in Sound_Quit.
It doesn't look like an actual bug since the code only removes elements
from the head of the linked list.
Add an assert so hopefully Coverity sees that we never take the "broken"
branch.
  • Loading branch information
weirddan455 committed Oct 14, 2023
1 parent d409ebe commit 019003d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libs/decoders/SDL_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ void Sound_FreeSample(Sound_Sample *sample)
/* update the sample_list... */
if (internal->prev != NULL)
{
// We're not removing from the head.
// Assert that we're not touching sample_list (which should be the head of the linked list).
// This assert fixes a Coverity warning.
assert(sample_list != sample);

Sound_SampleInternal *prevInternal;
prevInternal = (Sound_SampleInternal *) internal->prev->opaque;
prevInternal->next = internal->next;
Expand Down

0 comments on commit 019003d

Please sign in to comment.