summary refs log tree commit diff
path: root/edit.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-02-15 18:53:06 -0500
committerJune McEnroe <june@causal.agency>2021-02-15 19:15:38 -0500
commit3b9e778dacd3392fdf2e8fc29e726b401b50abfe (patch)
treea24ce0c471586eae197090239fba7f3b3535a712 /edit.c
parentDon't expand macro if it can't be converted to mbs (diff)
downloadcatgirl-3b9e778dacd3392fdf2e8fc29e726b401b50abfe.tar.gz
catgirl-3b9e778dacd3392fdf2e8fc29e726b401b50abfe.zip
Don't insert wchar_t if it can't be converted to mbs
Otherwise it could hit the assertion in editBuffer while converting
to mbs for consumption by the rest of the program.

It's possibly to trigger this with LC_ALL=C and typing C-z C-v M-a,
for example.
Diffstat (limited to 'edit.c')
-rw-r--r--edit.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/edit.c b/edit.c
index fc23c58..3e7e1af 100644
--- a/edit.c
+++ b/edit.c
@@ -260,6 +260,8 @@ void edit(uint id, enum Edit op, wchar_t ch) {
 		}
 
 		break; case EditInsert: {
+			char mb[MB_LEN_MAX];
+			if (wctomb(mb, ch) < 0) return;
 			if (reserve(pos, 1)) {
 				buf[pos++] = ch;
 			}