Bug 22828 – Compiler allow offset a pointer with types of size greater than sizeof(T*)

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-02-27T20:24:47Z
Last change time
2024-12-13T19:21:14Z
Keywords
pull
Assigned to
No Owner
Creator
Luís Ferreira
Moved to GitHub: dmd#20062 →

Comments

Comment #0 by contact — 2022-02-27T20:24:47Z
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; } ```
Comment #1 by dlang-bot — 2022-02-27T21:49:34Z
@ljmf00 created dlang/dmd pull request #13732 "Fix issue 22828: dcast: use an implicit cast instead of explicit" fixing this issue: - Fix issue 22828: dcast: use an implicit cast instead of explicit Signed-off-by: Luís Ferreira <[email protected]> https://github.com/dlang/dmd/pull/13732
Comment #2 by razvan.nitu1305 — 2022-02-28T10:57:23Z
What is the basis of your assumption that this should be illegal? You are doing pointer arithmetic in @System code, it is not the job of the compiler to prevent you from doing something like this. I don't think the bug report is valid.
Comment #3 by robert.schadek — 2024-12-13T19:21:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20062 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB