Skip to content

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

@GitSprocket

Description

@GitSprocket

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions