From dd9ab5fc0b6c0b706288f8f5e20989b6e24921e9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 17 May 2022 20:52:44 -0700 Subject: ffi: bugfix: null terminated string as flexible member. * ffi.c (ffi_char_array_get, ffi_zchar_array_get, ffi_wchar_array_get, ffi_bchar_array_get): Rearrange so that we test for tft->null_term first, and not nelem == 0. If nelem happens to be zero, but we are supposed to decode a null-terminated string, we will do the wrong thing and return the null string. (ffi_varray_in): The body can't be conditional on vec being non-nil, because then we do nothing if we don't have a Lisp object, which means we skip the cases when we should decode a null-terminated array. Now if vec is nil, we must guard against calling ffi_varray_dynsize. --- tests/017/ffi-misc.tl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/017/ffi-misc.tl') diff --git a/tests/017/ffi-misc.tl b/tests/017/ffi-misc.tl index 7053f78e..d0785513 100644 --- a/tests/017/ffi-misc.tl +++ b/tests/017/ffi-misc.tl @@ -88,3 +88,9 @@ (copy-cptr (cptr-int 3)) "#" (copy (cptr-int 3)) "#" (copy-cptr 3) :error) + +(ffi (struct flex (x char) (y (zarray char)))) + +(mtest + (ffi-put (new flex x #\a y "bcd") (ffi (struct flex))) #b'6100000062636400' + (ffi-get #b'6100000062636400' (ffi (struct flex))) #S(flex x #\a y "bcd")) -- cgit v1.2.3