Skip to content

gh-106550: Fix sign conversion in pycore_code.h #112613

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

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 2, 2023

Fix sign conversion in pycore_code.h: use unsigned integers and cast explicitly when needed.

Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
@@ -473,12 +475,12 @@ adaptive_counter_cooldown(void) {

static inline uint16_t
adaptive_counter_backoff(uint16_t counter) {
unsigned int backoff = counter & ((1<<ADAPTIVE_BACKOFF_BITS)-1);
uint16_t backoff = counter & ((1 << ADAPTIVE_BACKOFF_BITS) - 1);
Copy link
Member

Choose a reason for hiding this comment

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

Is there difference between 1 << ADAPTIVE_BACKOFF_BITS and 1u << ADAPTIVE_BACKOFF_BITS?

Copy link
Member Author

Choose a reason for hiding this comment

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

I hesitated to replace 1 with 1U. With proposed code, there is no warning. With 1U I got additional warnings 🤷🏻‍♂️ Maybe because "unsigned int" is larger than uint16_t. I don't know rules of implicit cast in C.

@vstinner vstinner merged commit a74902a into python:main Dec 4, 2023
@vstinner vstinner deleted the code_unsigned branch December 4, 2023 10:43
@miss-islington-app
Copy link

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@bedevere-app
Copy link

bedevere-app bot commented Dec 4, 2023

GH-112696 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 4, 2023
Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
(cherry picked from commit a74902a)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Dec 4, 2023
@vstinner
Copy link
Member Author

vstinner commented Dec 4, 2023

Merged, thanks for the review Serhiy.

vstinner added a commit that referenced this pull request Dec 4, 2023
…112696)

gh-106550: Fix sign conversion in pycore_code.h (GH-112613)

Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
(cherry picked from commit a74902a)

Co-authored-by: Victor Stinner <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Fix sign conversion in pycore_code.h: use unsigned integers and cast
explicitly when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants