summary refs log tree commit diff
path: root/pls.c
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 /pls.c
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;
 }
 
7036e9fbb00&follow=1'>Rewrite install script yet againJune McEnroe 2020-09-11Remove NetBSD from install scriptJune McEnroe I never use it. 2020-09-11Use MacPorts rather than pkgsrcJune McEnroe My system is probably such a mess now... 2020-09-11Add debian VM name to sshJune McEnroe 2020-09-11Add influencer tweetJune McEnroe 2020-09-10Add The Kingdom of GodsJune McEnroe Reading has really slowed down :( 2020-09-07Add SunglassesJune McEnroe An IRC find. 2020-09-06Add Between the BreathsJune McEnroe One of those good songs from a soundtrack of a film that probably isn't? The summary sounds a lot more interesting than the title implies, at least. 2020-09-04Open /dev/tty in nudgeJune McEnroe This makes it work even when it's run connected to a pipe, i.e. as the notify command of catgirl... 2020-09-04Add nudgeJune McEnroe 2020-09-03Build fbclock with -lzJune McEnroe I guess this got lost somewhere, long ago... 2020-08-29Add tweets from retweetsJune McEnroe