Bug 9418 – Segmentation fault using only datetime and stdio.
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-28T13:40:00Z
Last change time
2013-02-06T00:48:42Z
Keywords
accepts-invalid, pull, wrong-code
Assigned to
nobody
Creator
knud
Comments
Comment #0 by knud — 2013-01-28T13:40:45Z
Here is a simple program which provoke a Segmentation fault on Linux.
#!/usr/bin/rdmd
import std.datetime;
import std.stdio;
void main()
{
auto today=~Clock.currTime().toISOString()[0..8];
writeln(today);
}
Comment #1 by andrej.mitrovich — 2013-02-05T08:54:30Z
How strange, what is the tilde operating on in this code? For example:
import std.datetime;
import std.stdio;
void main()
{
auto x1 = ~Clock; // NG
auto x2 = ~Clock.currTime(); // NG
auto x3 = ~Clock.currTime().toISOString(); // NG
auto x4 = Clock.currTime().toISOString()[0 .. 8];
auto x5 = ~x4; // NG
auto x5 = ~Clock.currTime().toISOString()[0 .. 8]; // works?!
}
Comment #2 by maxim — 2013-02-05T09:51:39Z
(In reply to comment #1)
> How strange, what is the tilde operating on in this code? For example:
Indeed this is strange.
> import std.datetime;
> import std.stdio;
>
> void main()
> {
> auto x1 = ~Clock; // NG
> auto x2 = ~Clock.currTime(); // NG
> auto x3 = ~Clock.currTime().toISOString(); // NG
> auto x4 = Clock.currTime().toISOString()[0 .. 8];
> auto x5 = ~x4; // NG
> auto x5 = ~Clock.currTime().toISOString()[0 .. 8]; // works?!
> }
Actually it operates on dynamic array honestly corrupting (complementing) both length and ptr properties.
import core.stdc.stdio : printf;
void main()
{
string foo = "foo";
printf(".length = %d, .ptr=%p\n", foo.length, foo.ptr);
foo = ~foo[] ;
printf(".length = %d, .ptr=%p\n", foo.length, foo.ptr);
}
My guess is that slice expression escapes internal dmd checks.
Comment #3 by k.hara.pg — 2013-02-05T23:22:36Z
(In reply to comment #2)
> My guess is that slice expression escapes internal dmd checks.
That is correct. At least, glue layer should reject such incorrect codegen.
https://github.com/D-Programming-Language/dmd/pull/1628
Comment #4 by github-bugzilla — 2013-02-06T00:47:22Z