Bug 2613 – The trivial hello.d sample program fails at execution
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-01-24T14:40:00Z
Last change time
2015-06-09T01:21:00Z
Assigned to
nobody
Creator
PhiBerthault
Comments
Comment #0 by PhiBerthault — 2009-01-24T14:40:25Z
The hello.d sample programs shows parasite characters when invoked.
The problem comes from missing nul terminating character in D strings.
The line:
printf("args[%d] = '%s'\n", i, cast(char *)args[i]);
must be rewritten as:
printf("args[%d] = '%.*s'\n", i, args[i]);
There is the same error in the unittest.d program in Phobos.
Comment #1 by smjg — 2009-01-25T16:25:25Z
Wrong again. It should be fixed to use writefln, in both the D1 and D2 packages. And probably have args declared as string[] rather than char[][].
----------
import std.stdio;
int main(string[] args)
{
writefln("hello world");
writefln("args.length = %d", args.length);
for (int i = 0; i < args.length; i++)
writefln("args[%d] = '%s'", i, args[i]);
return 0;
}
----------
Comment #2 by braddr — 2009-01-25T16:58:36Z
Walter, these sources don't seem to be part of either the phobos or druntime projects, so they must live along side the compiler itself. Over half of them use printf, and I'll bet that most could stand to be updated in one way or another. This applies to both 1.x and 2.x as well.
Comment #3 by cruxic — 2010-08-31T21:25:57Z
I'm seeing this problem in D2.0.48 although I only see the garbage characters on Windows. Is this stuff in version control? I'd be glad to rid all the sample programs of printf...
Comment #4 by dlang-bugzilla — 2011-08-24T13:30:36Z
This seems to have been fixed for a while now (hello.d uses writefln).