Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a Coverity warning in SDL Sound #3000

Merged
merged 2 commits into from
Oct 14, 2023
Merged

Fix a Coverity warning in SDL Sound #3000

merged 2 commits into from
Oct 14, 2023

Conversation

weirddan455
Copy link
Collaborator

Description

First commit fixes the assert macro. The downside of how we're copy + pasting third party libraries into our tree is that we're not using the build system it was written for. HAVE_ASSERT_H is something SDL's build system would have defined. I just removed that macro and always do a #include assert.h since we rely on that header in our other code regardless.

Second commit adds an assert that hopefully Coverity is smart enough to follow. It thinks there is a use after free bug if we're removing from the middle of the linked list in Sound_Quit but that never happens. It's freeing the entire list always removing from the head.

Related issues

#2996

Manual testing

Tested with ripped .ogg files of the Quake sound track. Added the assert and confirmed it does not trigger on quit.

Checklist

Please tick the items as you have addressed them. Don't remove items; leave the ones that are not applicable unchecked.

I have:

  • followed the project's contributing guidelines and code of conduct.
  • performed a self-review of my code.
  • commented on the particularly hard-to-understand areas of my code.
  • split my work into well-defined, bisectable commits, and I named my commits well.
  • applied the appropriate labels (bug, enhancement, refactoring, documentation, etc.)
  • checked that all my commits can be built.
  • confirmed that my code does not cause performance regressions (e.g., by running the Quake benchmark).
  • added unit tests where applicable to prove the correctness of my code and to avoid future regressions.
  • made corresponding changes to the documentation or the website according to the documentation guidelines.
  • locally verified my website or documentation changes.

HAVE_ASSERT_H is not defined anywhere. We already depend on assert.h in
our own code base so just include this without checking.
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.
@weirddan455 weirddan455 added the plumbing Issues related to low-level support functions and classes label Oct 14, 2023
@weirddan455 weirddan455 self-assigned this Oct 14, 2023
@weirddan455
Copy link
Collaborator Author

I don't see Coverity in the list of CI checks for this PR. @kcgen Does this only happen in the main branch? Is there a way I can test this before merging to see if it actually fixes the warning?

Copy link
Member

@kcgen kcgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix, @weirddan455 !

@kcgen
Copy link
Member

kcgen commented Oct 14, 2023

I don't see Coverity in the list of CI checks for this PR. @kcgen Does this only happen in the main branch? Is there a way I can test this before merging to see if it actually fixes the warning?

Yes - we have only 7 scans per week; once we use them, PRs will pass through unscanned.

I'll merge your Coverity fixes in quick succession (CI will quickly cancel jobs from prior merges), so this is one way to manually "combine" a handful of small merges and have them only "cost" us a single Coverity scan.

A scan takes about an hour to complete and it does the entire code base.

@kcgen kcgen merged commit 50f6d57 into main Oct 14, 2023
50 checks passed
@kcgen kcgen deleted the wd/sdl_sound branch October 14, 2023 18:38
@johnnovak johnnovak added the audio Audio related issues or enhancements label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Audio related issues or enhancements plumbing Issues related to low-level support functions and classes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants