shithub: sl

Download patch

ref: ab09c60230b5e4ae63e3ff3c0e813dfe0409cddc
parent: e404c758ba24065c606359e8fc061ca144f2bf20
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Apr 7 23:55:24 EDT 2025

don't crash on (rune "")

--- a/src/cvalues.c
+++ b/src/cvalues.c
@@ -198,7 +198,7 @@
 	else if(isrune(a))
 		r = torune(a);
 	else if(iscvalue(a))
-		r = conv_to_u32(a, cv_data(ptr(a)), T_BIGNUM);
+		r = conv_to_u32(a, cv_data(ptr(a)), cv_numtype(ptr(a)));
 	else if(isubnum(a)){
 		sl_fx v = ubnumval(a);
 		r = conv_to_u32(a, &v, ubnumtype(a));
@@ -379,7 +379,7 @@
 		mpfree(*s);
 }
 
-static sl_cvtable mp_vtable = { nil, nil, free_bignum, nil };
+static sl_cvtable bignum_vtable = { nil, nil, free_bignum, nil };
 
 sl_constfn
 sl_v
@@ -1445,7 +1445,7 @@
 	ctor_cv_intern(bignum, T_BIGNUM, mpint*);
 	sl_bignumtype = get_type(sl_bignumsym);
 	sl_bignumtype->init = cvalue_bignum_init;
-	sl_bignumtype->vtable = &mp_vtable;
+	sl_bignumtype->vtable = &bignum_vtable;
 
 	unboxedtypes[T_S8] = sl_s8type;
 	unboxedtypes[T_U8] = sl_u8type;
--- a/test/unittest.sl
+++ b/test/unittest.sl
@@ -607,6 +607,8 @@
 (assert (equal? #\Dž (rune-titlecase #\DŽ)))
 (assert (rune-title-case? #\Dž))
 
+(assert-fail (rune ""))
+
 (def s "hello й goodbye")
 (assert (= 4 (str-find s #\o)))
 (assert (= 9 (str-find s #\o 5)))
--