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 integer underflow/unsigned wrapping. #607

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

szanni
Copy link
Contributor

@szanni szanni commented Sep 3, 2020

Got pointed here from the Mozilla bug tracker to send in the patch upstream:

This is an attempt at a fix for firefox bug 1614278 where firefox crashes on a regular on xruns. This has been a long standing issue for me (older than the linked bug report). With this patch applied firefox does run stable again with the jack backend.
Looking at the subtraction logic in the xrun handing I am somewhat surprised this does not crash more often. Might also be related to #154

--

The number of xrun fragments to skip is added once to ctx->jack_xruns but
then subtracted multiple times (once for each stream) from the same variable.
This causes the unsigned int to "underflow" and wrap around.

  • Use unsigned int in all calculations instead of mixing un/signed.
  • Remove erroneous and useless subtraction logic
  • Replace for loop by simple multiplication
  • Remove unneeded casts to float

The number of xrun fragments to skip is added once to ctx->jack_xruns but
then subtracted multiple times (once for each stream) from the same variable.
This causes the unsigned int to "underflow" and wrap around.

- Use unsigned int in all calculations instead of mixing un/signed.
- Remove erroneous and useless subtraction logic
- Replace for loop by simple multiplication
- Remove unneeded casts to float
@szanni
Copy link
Contributor Author

szanni commented Sep 12, 2020

Any chance to get a review on this one? @padenot @kinetiknz

@padenot
Copy link
Collaborator

padenot commented Sep 14, 2020

Looks good, sorry for the delay, feel free to ping us directly to get a faster review if we don't get to it quickly enough, especially for things like this that make your life easier.

I'm a bit surprised you're under-running that much, that said. Do you have a setup in which this is expected for some reason?

@padenot padenot merged commit f4c3197 into mozilla:master Sep 14, 2020
@szanni
Copy link
Contributor Author

szanni commented Sep 15, 2020

Delays do happen. I know so myself. All good, thanks for looking at it now.

And regarding the xruns: it is because I usually push my hardware to the limits. Meaning I often run my setup like in a live environment: bitwig and/or traktor open + the buffer size at the lowest setting that does not give me xruns. If I then open Firefox additionally - to watch some tutorial or hunt for some new music - it tends to push my laptop beyond its limits. Hence the occasional under run.

@padenot
Copy link
Collaborator

padenot commented Sep 15, 2020

I see, sounds like a normal behaviour then, considering what is being discussed for the jack backend in other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants