[Issue 23813] New: DIP1000 can introduce memory corruption in @safe function with typesafe variadics

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 28 15:01:49 UTC 2023


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

          Issue ID: 23813
           Summary: DIP1000 can introduce memory corruption in @safe
                    function with typesafe variadics
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kinke at gmx.net

With DMD v2.102:

```
auto foo(scope int[] i...) @safe {
    return () {
        import core.stdc.stdio;
        foreach (j; i)
            printf("%d\n", j);
    };
}

auto bar() @safe {
    return foo([1, 2, 3, 4, 5, 6]);
}

void main() {
    auto dg = bar();
    dg();
}
```

This works 'fine' without `-dip1000`. With DIP1000, it prints garbage (array
literal allocated on the stack then). It ultimately boils down to the `scope`
violation in `foo` not being detected.

Related to https://issues.dlang.org/show_bug.cgi?id=23440.

--


More information about the Digitalmars-d-bugs mailing list