www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6473] New: segfault in Lexer::uniqueId

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6473

           Summary: segfault in Lexer::uniqueId
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



struct Eins
{
    ~this() {}
}

struct Zwei
{
    void build(Eins devices = Eins())
    {
    }
}

$ gdb --batch -ex "run program.d" -ex "bt 10" dmd
DMD v2.054 DEBUG

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff72e4893 in vfprintf () from /lib/x86_64-linux-gnu/libc.so.6




lexer.c:2881


sc=0x1128a70) at expression.c:3648

sc=0x1128a70) at declaration.c:1280

sc=0x1128670) at expression.c:4910

expression.c:5626

expression.c:5646

build as a free function doesn't trigger it.
Nor does a global 'Eins devices = Eins();'.


btw, lexer.c(2876):

Identifier *Lexer::uniqueId(const char *s, int num)
{   char buffer[32];
    size_t slen = strlen(s);

    assert(slen + sizeof(num) * 3 + 1 <= sizeof(buffer));
    sprintf(buffer, "%s%d", s, num);

Why that sizeof(num) there? It's always 4.
Why isn't snprintf(buffer, 32.... used?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6473


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|D1 & D2                     |D2
            Summary|segfault in Lexer::uniqueId |Stack overflow with struct
                   |                            |destructor as default
                   |                            |parameter



It's not a segfault, and it has nothing to do with Lexer::uniqueId.
It's a stack overflow. It's also D2-only, because it requires a struct
destructor.

StructLiteralExp::semantic() sees that Eins has a destructor, so it rewrites it
as
Eins devices = (Eins tmp = Eins(), tmp);
Then, it runs semantic on the comma expression it created.
VarDeclaration::semantic on tmp calls StructLiteralExp::semantic, which again
sees Eins has destructor, so it does an another rewrite.
Eins devices = (Eins tmp = (Eins tmp2 = Eins(), tmp2), tmp);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 19 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6473




Very interesting. Any idea how to solve it?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 18 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6473


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



https://github.com/D-Programming-Language/dmd/pull/575

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 22 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6473


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



https://github.com/D-Programming-Language/dmd/commit/4bda5de701e817b5ea4967fb311350e854a70dde

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 01 2012