summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-06-05 22:28:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-06-05 22:28:45 -0700
commit2b1114c01474940c70196a3aa8bb88f9f546b71c (patch)
tree625ee5be6165cfe32ee83eb531690f7e25665937
parent33a5096c9d4659e870a9869b2a5a280281a06d3b (diff)
downloadtxr-2b1114c01474940c70196a3aa8bb88f9f546b71c.tar.gz
txr-2b1114c01474940c70196a3aa8bb88f9f546b71c.tar.bz2
txr-2b1114c01474940c70196a3aa8bb88f9f546b71c.zip
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.
-rw-r--r--lib.c3
1 files changed, 2 insertions, 1 deletions
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);
}