Skip to content

Commit c544c3a

Browse files
committed
darray: fix strict aliasing issue
1 parent 7d2ea80 commit c544c3a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

darray.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ rb_darray_ensure_space(void *ptr_to_ary, size_t header_size, size_t element_size
146146

147147
doubled_ary->capa = new_capa;
148148

149-
*ptr_to_ptr_to_meta = doubled_ary;
149+
// We don't have access to the type of the dynamic array in function context.
150+
// Write out result with memcpy to avoid strict aliasing issue.
151+
memcpy(ptr_to_ary, &doubled_ary, sizeof(doubled_ary));
150152
return 1;
151153
}
152154

@@ -167,7 +169,9 @@ rb_darray_make_impl(void *ptr_to_ary, int32_t array_size, size_t header_size, si
167169
meta->size = array_size;
168170
meta->capa = array_size;
169171

170-
*ptr_to_ptr_to_meta = meta;
172+
// We don't have access to the type of the dynamic array in function context.
173+
// Write out result with memcpy to avoid strict aliasing issue.
174+
memcpy(ptr_to_ary, &meta, sizeof(meta));
171175
return 1;
172176
}
173177

0 commit comments

Comments
 (0)