Skip to content

Commit

Permalink
darray: fix strict aliasing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
XrXr committed Feb 19, 2021
1 parent 7d2ea80 commit c544c3a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions darray.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit c544c3a

Please sign in to comment.