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
commitfa2318f5fb705f106bf251e2dd52f22c5c6bc5f4 (patch)
tree625ee5be6165cfe32ee83eb531690f7e25665937
parent43d1b6f69210064c4df8006c3a692d53e31fea64 (diff)
downloadtxr-fa2318f5fb705f106bf251e2dd52f22c5c6bc5f4.tar.gz
txr-fa2318f5fb705f106bf251e2dd52f22c5c6bc5f4.tar.bz2
txr-fa2318f5fb705f106bf251e2dd52f22c5c6bc5f4.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);
}