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;
 }
 
/commit/catgirl.1?h=2.1&id=31a2af0c65c492b7e8ab6efaf4162aeaeb716e7f&follow=1'>Clarify /window documentationJune McEnroe 2019-02-23Use first word of params in input commandsJune McEnroe 2019-02-23Add C-n and C-p key bindings to switch windowsJune McEnroe 2019-02-23Change example command to join #ascii.town on freenodeJune McEnroe 2019-02-23Call def_prog_mode after termNoFlowJune McEnroe 2019-02-22Move IRC formatting reset to C-sJune McEnroe 2019-02-22Disable terminal flow controlJune McEnroe 2019-02-22Bind up and down arrows to scrollJune McEnroe 2019-02-22Remove topic TODOJune McEnroe 2019-02-22Add /znc commandJune McEnroe 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe 2019-02-21Replace "view" with "window"June McEnroe 2019-02-21Remove ROT13June McEnroe 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe