[Issue 22828] New: Compiler allow offset a pointer with types of size greater than sizeof(T*)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 27 20:24:47 UTC 2022


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

          Issue ID: 22828
           Summary: Compiler allow offset a pointer with types of size
                    greater than sizeof(T*)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: contact at lsferreira.net

The compiler allows offset a pointer on -m32 with ulong type. This should be
illegal and doing so is dangerous, as overflow may happen. This pointer
arithmetic should also conform with IndexExpr behaviour described in the
language specification.

```d
int main() {
    int i;
    ulong len;
    *(&i + len) = 0; // ok
    (&i)[len] = 0;   // error

    return 0;
}
```

--


More information about the Digitalmars-d-bugs mailing list