shithub: mc

Download patch

ref: 8e62e63f2e282f1b476d15c609d5f65525bca0cf
parent: 6b0a400370a39fdb924cb9172ef2241f7fc2a096
author: Ori Bernstein <[email protected]>
date: Thu Sep 11 20:51:51 EDT 2014

Fix buffer sizing for bigfmt.

    We were hitting the 1024 character limit and generating bad
    output.... oops.

--- a/libstd/bigint.myr
+++ b/libstd/bigint.myr
@@ -99,11 +99,21 @@
 }
 
 const bigfmt = {a
-	var buf : byte[1024]
+	var buf
 	var n
 
-	n = bigbfmt(buf[:], a)
-	-> sldup(buf[:n])
+ 	/*
+	allocate a buffer guaranteed to be big enough.
+	that's 
+		2 + floor(nbits/(log_2(10)))
+	or
+		2 + a.dig.len * 32/3.32...
+	or
+		2 + a.dig.len * 11
+	*/
+	buf = slalloc(2 + a.dig.len * 11)
+	n = bigbfmt(buf, a)
+	-> buf[:n]
 }
 
 /* for now, just dump out something for debugging... */