diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-02-19 11:02:09 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:30 -0400 |
commit | 9ce27716972951ed610d048fbf42db9b1c9f42b4 (patch) | |
tree | e763995451110d1f80c4ae0d1229de15732eb838 /darray.h | |
parent | 0658ab73eed9bb5b0a867424492a51120c83de41 (diff) | |
download | ruby-9ce27716972951ed610d048fbf42db9b1c9f42b4.tar.gz |
darray: fix strict aliasing issue
Diffstat (limited to 'darray.h')
-rw-r--r-- | darray.h | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -146,7 +146,9 @@ rb_darray_ensure_space(void *ptr_to_ary, size_t header_size, size_t element_size 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 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; } |