Bug 145254

Summary: Fix logical-not-parentheses warning in CachedScript.cpp
Product: WebKit Reporter: Csaba Osztrogonác <ossy>
Component: New BugsAssignee: Csaba Osztrogonác <ossy>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, darin, japhet, ossy
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 145121    
Attachments:
Description Flags
Patch
none
Patch for landing none

Description Csaba Osztrogonác 2015-05-21 03:23:23 PDT
../../Source/WebCore/loader/cache/CachedScript.cpp:98:12: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
    return !parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
           ^                                                                                               ~~
../../Source/WebCore/loader/cache/CachedScript.cpp:98:12: note: add parentheses after the '!' to evaluate the comparison first
    return !parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
           ^
            (                                                                                                                          )
../../Source/WebCore/loader/cache/CachedScript.cpp:98:12: note: add parentheses around left hand side expression to silence this warning
    return !parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
           ^
           (                                                                                              )
1 warning generated.

----

It seems this warning found a real bug should be fixed.
Comment 1 Csaba Osztrogonác 2015-05-21 03:25:35 PDT
Created attachment 253515 [details]
Patch
Comment 2 Alexey Proskuryakov 2015-05-23 18:48:37 PDT
Comment on attachment 253515 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253515&action=review

> Source/WebCore/loader/cache/CachedScript.cpp:98
> +    return !(parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());

Shouldn't this just use != ?
Comment 3 Darin Adler 2015-05-26 14:53:12 PDT
Comment on attachment 253515 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253515&action=review

>> Source/WebCore/loader/cache/CachedScript.cpp:98
>> +    return !(parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
> 
> Shouldn't this just use != ?

I agree that it should.
Comment 4 Darin Adler 2015-05-26 14:53:35 PDT
Also, we should test this feature. Now that we know it was broken.
Comment 5 Csaba Osztrogonác 2015-06-01 02:54:12 PDT
Comment on attachment 253515 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253515&action=review

>>> Source/WebCore/loader/cache/CachedScript.cpp:98
>>> +    return !(parseContentTypeOptionsHeader(m_response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) == ContentTypeOptionsNosniff) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType());
>> 
>> Shouldn't this just use != ?
> 
> I agree that it should.

Good point, I'll change it before landing.
Comment 6 Csaba Osztrogonác 2015-06-01 03:41:30 PDT
(In reply to comment #4)
> Also, we should test this feature. Now that we know it was broken.

Source/WebCore/platform/network/HTTPParsers.h:
-----------------------------------------------
...
enum ContentTypeOptionsDisposition {
    ContentTypeOptionsNone,
    ContentTypeOptionsNosniff
};
...

It is already covered by testcases and this code isn't broken
functionally, because ContentTypeOptionsNosniff gets 1 value in 
this enum and we were lucky and got the same results in both cases.

           X: ContentTypeOptionsNone (0)    X: ContentTypeOptionsNosniff (1)
 !X==1               true                            false
!(X==1)              true                            false
  X!=1               true                            false
Comment 7 Csaba Osztrogonác 2015-06-01 03:47:30 PDT
Created attachment 253991 [details]
Patch for landing
Comment 8 Csaba Osztrogonác 2015-06-01 03:58:44 PDT
( just a note, it is already fixed in blink near 2 years ago :)
  https://codereview.chromium.org/18753002 )
Comment 9 WebKit Commit Bot 2015-06-01 04:37:04 PDT
Comment on attachment 253991 [details]
Patch for landing

Clearing flags on attachment: 253991

Committed r185057: <http://trac.webkit.org/changeset/185057>
Comment 10 WebKit Commit Bot 2015-06-01 04:37:08 PDT
All reviewed patches have been landed.  Closing bug.