shithub: mc

Download patch

ref: 30c662571c4f64f72171cca0efc7bedc59bd53fa
parent: fcfba8c44c5ee110b7b5fd86d752fdeec33eeb0b
author: Quentin Carbonneaux <quentin@c9x.me>
date: Sun Jan 28 14:37:32 EST 2018

Improve error message for mismatched formats.

That caught me many times.

--- a/lib/std/fmt.myr
+++ b/lib/std/fmt.myr
@@ -180,6 +180,9 @@
 		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))
@@ -238,7 +241,7 @@
 		;;
 	;;
 	if nfmt != nvarargs
-		die("too many params for fmt\n")
+		die("too many values for fmt\n")
 	;;
 	-> sb.len
 }
@@ -463,7 +466,7 @@
 		| ("x", ""):	ip.base = 16
 		| ("w", wid):	ip.padto = getint(wid, "fmt: width must be integer")
 		| ("p", pad):	ip.padfill = decode(pad)
-		| (opt, arg):	
+		| (opt, arg):
 			std.write(2, "fmt: ")
 			std.write(2, opt)
 			std.write(2, "arg: ")