Bug 5802 – Pointer becoming invalid

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-03-30T21:56:00Z
Last change time
2011-03-31T07:11:27Z
Assigned to
nobody
Creator
Jesse.K.Phillips+D

Attachments

IDFilenameSummaryContent-TypeSize
936csv.dExample codetext/x-dsrc1602

Comments

Comment #0 by Jesse.K.Phillips+D — 2011-03-30T21:56:47Z
Created attachment 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
Comment #1 by braddr — 2011-03-30T22:27:12Z
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.
Comment #2 by Jesse.K.Phillips+D — 2011-03-31T07:11:27Z
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.