[前][次][番号順一覧][スレッド一覧]

ruby-changes:68790

From: Alan <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:34 +0900 (JST)
Subject: [ruby-changes:68790] 9ce2771697 (master): darray: fix strict aliasing issue

https://git.ruby-lang.org/ruby.git/commit/?id=9ce2771697

From 9ce27716972951ed610d048fbf42db9b1c9f42b4 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Fri, 19 Feb 2021 11:02:09 -0500
Subject: darray: fix strict aliasing issue

---
 darray.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/darray.h b/darray.h
index db69b71507..d3ffc88131 100644
--- a/darray.h
+++ b/darray.h
@@ -146,7 +146,9 @@ rb_darray_ensure_space(void *ptr_to_ary, size_t header_size, size_t element_size https://github.com/ruby/ruby/blob/trunk/darray.h#L146
 
     doubled_ary->capa = new_capa;
 
-    *ptr_to_ptr_to_meta = doubled_ary;
+    // We don't have access to the type of the dynamic array in function context.
+    // Write out result with memcpy to avoid strict aliasing issue.
+    memcpy(ptr_to_ary, &doubled_ary, sizeof(doubled_ary));
     return 1;
 }
 
@@ -167,7 +169,9 @@ rb_darray_make_impl(void *ptr_to_ary, int32_t array_size, size_t header_size, si https://github.com/ruby/ruby/blob/trunk/darray.h#L169
     meta->size = array_size;
     meta->capa = array_size;
 
-    *ptr_to_ptr_to_meta = meta;
+    // We don't have access to the type of the dynamic array in function context.
+    // Write out result with memcpy to avoid strict aliasing issue.
+    memcpy(ptr_to_ary, &meta, sizeof(meta));
     return 1;
 }
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]