<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>28901</bug_id>
          
          <creation_ts>2009-09-01 20:20:54 -0700</creation_ts>
          <short_desc>strnstr in wtf/StringExtras.h</short_desc>
          <delta_ts>2010-02-10 18:24:34 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fumitoshi Ukai">ukai</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>eric</cc>
    
    <cc>oinktomi</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>144104</commentid>
    <comment_count>0</comment_count>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-01 20:20:54 -0700</bug_when>
    <thetext>Add strnstr in wtf/StringExtras.h
MacOSX has strnstr(), but at least Linux and Windows don&apos;t have it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144117</commentid>
    <comment_count>1</comment_count>
      <attachid>38912</attachid>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-01 22:28:02 -0700</bug_when>
    <thetext>Created attachment 38912
Add strnstr for Linux and Windows in StringExtras.h


---
 2 files changed, 26 insertions(+), 0 deletions(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144118</commentid>
    <comment_count>2</comment_count>
      <attachid>38912</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2009-09-01 23:46:18 -0700</bug_when>
    <thetext>Comment on attachment 38912
Add strnstr for Linux and Windows in StringExtras.h

&gt; +    return NULL;

Should be 0, not NULL.

Is this new code, or did you take it from somewhere? The implementation in &lt;http://www.opensource.apple.com/source/Libc/Libc-583/string/FreeBSD/strnstr.c&gt; looks quite different, but I do not know if any of the differences are practical.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144128</commentid>
    <comment_count>3</comment_count>
      <attachid>38912</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-09-02 00:30:08 -0700</bug_when>
    <thetext>Comment on attachment 38912
Add strnstr for Linux and Windows in StringExtras.h

I would have used longer names for the variables.  Just because this is a POSIX method doesn&apos;t mean we have to use old c-style naming conventions. ;)

r-, but not for the naming nit, rather for the nits above from ap. :)

Thanks for the patch!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144129</commentid>
    <comment_count>4</comment_count>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-02 00:34:21 -0700</bug_when>
    <thetext>Thanks for the review

