summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-09-02 13:40:05 -0400
committerJune McEnroe <june@causal.agency>2018-09-02 13:45:00 -0400
commitc58baa84eee3b0d80b1ec62c57ba616da99e3125 (patch)
treea4d4807a2184526570a55ab6245957c823c536cd
parentTreat all direct messages as pings (diff)
downloadcatgirl-c58baa84eee3b0d80b1ec62c57ba616da99e3125.tar.gz
catgirl-c58baa84eee3b0d80b1ec62c57ba616da99e3125.zip
Write terminating null in allocating wcs/mbs conversions
Turns out wcsnrtombs doesn't.
Diffstat (limited to '')
-rw-r--r--pls.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/pls.c b/pls.c
index 9f6cb69..d91fc97 100644
--- a/pls.c
+++ b/pls.c
@@ -45,12 +45,13 @@ wchar_t *ambstowcs(const char *src) {
 	wchar_t *dst = malloc(sizeof(*dst) * (1 + len));
 	if (!dst) return NULL;
 
-	len = mbsrtowcs(dst, &src, 1 + len, NULL);
+	len = mbsrtowcs(dst, &src, len, NULL);
 	if (len == (size_t)-1) {
 		free(dst);
 		return NULL;
 	}
 
+	dst[len] = L'\0';
 	return dst;
 }
 
@@ -61,12 +62,13 @@ char *awcstombs(const wchar_t *src) {
 	char *dst = malloc(sizeof(*dst) * (1 + len));
 	if (!dst) return NULL;
 
-	len = wcsrtombs(dst, &src, 1 + len, NULL);
+	len = wcsrtombs(dst, &src, len, NULL);
 	if (len == (size_t)-1) {
 		free(dst);
 		return NULL;
 	}
 
+	dst[len] = '\0';
 	return dst;
 }
 
@@ -77,12 +79,13 @@ char *awcsntombs(const wchar_t *src, size_t nwc) {
 	char *dst = malloc(sizeof(*dst) * (1 + len));
 	if (!dst) return NULL;
 
-	len = wcsnrtombs(dst, &src, nwc, 1 + len, NULL);
+	len = wcsnrtombs(dst, &src, nwc, len, NULL);
 	if (len == (size_t)-1) {
 		free(dst);
 		return NULL;
 	}
 
+	dst[len] = '\0';
 	return dst;
 }
 
sal.agency/.gitignore?id=2edd4666909c4abd0bc62cd73eb5cdcda502fded&follow=1'>Ignore about-filterJune McEnroe 2019-12-19Fix matching make tags with no sourcesJune McEnroe 2019-12-19Avoid matching := assignments as tagsJune McEnroe 2019-12-18Hide line numbers when rendering mdocJune McEnroe Hack: output an extra <td> after rendering mdoc so that line numbers can be hidden based on there being three. This required splitting source-filter and about-filter since on about pages there is no table. 2019-12-18Customize cgit CSSJune McEnroe 2019-12-18Use :target rather than :focus pseudo-classJune McEnroe :target persists after you click on something else. 2019-12-18Copy cgit auxiliary binaries properlyJune McEnroe 2019-12-18Add git.causal.agency cgit configJune McEnroe 2019-12-18Bail from hi if input is binaryJune McEnroe NULs in the input cause an infinite loop in htmlEscape, not to mention regexes obviously not working, etc. 2019-12-16Post "cgit setup"June McEnroe