From c9d3fe11981aaf461ad95aa56a2671c101894012 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 25 Jul 2018 17:04:36 +0200 Subject: [PATCH] avoid UB by using + instead of array indexing Thanks gnzlbg --- ralf/_posts/2018-07-24-pointers-and-bytes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ralf/_posts/2018-07-24-pointers-and-bytes.md b/ralf/_posts/2018-07-24-pointers-and-bytes.md index 53daa57..85ba4aa 100644 --- a/ralf/_posts/2018-07-24-pointers-and-bytes.md +++ b/ralf/_posts/2018-07-24-pointers-and-bytes.md @@ -56,7 +56,7 @@ int test() { auto x = new int[8]; auto y = new int[8]; y[0] = 42; - auto x_ptr = &x[8]; // one past the end + auto x_ptr = x+8; // one past the end if (x_ptr == &y[0]) *x_ptr = 23; return y[0]; -- 2.30.2