Bug 7244 – Access Violation with optimized build when using memory-mapped file

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2012-01-07T19:53:00Z
Last change time
2016-08-27T22:31:50Z
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2012-01-07T19:53:30Z
I am *not* sure if the following code is correct, it's copied from another source and I've never used memory-mapped files before: module test; import std.algorithm; import std.mmfile; void readfile(string filename) { string[] lines; auto fFile = new MmFile(filename); auto fBuffer = cast(char*)(fFile[].ptr); auto fLength = cast(size_t)fFile.length; auto textData = fBuffer[0 .. fLength]; foreach (char[] line; splitter(textData, "\n")) lines ~= line.idup; } void main() { readfile("datetime.d"); } This only happens when reading large files like std.datetime: $ dmd test.d && test.exe ok $ dmd -O test.d && test.exe object.Error: Access Violation ---------------- ---------------- ddbg says: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at std.algorithm.find!(pred,ubyte[],ubyte[]).find D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d:2885 (0x00402b23) thread(2408) That's why I've labeled is as a Phobos bug. But maybe it's a bug in the user code?
Comment #1 by lovelydear — 2012-04-21T02:55:08Z
Note that this executes correctly (even with -O) when we replace "\n" (LF) by "\r\n" (CR+LF) under Windows: foreach (char[] line; splitter(textData, "\r\n")) lines ~= line.idup; Yet datetime.d is in Unix format according to my editor !
Comment #2 by lovelydear — 2012-04-21T06:28:21Z
See also issue 7689
Comment #3 by andrej.mitrovich — 2016-08-27T22:31:50Z
Works with latest DMD.