From f3b502ba585d332f4ea7dd98c918f7b8b79d9c59 Mon Sep 17 00:00:00 2001 From: Henning Pohl Date: Wed, 19 Jun 2013 16:42:31 +0200 Subject: [PATCH] fix issue 10359 - Pointer slicing allowed in @safe mode --- src/expression.c | 2 ++ test/fail_compilation/diag10359.d | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 test/fail_compilation/diag10359.d diff --git a/src/expression.c b/src/expression.c index c652ac9705..744559e084 100644 --- a/src/expression.c +++ b/src/expression.c @@ -9848,6 +9848,8 @@ Lagain: { error("need upper and lower bound to slice pointer"); return new ErrorExp(); } + if (sc->func && !sc->intypeof && sc->func->setUnsafe()) + error("pointer slicing not allowed in safe functions"); } else if (t->ty == Tarray) { diff --git a/test/fail_compilation/diag10359.d b/test/fail_compilation/diag10359.d new file mode 100644 index 0000000000..142cec98e0 --- /dev/null +++ b/test/fail_compilation/diag10359.d @@ -0,0 +1,11 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/diag10359.d(10): Error: pointer slicing not allowed in safe functions +--- +*/ + +void foo(int* p) @safe +{ + auto a = p[0 .. 10]; +}