From 2b1114c01474940c70196a3aa8bb88f9f546b71c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 5 Jun 2017 22:28:45 -0700 Subject: ffi: fix broken bchar array get. * lib.c (string_8bit_size): This function must allocate an extra wchar_t and null-terminate. That is the semantics expected by ffi_bchar_array_get which uses it, and of course string_own requires a null-terminated string. --- lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 3dd2c536..d43107a1 100644 --- a/lib.c +++ b/lib.c @@ -3307,9 +3307,10 @@ val string_8bit(const unsigned char *str) val string_8bit_size(const unsigned char *str, size_t sz) { size_t i; - wchar_t *wstr = chk_wmalloc(sz); + wchar_t *wstr = chk_wmalloc(sz + 1); for (i = 0; i < sz; i++) wstr[i] = str[i]; + wstr[i] = 0; return string_own(wstr); } -- cgit v1.2.3