www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - writing to closed stdout (I)

reply kdevel <kdevel vogtner.de> writes:
```d
void main ()
{
    import std.stdio;
    stdout.close;
    writeln ();
}
```

```sh
$ dmd stdoutclosedsegfault
$ ./stdoutclosedsegfault
Segmentation fault
```

Can or shall issues still be reported in bugzilla?
Dec 15
parent kdevel <kdevel vogtner.de> writes:
On Sunday, 15 December 2024 at 13:51:31 UTC, kdevel wrote:
 ```sh
 $ dmd stdoutclosedsegfault
 $ ./stdoutclosedsegfault
 Segmentation fault
 ```
``` --- ./src/phobos/std/stdio.d_ 2024-12-15 22:24:39.000000000 +0100 +++ ./src/phobos/std/stdio.d 2024-12-15 22:30:00.000000000 +0100 -4252,6 +4252,7 { import std.exception : enforce; + enforce(.trustedStdout.isOpen, "Attempting to writeln() to closed file"); enforce(fputc('\n', .trustedStdout._p.handle) != EOF, "fputc failed"); } else static if (T.length == 1 && ``` Im wondering, why `stdout.writeln ();` and `writeln ();` use different code. The former fragment will not segfault but throw ``` object.Exception std/stdio.d(3144): Attempting to write to closed File ```
Dec 15