-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
src: audit and fix shift-into-sign-bit bugs #34827
Copy link
Copy link
Closed
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
Metadata
Metadata
Assignees
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.good first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
The LHS here is usually of type
unsigned charbut gets promoted to int (because 24 is an int) and is then left-shifted.If the LHS >= 128, that ends up shifting into the sign bit and that's implementation-defined behavior (i.e., bad - although it probably works okay with most compilers.)
Replace
24with24uand all is good. But! It's probably best to abstract it away into a helper function.cares_wrap.cc already has one -
cares_get_32bit()- that handles it correctly.