[Issue 9195] New: Can do pointer arithmetic in safeD!

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 22 11:42:25 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9195

           Summary: Can do pointer arithmetic in safeD!
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2012-12-22 11:42:23 PST ---
Pointer arithmetic limitation is too dam easy to side step. In fact I did it
accidentaly.

The snippet shows the problem in its full glory:


@safe uint* glorious(uint * ptr, size_t offset)
{
    return &ptr[offset];
}

//correctly can't be @safe
/*@safe*/ @trusted uint* casual(uint * ptr, size_t offset)
{
    return ptr+offset;
}

@safe void main()
{
    uint[] arr = [1, 2, 3, 4];
    assert(*casual(arr.ptr, 3) == 4);
    assert(*glorious(arr.ptr, 3) == 4);
    assert(glorious(arr.ptr, 0xdead_beaf) == casual(arr.ptr, 0xdead_beaf));
}

This undermines the whole promise of memory safety in SafeD  - if you can index
raw pointers you no safer then with direct pointer arithmetic.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list