digitalmars.D - Bug?
- Wulfklaue (17/33) Jun 01 2017 There does not seem to be a type check on calling the C printf...
- Nicholas Wilson (3/36) Jun 01 2017 you want issues.dlang.org
- Jonathan M Davis via Digitalmars-d (12/49) Jun 01 2017 You're literally calling C's printf here, so you're going to get the sam...
- Mike Parker (3/11) Jun 01 2017 That's not a crash. It's an exception. You can catch it and
Some C playing around:import core.stdc.stdio; void main() { int x = 5; printf("The action is:\n%s", x); }There does not seem to be a type check on calling the C printf... %s expects a string but entering the wrong type like a integer simply dumps down to this.The action is: object.Error (0): Access ViolationPlaying around a bit more and even D can be made to crash:import std.stdio : writefln; void main() { int x = 5; writefln("The action is:\n%i", x); }std.format.FormatException C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1744):Interesting ways to crash the code. I do not think this is expected behavior. :) And yes, i know that %i is not valid in this case but the fact that phobos simply crashes with a exception, no proper error warning ... If this error was somewhere in a large code base, it will be hard and time consuming to track down as the dumps do not show any trace / line error information. And side note: The first spot i look to report a bug, is on the DMD git repository ( and so do a lot of other people these days ). Do not even know where the bugs are reported here. Not very convenient.
Jun 01 2017
On Thursday, 1 June 2017 at 08:45:56 UTC, Wulfklaue wrote:Some C playing around:There is a check in LDC for that.import core.stdc.stdio; void main() { int x = 5; printf("The action is:\n%s", x); }There does not seem to be a type check on calling the C printf... %s expects a string but entering the wrong type like a integer simply dumps down to this.you want issues.dlang.orgThe action is: object.Error (0): Access ViolationPlaying around a bit more and even D can be made to crash:import std.stdio : writefln; void main() { int x = 5; writefln("The action is:\n%i", x); }std.format.FormatException C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1744):Interesting ways to crash the code. I do not think this is expected behavior. :) And yes, i know that %i is not valid in this case but the fact that phobos simply crashes with a exception, no proper error warning ... If this error was somewhere in a large code base, it will be hard and time consuming to track down as the dumps do not show any trace / line error information. And side note: The first spot i look to report a bug, is on the DMD git repository ( and so do a lot of other people these days ). Do not even know where the bugs are reported here. Not very convenient.
Jun 01 2017
On Thursday, June 01, 2017 08:45:56 Wulfklaue via Digitalmars-d wrote:Some C playing around:You're literally calling C's printf here, so you're going to get the same behavior as printf, and there is no type checking. If you want type checking, use writef or writefln.import core.stdc.stdio; void main() { int x = 5; printf("The action is:\n%s", x); }There does not seem to be a type check on calling the C printf... %s expects a string but entering the wrong type like a integer simply dumps down to this.The action is: object.Error (0): Access ViolationPlaying around a bit more and even D can be made to crash:\src\phobos\std\format.d(1744):import std.stdio : writefln; void main() { int x = 5; writefln("The action is:\n%i", x); }std.format.FormatException C:\D\dmd2\windows\bin\..\..Interesting ways to crash the code. I do not think this is expected behavior. :) And yes, i know that %i is not valid in this case but the fact that phobos simply crashes with a exception, no proper error warning ... If this error was somewhere in a large code base, it will be hard and time consuming to track down as the dumps do not show any trace / line error information. And side note: The first spot i look to report a bug, is on the DMD git repository ( and so do a lot of other people these days ). Do not even know where the bugs are reported here. Not very convenient.The format string is a runtime argument. Why would you expect a compile-time warning? If you want it to be tested at compile time, then pass the string as a compile-time argument. e.g. writefln!"The action is:\n%i"(x); and that will result in a static assertion failure. - Jonathan M Davis
Jun 01 2017
On Thursday, 1 June 2017 at 08:45:56 UTC, Wulfklaue wrote:Playing around a bit more and even D can be made to crash:That's not a crash. It's an exception. You can catch it and respond to it.import std.stdio : writefln; void main() { int x = 5; writefln("The action is:\n%i", x); }std.format.FormatException C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1744):
Jun 01 2017