summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2019-04-05 08:58:22 +0200
committerEugen Wissner <belka@caraus.de>2019-04-05 08:58:22 +0200
commite6c6a2d21a6869bcfdf872479db566864a22f5fc (patch)
treed0b520486efcf3851dcb7236301929d80bd6b211 /source
parentd55eac3bace62774e730921f4544681f00db4fc2 (diff)
downloadtanya-e6c6a2d21a6869bcfdf872479db566864a22f5fc.tar.gz
Make Array.get system function
.get() returns a memory block that can be changed if the original array is manipulated after getting the slice. So the slice returned by .get() may allow access to invalid memory.
Diffstat (limited to 'source')
-rw-r--r--source/tanya/container/array.d21
1 files changed, 11 insertions, 10 deletions
diff --git a/source/tanya/container/array.d b/source/tanya/container/array.d
index 0afd2ac..704dc35 100644
--- a/source/tanya/container/array.d
+++ b/source/tanya/container/array.d
@@ -40,7 +40,8 @@ struct Range(A)
invariant (this.begin >= this.container.data);
invariant (this.end <= this.container.data + this.container.length);
- private this(ref A container, E* begin, E* end) @trusted
+ private this(return ref A container, return E* begin, return E* end)
+ @trusted
in (begin <= end)
in (begin >= container.data)
in (end <= container.data + container.length)
@@ -123,7 +124,7 @@ struct Range(A)
return typeof(return)(*this.container, this.begin + i, this.begin + j);
}
- inout(E)[] get() inout @trusted
+ inout(E)[] get() inout
{
return this.begin[0 .. length];
}
@@ -172,7 +173,7 @@ struct Array(T)
* init = Values to initialize the array with.
* allocator = Allocator.
*/
- this(R)(R init, shared Allocator allocator = defaultAllocator)
+ this(R)(scope R init, shared Allocator allocator = defaultAllocator)
if (!isInfinite!R
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
@@ -225,7 +226,7 @@ struct Array(T)
{
// Move each element.
reserve(init.length_);
- foreach (ref target; this.data[0 .. init.length_])
+ foreach (ref target; slice(init.length_))
{
moveEmplace(*init.data++, target);
}
@@ -660,7 +661,7 @@ struct Array(T)
}
/// ditto
- size_t insertBack(R)(R el)
+ size_t insertBack(R)(scope R el)
if (!isInfinite!R
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
@@ -739,7 +740,7 @@ struct Array(T)
*
* Precondition: $(D_PARAM r) refers to a region of $(D_KEYWORD this).
*/
- size_t insertAfter(R)(Range r, R el)
+ size_t insertAfter(R)(Range r, scope R el)
if (!isInfinite!R
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
@@ -788,7 +789,7 @@ struct Array(T)
}
/// ditto
- size_t insertBefore(R)(Range r, R el)
+ size_t insertBefore(R)(Range r, scope R el)
if (!isInfinite!R
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))
@@ -1255,13 +1256,13 @@ struct Array(T)
*
* Returns: The array with elements of this array.
*/
- inout(T[]) get() inout @trusted
+ inout(T[]) get() inout
{
return this.data[0 .. length];
}
///
- @nogc nothrow pure @safe unittest
+ @nogc nothrow pure @system unittest
{
auto v = Array!int([1, 2, 4]);
auto data = v.get();
@@ -1317,7 +1318,7 @@ struct Array(T)
*
* Returns: $(D_KEYWORD this).
*/
- ref typeof(this) opAssign(R)(R that)
+ ref typeof(this) opAssign(R)(scope R that)
if (!isInfinite!R
&& isInputRange!R
&& isImplicitlyConvertible!(ElementType!R, T))