www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21730] New: null ptr dereferenced in ChunksImpl.opApply

https://issues.dlang.org/show_bug.cgi?id=21730

          Issue ID: 21730
           Summary: null ptr dereferenced in ChunksImpl.opApply (SIGSEGV)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: kdevel vogtner.de

```three.d
import std.stdio;

void main ()
{
   auto err1 = File ("/tmp/err1.txt", "w+x");
   remove ("/tmp/err1.txt");
   err1.close;
   foreach (ubyte [] buf; chunks (err1, 4096))
      stderr.writeln (buf);
}
```

(gdb) r
[...]
Program received signal SIGSEGV, Segmentation fault.
0xXXXXXXXXXXXXXXXX in std.stdio.ChunksImpl() (this=..., dg=...)
    at [...]dmd2/linux/bin64/../../src/phobos/std/stdio.d:4711
4711            while ((r = trustedFread(f._p.handle, buffer)) > 0)
(gdb) p f
$1 = {_p = 0x0, _name = "/tmp/err1.txt"}

(related to Issue 21729)

--
Mar 18 2021