shithub: sl

Download patch

ref: 52d518b5e346b66e9023ec35101480f706810977
parent: 4b8271cd44fd92d2580e9e2da23c5dcc85b1ffad
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jan 28 19:46:23 EST 2025

string-reverse: fix a crash on empty string

--- a/src/utf8.c
+++ b/src/utf8.c
@@ -285,6 +285,9 @@
 {
 	size_t si, di;
 
+	if(len == 0)
+		return 0;
+
 	dest[di = len] = '\0';
 	for(si = 0; si < len;){
 		switch((uint8_t)src[si]>>4){
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -510,5 +510,9 @@
 (assert (eq? 0 (string-length s 21 21)))
 (assert-fail (string-length s 21 22))
 
+(assert (equal? "акоп\0тевирп" (string-reverse s)))
+(assert (equal? "" (string-reverse "")))
+(assert (equal? "й" (string-reverse "й")))
+
 (princ "all tests pass")
 (newline)