Skip to content

Commit acb7fc3

Browse files
JeffBezansonstaticfloat
authored andcommitted
fix struct tail initialization for inline reference allocation (#35291)
1 parent 1a8d57a commit acb7fc3

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/datatype.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -887,19 +887,10 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
887887

888888
static void init_struct_tail(jl_datatype_t *type, jl_value_t *jv, size_t na)
889889
{
890-
size_t nf = jl_datatype_nfields(type);
891-
char *data = (char*)jl_data_ptr(jv);
892-
for (size_t i = na; i < nf; i++) {
893-
if (jl_field_isptr(type, i)) {
894-
*(jl_value_t**)(data + jl_field_offset(type, i)) = NULL;
895-
}
896-
else {
897-
jl_value_t *ft = jl_field_type(type, i);
898-
if (jl_is_uniontype(ft)) {
899-
uint8_t *psel = &((uint8_t *)data)[jl_field_offset(type, i) + jl_field_size(type, i) - 1];
900-
*psel = 0;
901-
}
902-
}
890+
if (na < jl_datatype_nfields(type)) {
891+
char *data = (char*)jl_data_ptr(jv);
892+
size_t offs = jl_field_offset(type, na);
893+
memset(data + offs, 0, jl_datatype_size(type) - offs);
903894
}
904895
}
905896

0 commit comments

Comments
 (0)