writing to closed stdout (I)
kdevel
kdevel at vogtner.de
Sun Dec 15 21:35:13 UTC 2024
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 at std/stdio.d(3144): Attempting to write to closed
File
```
More information about the Digitalmars-d
mailing list