summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib.c7
2 files changed, 8 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5d4c51f6..82b28fc1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2015-06-18 Kaz Kylheku <kaz@kylheku.com>
+ * lib.c (mkstring): Fix neglect to null terminate.
+
+2015-06-18 Kaz Kylheku <kaz@kylheku.com>
+
* lib.c (cat_str): Detect overflow in the total length
calculation.
diff --git a/lib.c b/lib.c
index 656c127e..0e8a15e1 100644
--- a/lib.c
+++ b/lib.c
@@ -2274,10 +2274,11 @@ val string_utf8(const char *str)
val mkstring(val len, val ch)
{
- size_t nchar = c_num(len) + 1;
- wchar_t *str = coerce(wchar_t *, chk_malloc(nchar * sizeof *str));
+ size_t l = c_num(len);
+ wchar_t *str = coerce(wchar_t *, chk_malloc((l + 1) * sizeof *str));
val s = string_own(str);
- wmemset(str, c_chr(ch), nchar);
+ wmemset(str, c_chr(ch), l);
+ str[l] = 0;
s->st.len = len;
s->st.alloc = plus(len, one);
return s;