shithub: femtolisp

Download patch

ref: 3581e6f7261122ff2176bbcac7f792758ac4d144
parent: d80ec38b8db4759c447b546b689d46de22c2e501
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Jan 5 22:46:53 EST 2025

mptoa: unconfuse clang-analyzer

--- a/3rd/mp/mpfmt.c
+++ b/3rd/mp/mpfmt.c
@@ -32,7 +32,7 @@
 	return 0;
 }
 
-static char*
+static char *
 modbillion(int rem, uint32_t r, char *out, char *buf)
 {
 	uint32_t rr;
@@ -134,15 +134,16 @@
 	return 0;
 }
 
-char*
+char *
 mptoa(mpint *b, int base, char *buf, int len)
 {
+	bool alloced;
 	char *out;
-	int rv, alloced;
+	int rv;
 
 	if(base == 0)
 		base = 16;	/* default */
-	alloced = 0;
+	alloced = false;
 	if(buf == nil){
 		/* rv <= log₂(base) */
 		for(rv=1; (base >> rv) > 1; rv++)
@@ -151,11 +152,11 @@
 		buf = MEM_ALLOC(len);
 		if(buf == nil)
 			return nil;
-		alloced = 1;
+		alloced = true;
 	}
 
 	if(len < 2)
-		return nil;
+		goto leave;
 
 	out = buf;
 	if(b->sign < 0){
@@ -183,6 +184,7 @@
 		exit(2);
 	}
 	if(rv < 0){
+leave:
 		if(alloced)
 			MEM_FREE(buf);
 		return nil;