shithub: femtolisp

Download patch

ref: 88243e3e030745d238c7a3b22cebdea14be5eeb0
parent: 5df1e1690d92bbe74d89591bcb0c8f4841275bd3
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Nov 16 02:36:19 EST 2024

fl_read_numtok: simplify worst case, make sure there is no leak

--- a/read.c
+++ b/read.c
@@ -28,7 +28,6 @@
 	char *end;
 	int64_t i64;
 	double d;
-	mpint *mp;
 	if(*tok == '\0')
 		return false;
 	if(!((tok[0] == '0' && tok[1] == 'x') || (base >= 15)) && strpbrk(tok, ".eEpP")){
@@ -72,11 +71,11 @@
 		}
 	}
 	i64 = strtoll(tok, &end, base);
-	mp = fits_fixnum(i64) ? nil : strtomp(tok, &end, base, nil);
-	bool ok = *end == '\0';
-	if(pval)
-		*pval = mp == nil ? fixnum(i64) : mk_mpint(mp);
-	return ok;
+	if(*end != '\0')
+		return false;
+	if(pval != nil)
+		*pval = fits_fixnum(i64) ? fixnum(i64) : mk_mpint(strtomp(tok, &end, base, nil));
+	return true;
 }
 
 static char