Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsrc: audit and fix shift-into-sign-bit bugs #34827
Open
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


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.