-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix bit shift math in CFCharacterSet equality code #936
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
Conversation
The code was originally shifting a 32-bit value by 32 bits in some cases, which is undefined behavior. The intent was that all bits would be shifted out, leaving a value of 0 to perform computation with. We now treat the value as 64-bits for the shift and re-cast to 32-bits for the computation.
The code below exercises the code paths in fast path comparison Interestingly, this bug also symptomizes in shipping OS X and iOS.
|
cc: @modocache |
@mark1smi Good catch. Will it be possible to include a unit test for this? |
@pushkarnk Thanks. I provided a unit test in the comment to exercise the C API, but didn't find anywhere in the project where C unit tests run. I spent a number of hours attempting to provide a test in NSCharacterSet.swift, but encountered two problems:
For reference, the swift code for the unit test would look like:
I could add that as a disabled test to the diff if you would like, but it felt to me a strange way of testing the C API. |
We know that NSCharacterSet is basically un-subclassable, which is why we switched the implementation over to has-a CFCharacterSet instead. That is likely the issue you ran into with it in Swift. |
I'll run our internal CF tests against your change to verify this. (rdar://31503541) |
@swift-ci test and merge |
The code was originally shifting a 32-bit value by 32 bits in
some cases, which is undefined behavior. The intent was that
all bits would be shifted out, leaving a value of 0 to perform
computation with. We now treat the value as 64-bits for the shift
and re-cast to 32-bits for the computation.