(In reply to comment #2)
&gt; (From update of attachment 38912 [details])
&gt; &gt; +    return NULL;
&gt; 
&gt; Should be 0, not NULL.
&gt; 
&gt; Is this new code, or did you take it from somewhere? The implementation in
&gt; &lt;http://www.opensource.apple.com/source/Libc/Libc-583/string/FreeBSD/strnstr.c&gt;
&gt; looks quite different, but I do not know if any of the differences are
&gt; practical.

This is new code. Should we use FreeBSD implementation?
I&apos;m slightly worried about copyright issue (FreeBSD one has advertise clause).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144159</commentid>
    <comment_count>5</comment_count>
      <attachid>38917</attachid>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-02 02:21:50 -0700</bug_when>
    <thetext>Created attachment 38917
Add strnstr for Linux and Windows in StringExtras.h


---
 2 files changed, 26 insertions(+), 0 deletions(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144230</commentid>
    <comment_count>6</comment_count>
      <attachid>38917</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-09-02 09:18:55 -0700</bug_when>
    <thetext>Comment on attachment 38917
Add strnstr for Linux and Windows in StringExtras.h

This is a fairly long function. Do we really want it as an inline? I suppose we don&apos;t have a StringExtras.cpp so this is OK for now.

The name &quot;find&quot; is not really good as a name for the second argument, because it&apos;s a verb, not a noun. The second argument is the string to find, not &quot;a find&quot;. So I suggest calling it something like &quot;target&quot;.

&gt; +    int findLength = strlen(find);

The result of strlen is a size_t, not an int. There&apos;s no reason to use int instead of size_t here.

&gt; +    for (const char* start = buffer; *start &amp;&amp; start + findLength &lt;= buffer + bufferLength; start++) {
&gt; +        if (*start == *find &amp;&amp; strncmp(start, find, findLength) == 0)
&gt; +            return const_cast&lt;char*&gt;(start);
&gt; +    }

I&apos;d think you&apos;d want to call strncmp on start + 1 and find + 1 and findLength - 1 instead.

r=me but I think it&apos;s worth fixing some of those things I mentioned. So you could clear the review flag if you intend to post a new patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144360</commentid>
    <comment_count>7</comment_count>
      <attachid>38958</attachid>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-02 18:28:14 -0700</bug_when>
    <thetext>Created attachment 38958
Add strnstr for Linux and Windows in StringExtras.h


---
 2 files changed, 26 insertions(+), 0 deletions(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144361</commentid>
    <comment_count>8</comment_count>
    <who name="Fumitoshi Ukai">ukai</who>
    <bug_when>2009-09-02 18:29:24 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; (From update of attachment 38917 [details])
&gt; This is a fairly long function. Do we really want it as an inline? I suppose we
&gt; don&apos;t have a StringExtras.cpp so this is OK for now.
&gt; 
&gt; The name &quot;find&quot; is not really good as a name for the second argument, because
&gt; it&apos;s a verb, not a noun. The second argument is the string to find, not &quot;a
&gt; find&quot;. So I suggest calling it something like &quot;target&quot;.
&gt; 
&gt; &gt; +    int findLength = strlen(find);
&gt; 
&gt; The result of strlen is a size_t, not an int. There&apos;s no reason to use int
&gt; instead of size_t here.
&gt; 
&gt; &gt; +    for (const char* start = buffer; *start &amp;&amp; start + findLength &lt;= buffer + bufferLength; start++) {
&gt; &gt; +        if (*start == *find &amp;&amp; strncmp(start, find, findLength) == 0)
&gt; &gt; +            return const_cast&lt;char*&gt;(start);
&gt; &gt; +    }
&gt; 
&gt; I&apos;d think you&apos;d want to call strncmp on start + 1 and find + 1 and findLength -
&gt; 1 instead.
&gt; 
&gt; r=me but I think it&apos;s worth fixing some of those things I mentioned. So you
&gt; could clear the review flag if you intend to post a new patch.

Thanks for review. Fixed those things.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144438</commentid>
    <comment_count>9</comment_count>
      <attachid>38958</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-09-03 01:49:31 -0700</bug_when>
    <thetext>Comment on attachment 38958
Add strnstr for Linux and Windows in StringExtras.h

Based partially on Darin&apos;s previous r+, this still looks good.  Thanks for the patch!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144466</commentid>
    <comment_count>10</comment_count>
      <attachid>38958</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-09-03 02:38:07 -0700</bug_when>
    <thetext>Comment on attachment 38958
Add strnstr for Linux and Windows in StringExtras.h

Clearing flags on attachment: 38958

Committed r48012: &lt;http://trac.webkit.org/changeset/48012&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>144467</commentid>
    <comment_count>11</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-09-03 02:38:11 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>189564</commentid>
    <comment_count>12</comment_count>
    <who name="Noah Friedman">oinktomi</who>
    <bug_when>2010-02-10 18:24:34 -0800</bug_when>
    <thetext>This seems to be needed for PLATFORM(SOLARIS) also, at least with Solaris 10 sparc.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>38912</attachid>
            <date>2009-09-01 22:28:02 -0700</date>
            <delta_ts>2009-09-02 02:21:45 -0700</delta_ts>
            <desc>Add strnstr for Linux and Windows in StringExtras.h</desc>
            <filename>bug-28901-20090902142800.patch</filename>
            <type>text/plain</type>
            <size>1246</size>
            <attacher name="Fumitoshi Ukai">ukai</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZyBiL0phdmFTY3JpcHRDb3JlL0No
YW5nZUxvZwppbmRleCBlZjEyMWZhLi5hMGMwOGE0IDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS9DaGFuZ2VMb2cKKysrIGIvSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTMg
QEAKKzIwMDktMDktMDEgIEZ1bWl0b3NoaSBVa2FpICA8dWthaUBjaHJvbWl1bS5vcmc+CisKKyAg
ICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgQWRkIHN0cm5zdHIg
Zm9yIExpbnV4IGFuZCBXaW5kb3dzIGluIFN0cmluZ0V4dHJhcy5oCisgICAgICAgIGh0dHBzOi8v
YnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yODkwMQorCisgICAgICAgICogd3RmL1N0
cmluZ0V4dHJhcy5oOgorICAgICAgICAoc3RybnN0cik6CisKIDIwMDktMDgtMzEgIFJvYmVydCBB
Z29zdG9uICA8QWdvc3Rvbi5Sb2JlcnRAc3R1ZC51LXN6ZWdlZC5odT4KIAogICAgICAgICBSZXZp
ZXdlZCBieSBHYXZpbiBCYXJyYWNsb3VnaC4KZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL3d0
Zi9TdHJpbmdFeHRyYXMuaCBiL0phdmFTY3JpcHRDb3JlL3d0Zi9TdHJpbmdFeHRyYXMuaAppbmRl
eCAxYzIzMzkwLi41MmVkNzYzIDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29yZS93dGYvU3RyaW5n
RXh0cmFzLmgKKysrIGIvSmF2YVNjcmlwdENvcmUvd3RmL1N0cmluZ0V4dHJhcy5oCkBAIC04NSw0
ICs4NSwyMCBAQCBpbmxpbmUgaW50IHN0cmNhc2VjbXAoY29uc3QgY2hhciogczEsIGNvbnN0IGNo
YXIqIHMyKQogCiAjZW5kaWYKIAorI2lmIFBMQVRGT1JNKFdJTl9PUykgfHwgUExBVEZPUk0oTElO
VVgpCisKK2lubGluZSBjaGFyKiBzdHJuc3RyKGNvbnN0IGNoYXIqIHMxLCBjb25zdCBjaGFyKiBz
Miwgc2l6ZV90IG4pCit7CisgICAgaW50IHMybGVuID0gc3RybGVuKHMyKTsKKyAgICBpZiAoczJs
ZW4gPT0gMCkKKyAgICAgICAgcmV0dXJuIGNvbnN0X2Nhc3Q8Y2hhcio+KHMxKTsKKyAgICBmb3Ig
KGNvbnN0IGNoYXIqIHAgPSBzMTsgKnAgJiYgcCArIHMybGVuIDw9IHMxICsgbjsgcCsrKSB7Cisg
ICAgICAgIGlmICgqcCA9PSAqczIgJiYgc3RybmNtcChwLCBzMiwgczJsZW4pID09IDApCisgICAg
ICAgICAgICByZXR1cm4gY29uc3RfY2FzdDxjaGFyKj4ocCk7CisgICAgfQorICAgIHJldHVybiBO
VUxMOworfQorCisjZW5kaWYKKwogI2VuZGlmIC8vIFdURl9TdHJpbmdFeHRyYXNfaA==
</data>

          </attachment>
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>38917</attachid>
            <date>2009-09-02 02:21:50 -0700</date>
            <delta_ts>2009-09-02 18:28:09 -0700</delta_ts>
            <desc>Add strnstr for Linux and Windows in StringExtras.h</desc>
            <filename>bug-28901-20090902182148.patch</filename>
            <type>text/plain</type>
            <size>1337</size>
            <attacher name="Fumitoshi Ukai">ukai</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZyBiL0phdmFTY3JpcHRDb3JlL0No
YW5nZUxvZwppbmRleCBlZjEyMWZhLi42NDQ1NTVmIDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS9DaGFuZ2VMb2cKKysrIGIvSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTMg
QEAKKzIwMDktMDktMDIgIEZ1bWl0b3NoaSBVa2FpICA8dWthaUBjaHJvbWl1bS5vcmc+CisKKyAg
ICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgQWRkIHN0cm5zdHIg
Zm9yIExpbnV4IGFuZCBXaW5kb3dzIGluIFN0cmluZ0V4dHJhcy5oCisgICAgICAgIGh0dHBzOi8v
YnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yODkwMQorCisgICAgICAgICogd3RmL1N0
cmluZ0V4dHJhcy5oOgorICAgICAgICAoc3RybnN0cik6CisKIDIwMDktMDgtMzEgIFJvYmVydCBB
Z29zdG9uICA8QWdvc3Rvbi5Sb2JlcnRAc3R1ZC51LXN6ZWdlZC5odT4KIAogICAgICAgICBSZXZp
ZXdlZCBieSBHYXZpbiBCYXJyYWNsb3VnaC4KZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL3d0
Zi9TdHJpbmdFeHRyYXMuaCBiL0phdmFTY3JpcHRDb3JlL3d0Zi9TdHJpbmdFeHRyYXMuaAppbmRl
eCAxYzIzMzkwLi5lMzZjMTY2IDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29yZS93dGYvU3RyaW5n
RXh0cmFzLmgKKysrIGIvSmF2YVNjcmlwdENvcmUvd3RmL1N0cmluZ0V4dHJhcy5oCkBAIC04NSw0
ICs4NSwyMCBAQCBpbmxpbmUgaW50IHN0cmNhc2VjbXAoY29uc3QgY2hhciogczEsIGNvbnN0IGNo
YXIqIHMyKQogCiAjZW5kaWYKIAorI2lmIFBMQVRGT1JNKFdJTl9PUykgfHwgUExBVEZPUk0oTElO
VVgpCisKK2lubGluZSBjaGFyKiBzdHJuc3RyKGNvbnN0IGNoYXIqIGJ1ZmZlciwgY29uc3QgY2hh
ciogZmluZCwgc2l6ZV90IGJ1ZmZlckxlbmd0aCkKK3sKKyAgICBpbnQgZmluZExlbmd0aCA9IHN0
cmxlbihmaW5kKTsKKyAgICBpZiAoZmluZExlbmd0aCA9PSAwKQorICAgICAgICByZXR1cm4gY29u
c3RfY2FzdDxjaGFyKj4oYnVmZmVyKTsKKyAgICBmb3IgKGNvbnN0IGNoYXIqIHN0YXJ0ID0gYnVm
ZmVyOyAqc3RhcnQgJiYgc3RhcnQgKyBmaW5kTGVuZ3RoIDw9IGJ1ZmZlciArIGJ1ZmZlckxlbmd0
aDsgc3RhcnQrKykgeworICAgICAgICBpZiAoKnN0YXJ0ID09ICpmaW5kICYmIHN0cm5jbXAoc3Rh
cnQsIGZpbmQsIGZpbmRMZW5ndGgpID09IDApCisgICAgICAgICAgICByZXR1cm4gY29uc3RfY2Fz
dDxjaGFyKj4oc3RhcnQpOworICAgIH0KKyAgICByZXR1cm4gMDsKK30KKworI2VuZGlmCisKICNl
bmRpZiAvLyBXVEZfU3RyaW5nRXh0cmFzX2g=
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>38958</attachid>
            <date>2009-09-02 18:28:14 -0700</date>
            <delta_ts>2009-09-03 02:38:07 -0700</delta_ts>
            <desc>Add strnstr for Linux and Windows in StringExtras.h</desc>
            <filename>bug-28901-20090903102812.patch</filename>
            <type>text/plain</type>
            <size>1380</size>
            <attacher name="Fumitoshi Ukai">ukai</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZyBiL0phdmFTY3JpcHRDb3JlL0No
YW5nZUxvZwppbmRleCAwMzY4OGJlLi4wYzk0OTMyIDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS9DaGFuZ2VMb2cKKysrIGIvSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTMg
QEAKKzIwMDktMDktMDIgIEZ1bWl0b3NoaSBVa2FpICA8dWthaUBjaHJvbWl1bS5vcmc+CisKKyAg
ICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgQWRkIHN0cm5zdHIg
Zm9yIExpbnV4IGFuZCBXaW5kb3dzIGluIFN0cmluZ0V4dHJhcy5oCisgICAgICAgIGh0dHBzOi8v
YnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yODkwMQorCisgICAgICAgICogd3RmL1N0
cmluZ0V4dHJhcy5oOgorICAgICAgICAoc3RybnN0cik6CisKIDIwMDktMDktMDIgIEdhdmluIEJh
cnJhY2xvdWdoICA8YmFycmFjbG91Z2hAYXBwbGUuY29tPgogCiAgICAgICAgIFNob3VsZCBjcmFz
aCBpZiBKSVQgY29kZSBidWZmZXIgYWxsb2NhdGlvbiBmYWlscy4KZGlmZiAtLWdpdCBhL0phdmFT
Y3JpcHRDb3JlL3d0Zi9TdHJpbmdFeHRyYXMuaCBiL0phdmFTY3JpcHRDb3JlL3d0Zi9TdHJpbmdF
eHRyYXMuaAppbmRleCAxYzIzMzkwLi41NTllM2YyIDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS93dGYvU3RyaW5nRXh0cmFzLmgKKysrIGIvSmF2YVNjcmlwdENvcmUvd3RmL1N0cmluZ0V4dHJh
cy5oCkBAIC04NSw0ICs4NSwyMCBAQCBpbmxpbmUgaW50IHN0cmNhc2VjbXAoY29uc3QgY2hhciog
czEsIGNvbnN0IGNoYXIqIHMyKQogCiAjZW5kaWYKIAorI2lmIFBMQVRGT1JNKFdJTl9PUykgfHwg
UExBVEZPUk0oTElOVVgpCisKK2lubGluZSBjaGFyKiBzdHJuc3RyKGNvbnN0IGNoYXIqIGJ1ZmZl
ciwgY29uc3QgY2hhciogdGFyZ2V0LCBzaXplX3QgYnVmZmVyTGVuZ3RoKQoreworICAgIHNpemVf
dCB0YXJnZXRMZW5ndGggPSBzdHJsZW4odGFyZ2V0KTsKKyAgICBpZiAodGFyZ2V0TGVuZ3RoID09
IDApCisgICAgICAgIHJldHVybiBjb25zdF9jYXN0PGNoYXIqPihidWZmZXIpOworICAgIGZvciAo
Y29uc3QgY2hhciogc3RhcnQgPSBidWZmZXI7ICpzdGFydCAmJiBzdGFydCArIHRhcmdldExlbmd0
aCA8PSBidWZmZXIgKyBidWZmZXJMZW5ndGg7IHN0YXJ0KyspIHsKKyAgICAgICAgaWYgKCpzdGFy
dCA9PSAqdGFyZ2V0ICYmIHN0cm5jbXAoc3RhcnQgKyAxLCB0YXJnZXQgKyAxLCB0YXJnZXRMZW5n
dGggLSAxKSA9PSAwKQorICAgICAgICAgICAgcmV0dXJuIGNvbnN0X2Nhc3Q8Y2hhcio+KHN0YXJ0
KTsKKyAgICB9CisgICAgcmV0dXJuIDA7Cit9CisKKyNlbmRpZgorCiAjZW5kaWYgLy8gV1RGX1N0
cmluZ0V4dHJhc19o
</data>

          </attachment>
      

    </bug>

</bugzilla>