[Issue 17363] @safety hole due to $ caching in slice expressions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 11 05:16:10 UTC 2018


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Walter Bright <bugzilla at digitalmars.com> ---
I don't think there is a solution to this problem. Consider:

    a()[b($)..c($)]

where a, b, c are functions with side effects that change the length of the
array, and the calls to b and c depend on the $, the length of the array. Each
function can only be called once, because they have side effects.

In order to get $, a() has to be called. But b($) and c($) both change the
value of $, so no ordering is correct.

However, it is not memory unsafe, because reallocating the array is memory safe
even if other references to that array remain.

I'm marking this as INVALID because 1) there is no solution, cache or no cache,
and 2) it is not memory unsafe. It's just buggy code.

--


More information about the Digitalmars-d-bugs mailing list