From 105ed11b305b3208e37cf48f21812ef1e187d6f5 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 31 Mar 2020 19:23:37 -0400 Subject: [PATCH] fix struct tail initialization for inline reference allocation (#35291) --- src/datatype.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/datatype.c b/src/datatype.c index 89ae943d835ae..15bdb8e6aa464 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -887,19 +887,10 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...) static void init_struct_tail(jl_datatype_t *type, jl_value_t *jv, size_t na) { - size_t nf = jl_datatype_nfields(type); - char *data = (char*)jl_data_ptr(jv); - for (size_t i = na; i < nf; i++) { - if (jl_field_isptr(type, i)) { - *(jl_value_t**)(data + jl_field_offset(type, i)) = NULL; - } - else { - jl_value_t *ft = jl_field_type(type, i); - if (jl_is_uniontype(ft)) { - uint8_t *psel = &((uint8_t *)data)[jl_field_offset(type, i) + jl_field_size(type, i) - 1]; - *psel = 0; - } - } + if (na < jl_datatype_nfields(type)) { + char *data = (char*)jl_data_ptr(jv); + size_t offs = jl_field_offset(type, na); + memset(data + offs, 0, jl_datatype_size(type) - offs); } }