From 4cb7a078887e649221a164f77262a92f23c39ee5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 Apr 2017 06:12:13 -0700 Subject: ffi: use chk_calloc for txr_ffi_type. Let's defend against uninitialized struct member bugs over this type which has grown somewhat complicated. * ffi.c (make_ffi_type_struct): Use chk_calloc for tft. (make_ffi_type_array): Likewise, and remove a couple of explicit zero initializations. --- ffi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ffi.c b/ffi.c index 8af0e554..f4062eb7 100644 --- a/ffi.c +++ b/ffi.c @@ -890,7 +890,7 @@ static val make_ffi_type_struct(val syntax, val lisp_type, val slots, val types) { struct txr_ffi_type *tft = coerce(struct txr_ffi_type *, - chk_malloc(sizeof *tft)); + chk_calloc(1, sizeof *tft)); ffi_type *ft = coerce(ffi_type *, chk_calloc(1, sizeof *ft)); cnum nmemb = c_num(length(types)), i; @@ -944,7 +944,7 @@ static val make_ffi_type_array(val syntax, val lisp_type, val dim, val eltypes) { struct txr_ffi_type *tft = coerce(struct txr_ffi_type *, - chk_malloc(sizeof *tft)); + chk_calloc(1, sizeof *tft)); ffi_type *ft = coerce(ffi_type *, chk_calloc(1, sizeof *ft)); cnum nelem = c_num(dim), i; @@ -965,8 +965,6 @@ static val make_ffi_type_array(val syntax, val lisp_type, tft->alloc = ffi_fixed_alloc; tft->free = free; tft->fill = ffi_array_fill; - tft->size = 0; - tft->align = 0; for (i = 0; i < nelem; i++) { val eltype = pop(&eltypes); -- cgit v1.2.3