D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8068 - Segmentation fault in std.string.format()
Summary: Segmentation fault in std.string.format()
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-08 11:28 UTC by Pablo
Modified: 2014-09-12 18:56 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Pablo 2012-05-08 11:28:01 UTC
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 Ali Cehreli 2012-05-17 22:55:43 UTC
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 Denis Shelomovskii 2013-11-07 08:52:38 UTC
And why is it a druntime bug? Looks more like a dmd codegen one.
Comment 3 Walter Bright 2013-11-07 15:48:30 UTC
(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 hsteoh 2014-09-12 18:55:33 UTC
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 hsteoh 2014-09-12 18:56:08 UTC
Please reopen if this problem crops up again.