[Issue 14643] New: Safety violation with final switch and void initializer

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 2 11:08:55 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14643

          Issue ID: 14643
           Summary: Safety violation with final switch and void
                    initializer
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: public at dicebot.lv

This compiles:

```
enum E
{
    A,
    B
}

int* foo() @safe
{
    E value = void;
    static int a, b;

    final switch (value)
    {
        case E.A: return &a;
        case E.B: return &b;
    }
}

void main() @safe
{
    *foo() = 43;
}
```

Throws core.exception.SwitchError in normal mode but crashes in release mode by
trying to write via garbage pointer.

--


More information about the Digitalmars-d-bugs mailing list