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

gh-96821: Fix undefined behaviour in audioop.c #96923

Merged
merged 11 commits into from
Oct 10, 2022

Conversation

matthiasgoergens
Copy link
Contributor

@matthiasgoergens matthiasgoergens commented Sep 19, 2022

Left-shifting negative numbers is undefined behaviour.

Fortunately, multiplication works just as well, is (implementation) defined behaviour, and gets compiled to the same machine code as before by optimizing compilers.

Left-shifting negative numbers is undefined behaviour.

Fortunately, multiplication works just as well, is defined behaviour,
and gets compiled to the same machine code as before by optimizing
compilers.
@matthiasgoergens
Copy link
Contributor Author

matthiasgoergens commented Sep 19, 2022

@kumaraditya303 @mdickinson @erlend-aasland Would you please have a look? Thanks!

@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Sep 26, 2022

Sorry but I won't have time for this in the near future, Mark or Erlend can take a look.

Modules/audioop.c Outdated Show resolved Hide resolved
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

The changes LGTM at least in principle; I haven't done much in the way of testing.

Modules/audioop.c Outdated Show resolved Hide resolved
Modules/audioop.c Outdated Show resolved Hide resolved
@mdickinson
Copy link
Member

@matthiasgoergens Can we revert the changes at lines 173 and 262 of the original code? I'm fairly sure that those changes aren't necessary, because the quantity being shifted is always nonnegative.

@mdickinson
Copy link
Member

Can we revert the changes at lines 173 and 262 of the original code?

To be clear, I'm happy with the rest of the changes as-is, so if @JelleZijlstra is also happy, I think we can merge after those two reversions.

@matthiasgoergens
Copy link
Contributor Author

@mdickinson Thanks. I'll revert the lines you asked about.

@matthiasgoergens
Copy link
Contributor Author

matthiasgoergens commented Oct 9, 2022

@mdickinson @JelleZijlstra I applied the suggested changes.

Thanks for having a look!

@mdickinson mdickinson merged commit 553d3c1 into python:main Oct 10, 2022
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
* pythongh-96821: Fix undefined behaviour in `audioop.c`

Left-shifting negative numbers is undefined behaviour.

Fortunately, multiplication works just as well, is defined behaviour,
and gets compiled to the same machine code as before by optimizing
compilers.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
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.

5 participants