Bug 53266 - Add WTFString method to compare equality with Vector<UChar>
Summary: Add WTFString method to compare equality with Vector<UChar>
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Adam Barth
URL:
Keywords:
Depends on:
Blocks: 49845
  Show dependency treegraph
 
Reported: 2011-01-27 16:17 PST by Adam Barth
Modified: 2011-01-27 20:27 PST (History)
5 users (show)

See Also:


Attachments
Patch (2.48 KB, patch)
2011-01-27 16:18 PST, Adam Barth
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Barth 2011-01-27 16:17:26 PST
Add WTFString method to compare equality with Vector<UChar>
Comment 1 Adam Barth 2011-01-27 16:18:35 PST
Created attachment 80373 [details]
Patch
Comment 2 Eric Seidel (no email) 2011-01-27 16:59:49 PST
Comment on attachment 80373 [details]
Patch

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

Seems OK.

> Source/JavaScriptCore/wtf/text/StringImpl.h:366
> +    if (!a.size())
> +        return true;
> +    return !memcmp(a.data(), b->characters(), b->length());

Is calling memcmp with length = 0 OK?  If so then you don't need the !a.size() check.
Comment 3 Adam Barth 2011-01-27 17:04:14 PST
Comment on attachment 80373 [details]
Patch

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

>> Source/JavaScriptCore/wtf/text/StringImpl.h:366
>> +    if (!a.size())
>> +        return true;
>> +    return !memcmp(a.data(), b->characters(), b->length());
> 
> Is calling memcmp with length = 0 OK?  If so then you don't need the !a.size() check.

Sounds dodgy:
http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-07/0109.html
Comment 4 Darin Adler 2011-01-27 17:45:14 PST
(In reply to comment #3)
> > Is calling memcmp with length = 0 OK?  If so then you don't need the !a.size() check.
> 
> Sounds dodgy:
> http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-07/0109.html

Why the FUD? memcpy with length == 0 is definitely OK!
Comment 5 Darin Adler 2011-01-27 17:45:27 PST
(In reply to comment #4)
> Why the FUD? memcpy with length == 0 is definitely OK!

I mean memcmp.
Comment 6 Adam Barth 2011-01-27 17:55:53 PST
> Why the FUD? memcpy with length == 0 is definitely OK!

Even if one of the pointers is NULL?
Comment 7 Darin Adler 2011-01-27 18:03:31 PST
(In reply to comment #6)
> > Why the FUD? memcmp with length == 0 is definitely OK!
> 
> Even if one of the pointers is NULL?

In practice, yes. I am pretty damned sure of this. And I think we rely on it.

But the C standard does use wording that makes it seem a little ambiguous.
Comment 8 Adam Barth 2011-01-27 18:15:10 PST
Okiedokes.  Thanks.
Comment 9 Adam Barth 2011-01-27 18:21:05 PST
Committed r76894: <http://trac.webkit.org/changeset/76894>
Comment 10 WebKit Review Bot 2011-01-27 19:47:31 PST
Attachment 80373 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7597383
Comment 11 WebKit Review Bot 2011-01-27 20:27:11 PST
http://trac.webkit.org/changeset/76894 might have broken GTK Linux 64-bit Debug