Bug 20490 – malloc and calloc should be @safe / @trusted

Status
RESOLVED
Resolution
WONTFIX
Severity
minor
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-08T15:44:04Z
Last change time
2022-04-13T14:17:33Z
Keywords
pull
Assigned to
No Owner
Creator
Nathan S.

Comments

Comment #0 by n8sh.secondary — 2020-01-08T15:44:04Z
malloc and calloc should be @trusted because by specification they cannot corrupt memory regardless of what arguments they are passed. core.stdc.stdlib.d has this comment explaining why they aren't @trusted: // We don't mark these @trusted. Given that they return a void*, one has // to do a pointer cast to do anything sensible with the result. Thus, // functions using these already have to be @trusted, allowing them to // call @system stuff anyway. That comment is longer than just writing @trusted twice. Moreover since that comment was written Phobos has adopted the style of wrapping individual statements in @trusted lambdas instead of marking entire functions as @trusted.
Comment #1 by dlang-bot — 2020-01-08T15:49:38Z
@n8sh created dlang/druntime pull request #2901 "Fix Issue 20490 - malloc and free should be `@safe` / `@trusted`" fixing this issue: - Fix Issue 20490 - malloc and free should be `@safe` / `@trusted` There is no good reason not to annotate them correctly. https://github.com/dlang/druntime/pull/2901
Comment #2 by dkorpel — 2022-04-13T14:17:33Z