Skip to content

Commit

Permalink
Merge pull request #5877 from WalterBright/fix15704
Browse files Browse the repository at this point in the history
fix Issue 15704 - @safe code should not allow copying to/from void[]
  • Loading branch information
yebblies authored Jun 21, 2016
2 parents 077a2d7 + 378e6e3 commit 8ed6966
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -13394,6 +13394,14 @@ extern (C++) class AssignExp : BinExp
else
e2x = e2x.implicitCastTo(sc, e1.type);
}
if (t1n.toBasetype.ty == Tvoid && t2n.toBasetype.ty == Tvoid)
{
if (!sc.intypeof && sc.func && sc.func.setUnsafe())
{
error("cannot copy void[] to void[] in @safe code");
return new ErrorExp();
}
}
}
else
{
Expand Down
17 changes: 17 additions & 0 deletions test/fail_compilation/test15704.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* TEST_OUTPUT:
---
fail_compilation/test15704.d(15): Error: cannot copy void[] to void[] in @safe code
---
*/

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

void main() @safe {
Object[] objs = [ new Object() ];
void[] arr1 = objs;
void[] arr2 = [ 123, 345, 567 ];

arr1[] = arr2[]; // overwrites pointers with arbitrary ints
}

0 comments on commit 8ed6966

Please sign in to comment.