-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heisenbug: deferred crash when writing to stdout on Windows without console. #9586
Labels
Comments
dlang-bugzilla (@CyberShadow) commented on 2011-11-02T14:40:04ZIt would help if you provided a stack trace. You can write a WinMain which displays uncaught exceptions in a message box:
http://www.digitalmars.com/d/2.0/windows.html
You may find this helpful:
if (!GetConsoleWindow()) {
stdout.open("stdout.log", "w");
stderr.open("stderr.log", "w");
} |
andy commented on 2015-01-25T18:06:20ZI test this, on windows, with DMD v2.066.1:
dmd -L/SUBSYSTEM:WINDOWS test.d
import std.stdio;
void main()
{
writ |
andy commented on 2015-01-25T18:10:51ZI test this, on windows, with DMD v2.066.1:
---- file test.d:
import std.stdio;
void main()
{
writeln("hello world");
}
comile:
dmd -L/SUBSYSTEM:WINDOWS test.d
ran it by dbl-clicking and from cmd.exe. No exception, no error.
I checked std/typecons.d and found no write's without debug.
Closing.
Please re-open if its still a problem, and please provide more specific steps to reproduce. "take tons of user feedback" doesn't help me fix the problem. |
verylonglogin.reg commented on 2015-01-25T18:28:43Z(In reply to AndyC from comment #3)
> I test this, on windows, with DMD v2.066.1:
>
> ---- file test.d:
> import std.stdio;
>
> void main()
> {
> writeln("hello world");
> }
>
>
> comile:
> dmd -L/SUBSYSTEM:WINDOWS test.d
>
> ran it by dbl-clicking and from cmd.exe. No exception, no error.
>
> I checked std/typecons.d and found no write's without debug.
>
> Closing.
>
> Please re-open if its still a problem, and please provide more specific
> steps to reproduce. "take tons of user feedback" doesn't help me fix the
> problem.
As I had written in the issue description it's a deffered failure (i.e. some buffer overflows). One can use any testcase which prints enough data to overflow the buffer, e.g.:
---
import std.stdio;
void main()
{
foreach(const i; 0 .. 100_000)
write("12345678"); // for me fails at i = 2048
}
--- |
andy commented on 2015-01-25T19:14:23ZConfirmed. Breaks for me to.
Do you know if there is a way to detect if a console exists? |
verylonglogin.reg commented on 2015-01-25T19:22:25Z(In reply to AndyC from comment #5)
> Confirmed. Breaks for me to.
>
> Do you know if there is a way to detect if a console exists?
This information alone doesn't give you much as e.g. a stream can be redirected.
Also I have already written all information I know about the issue here. |
dlang-bugzilla (@CyberShadow) commented on 2015-01-25T19:23:16ZYou can detect if your program is running in a console with:
GetConsoleWindow() != NULL
However, this is probably not what you want - instead you want to check if standard output is writable (you can probably create a GUI program and redirect its output somewhere, and the program will work fine). I'm not sure how to do that off the top of my head, though. |
dlang-bugzilla (@CyberShadow) commented on 2017-06-27T18:10:27ZAs I understand, what happens here is:
1. The program starts, and writes data to stdout / stderr
2. The data goes into the C FILE* buffer
3. When the buffer fills up, the C runtime attempts to flush it
4. Upon flushing, it discovers that the output handle in non-writable
Perhaps the runtime could detect an unwritable stdout/stderr and close (or otherwise make invalid) the respective std.stdio handles.
Though, even if writeln was changed to check if the output handle is writable on first or every write, the steps to reproduce would still apply - a forgotten writeln inside some rarely-executed code, such as an error handler, can still go through initial testing and end up crashing the application on the end-user's site. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
verylonglogin.reg (@denis-sh) reported this on 2011-11-02T06:42:48Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=6880
CC List
Description
The text was updated successfully, but these errors were encountered: