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

WebSocket.m generates a build warning, which looks like a legit bug #76

Open
GitSprocket opened this issue Oct 20, 2020 · 0 comments
Open

Comments

@GitSprocket
Copy link

I think that the below build warning is pointing to a real defect. The caseInsensitiveCompare call returns a value from the NSComparisonResult enumeration, of which NSOrderedSame is a member. Applying the "!" operator to the NSComparisonResult doesn't seem to make a lot of sense on the face of things.

Plugins/cordova-plugin-httpd/WebSocket.m:111:11: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
22:31:58         else if (![upgradeHeaderValue caseInsensitiveCompare:@"WebSocket"] == NSOrderedSame) {
22:31:58                  ^                                                         ~~
22:31:58 /Users/jenkins/workspace/workspace/VandorLauncherUS/WebClients/LandoLauncher/platforms/ios/Earthworks GO!/Plugins/cordova-plugin-httpd/WebSocket.m:111:11: note: add parentheses after the '!' to evaluate the comparison first
22:31:58         else if (![upgradeHeaderValue caseInsensitiveCompare:@"WebSocket"] == NSOrderedSame) {
22:31:58                  ^
22:31:58                   (                                                                        )
22:31:58 /Users/jenkins/workspace/workspace/VandorLauncherUS/WebClients/LandoLauncher/platforms/ios/Earthworks GO!/Plugins/cordova-plugin-httpd/WebSocket.m:111:11: note: add parentheses around left hand side expression to silence this warning
22:31:58         else if (![upgradeHeaderValue caseInsensitiveCompare:@"WebSocket"] == NSOrderedSame) {
22:31:58                  ^
22:31:58                  (                                                        )

For correctness, the "!A == B" structure of line 111 should be changed to "!(A == B)" or to "A != B", I think.

However, it's interesting to see that NSComparisonResult enumeration is defined with NSOrderedAscending as -1L, then NSOrderedSame, then NSOrderedDescending. If I'm correct to think that applying "!" to any nonzero value will always evaluate to 0 in Objective-C, which is the value of NSOrderedSame, then !A == B coincidentally evaluates to the same result as !(A == B), for this particular situation. I.e. there may be no behavioral change seen by correcting the code.

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

No branches or pull requests

1 participant