<?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>11737</bug_id>
          
          <creation_ts>2006-12-01 15:41:17 -0800</creation_ts>
          <short_desc>Windows cookie code uses a reference to a destroyed temporary</short_desc>
          <delta_ts>2007-01-21 11:30:38 -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>New Bugs</component>
          <version>420+</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</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="Brett Wilson (Google)">brettw</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>43635</commentid>
    <comment_count>0</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2006-12-01 15:41:17 -0800</bug_when>
    <thetext>In CookieJarWin cookies() there is this great code:
    String&amp; result = String(buffer, count-1); // Ignore the null terminator.
    delete buffer;
    return result;

The fix is just:
    String result(buffer, count-1); // Ignore the null terminator.
    delete buffer;
    return result;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>43551</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-12-01 20:59:03 -0800</bug_when>
    <thetext>This temporary should not be destroyed too early, according to C++ standard 12.2.5: &quot;The temporary to which the reference is bound &lt;...&gt; persists for the lifetime of the reference except as specified below &lt;exceptions don&apos;t seem to apply to this case&gt;.&quot; Does MSVC destroy it too early?

However, there is another problem in this snippet - a temporary object cannot be bound to a non-const reference, so it should be:
    const String&amp; result = String(buffer, count-1); // Ignore the null terminator.
    delete[] buffer;
    return result;
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>43082</commentid>
    <comment_count>2</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2006-12-06 11:17:21 -0800</bug_when>
    <thetext>Maybe you&apos;re right. I saw a memory corruption problem in this code (if I go to nytimes.com with no cookies), changed this, and the problem went away. In the code produced in debug mode it seems to do the right thing, but the maybe it&apos;s an optimizer problem.

I think that this is potentially confusing even if it is correct and even if all compilers handle this case properly. The code I suggested produces exactly the same result in terms of objects and work and is super obvious.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>33924</commentid>
    <comment_count>3</comment_count>
    <who name="Brett Wilson (Google)">brettw</who>
    <bug_when>2007-01-21 11:30:38 -0800</bug_when>
    <thetext>Alexey is right. The crash I saw in this code was bug 12081.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>