shithub: sl

Download patch

ref: ed1b3e1835f90a829efda23d77117a8f7c3295b0
parent: 9624f24595330a68be064b99a7ef055ec6b6ad5e
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Apr 20 02:47:36 EDT 2025

u8_strwidth: do not go over the string size

--- a/src/utf8.c
+++ b/src/utf8.c
@@ -75,7 +75,10 @@
 
 	assert(n >= 0);
 	for(i = w = 0; i < n;){
-		i += chartorune(&r, s+i);
+		if(!fullrune(s+i, n-i))
+			return -1;
+		else
+			i += chartorune(&r, s+i);
 		ssize x = sl_wcwidth(r);
 		if(x < 0)
 			return -1;