www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5802] New: Pointer becoming invalid

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5802

           Summary: Pointer becoming invalid
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com



21:56:47 PDT ---
Created an attachment (id=936)
Example code

I've been working toward a CSV parser that works efficiently with an input
range. I'm testing it with string and have come to the conclusion there is a
bug in DMD. But I'm having some issue with reducing this code further[1].

The issue manifests itself when I pass a string to a function, which is stored
in a range that produces a range that stores a pointer to the string, which
modifies the dereferenced string pointer.

The pointer is no longer valid by the time popFront is called. A segmentation
fault is produced on line 95 inside countUntil (the string is garbage).

1. https://gist.github.com/895807

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 30 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5802


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr puremagic.com



---
I haven't looked at this under a debugger, but what I suspect is happening is
this:

In csvText, you're creating a temporary RecordList which is copied on return if
NRVO isn't happening.  The pointer inside recordRange points to the temporary. 
After the copy, the temporary goes away and the pointer is invalid.

Test this by printing the address of RecordList._input inside the RecordList
ctor and again in RecordRange.front.  If I'm right, the two addresses will
differ and the pointer value inside recordRange._input will be the first value.

Assuming all of the above is right, the fix is to add a postblit to fix up the
pointer.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 30 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5802


Jesse Phillips <Jesse.K.Phillips+D gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



07:11:27 PDT ---
Oh, that makes sense. Adding a postblitz is providing a resolution to this
issue. My CSV parser is still segv, but it is in another location. I'll close
this as it obviously isn't a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 31 2011