Bug 8068 – Segmentation fault in std.string.format()

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-05-08T11:28:00Z
Last change time
2014-09-12T18:56:08Z
Assigned to
nobody
Creator
sebas.sir

Comments

Comment #0 by sebas.sir — 2012-05-08T11:28:01Z
This segmentation fault happens when format is called with 6 consecutive numbers followed by an string. It only occurs on 64bit platforms, on 32 it works as expected. The minimal example is as follows: 1 import std.string; 2 import std.stdio; 3 4 void main() { 5 string a = format("%d %d %d %d %d %d %s", 1,2,3,4,5,6,"string"); 6 writeln(a); 7 } 8 Regards! Pablo
Comment #1 by acehreli — 2012-05-17T22:55:43Z
With dmd 2.059 64-bit, I get a "segmentation fault" even though none of the format() calls have 6 items. There are three layers of structs in the following code: Outer, Inner, InnerMost: import std.stdio; import std.string; struct InnerMost { int m0; int m1; string toString() { return format("%s %s", m0, m1); } } struct Inner { string m0; int m1; InnerMost m2; InnerMost m3; string toString() const { return format("%s %s %s %s", m0, m1, m2, m3); } } struct Outer { Inner m0; string toString() const { return format("%s", m0); } } void main() { auto im0 = InnerMost(0, 0); auto im1 = InnerMost(1, 1); auto i = Inner("hello", 42, im0, im1); auto o = Outer(i); o.toString(); } When built with -m32, there is no bug. Also, when I replace the first two lines of main with the default initializations: auto im0 = InnerMost(); auto im1 = InnerMost(); This time I get "null this" similar to bug 6576. Ali
Comment #2 by verylonglogin.reg — 2013-11-07T08:52:38Z
And why is it a druntime bug? Looks more like a dmd codegen one.
Comment #3 by bugzilla — 2013-11-07T15:48:30Z
(In reply to comment #2) > And why is it a druntime bug? Looks more like a dmd codegen one. Yes, it smells like a codegen bug.
Comment #4 by hsteoh — 2014-09-12T18:55:33Z
Unable to reproduce bug in git HEAD (Linux/x86_64), for both code examples (including the 3rd variant). Perhaps the codegen bug has been fixed since?
Comment #5 by hsteoh — 2014-09-12T18:56:08Z
Please reopen if this problem crops up again.