Skip to content

Commit

Permalink
Fix Bugzilla 20872 - std.array.assocArray trusts user-provided 'front…
Browse files Browse the repository at this point in the history
…' for values
  • Loading branch information
ntrel committed Jul 31, 2024
1 parent c00a5ee commit b9dae66
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ if (isInputRange!Values && isInputRange!Keys)
alias ValueElement = ElementType!Values;
static if (hasElaborateDestructor!ValueElement)
ValueElement.init.__xdtor();
cast(void) values.front;
})))
{
() @trusted {
Expand Down Expand Up @@ -790,6 +791,20 @@ if (isInputRange!Values && isInputRange!Keys)
assert(assocArray(1.iota, [UnsafeElement()]) == [0: UnsafeElement()]);
}

@safe unittest
{
struct ValueRange
{
string front () const @system { int* ptr = cast(int*)42; *ptr = 42; return null; }
@safe:
void popFront() {}
bool empty() const { return false; }
}
int[] keys;
ValueRange values;
static assert(!__traits(compiles, assocArray(keys, values)));
}

/**
Construct a range iterating over an associative array by key/value tuples.
Expand Down

0 comments on commit b9dae66

Please sign in to comment.