shithub: mc

Download patch

ref: 9bf446ab7795f7397bc4fb7ae9e46ce14c3f679c
parent: fd333ef7321e70c49b97d9ffb47805fe686e5d05
author: S. Gilles <sgilles@math.umd.edu>
date: Tue May 21 04:30:02 EDT 2019

Fix error message for {} without parameter

Move the nfmt > nvarargs check to where it can detect the imminent bad
access.

--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -181,9 +181,6 @@
 		match (state, (b : char))
 		/* raw bytes */
 		| (`Copy, '{'):
-			if nfmt > nvarargs
-				die("too few values for fmt\n")
-			;;
 			if (fmt[i] : char) == '{'
 				b = fmt[i++]
 				sbputb(sb, ('{' : byte))
@@ -217,8 +214,11 @@
 			if startp != nbuf
 				param[nparam++] = (buf[startp:nbuf], "")
 			;;
-			fmtval(sb, vatype(ap), ap, param[:nparam])
 			nfmt++
+			if nfmt > nvarargs
+				die("too few values for fmt\n")
+			;;
+			fmtval(sb, vatype(ap), ap, param[:nparam])
 		| (`ParamOpt, '\\'):
 			buf[nbuf++] = fmt[i++]
 		| (`ParamOpt, chr):