From 1b891820b5b1e4ed35b87b3c0a040fd289e95801 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 29 May 2017 18:25:28 -0700 Subject: ffi: pad retval to ffi_arg size on all platforms. * ffi.c (pad_retval): Define same way regardless of big or little endian. For instance, we don't want to call alloca(1) for a char return value. It could be the case on little endian targets that libffi prepares an entire ffi_arg return value. Even though we just read the low order byte, we still have to prepare enough space for the whole thing. --- ffi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'ffi.c') diff --git a/ffi.c b/ffi.c index e6d22814..55f58c01 100644 --- a/ffi.c +++ b/ffi.c @@ -62,18 +62,19 @@ #define alignof(type) offsetof(struct {char x; type y;}, y) +#define pad_retval(size) ((size) > sizeof (ffi_arg) \ + ? (size) \ + : sizeof (ffi_arg)) + #if HAVE_LITTLE_ENDIAN -#define pad_retval(size) (size) #define ifbe(expr) (0) #define ifbe2(expr1, expr2) (expr2) #else -#define pad_retval(size) ((size) > sizeof (ffi_arg) \ - ? (size) \ - : sizeof (ffi_arg)) #define ifbe(expr) (expr) #define ifbe2(expr1, expr2) (expr1) #endif + val uint8_s, int8_s; val uint16_s, int16_s; val uint32_s, int32_s; -- cgit v1.2.3