hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 99bd4878dce080c8e0d47ba1b1ff7cb67fa08765
parent f65ef50516241f48bd876a594614fb6cd6599dde
Author: Sebastian <sebastian@sebsite.pw>
Date:   Wed, 13 Apr 2022 20:34:09 -0400

fmt: abort if too many parameters are given

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mfmt/fmt.ha | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/fmt/fmt.ha b/fmt/fmt.ha @@ -176,6 +176,7 @@ export fn fprintf( args: field... ) (io::error | size) = { let n = 0z, i = 0z; + let checkunused = true; let iter = strings::iter(fmt); for (true) { let r: rune = match (strings::next(&iter)) { @@ -200,6 +201,7 @@ export fn fprintf( const idx = if (ascii::isdigit(r)) { strings::push(&iter, r); + checkunused = false; yield scan_uint(&iter): size; } else { strings::push(&iter, r); @@ -236,6 +238,7 @@ export fn fprintf( match (pi) { case let pi: uint => + checkunused = false; match (args[pi]) { case let pmod: *modifiers => mod = pmod; @@ -272,6 +275,7 @@ export fn fprintf( }; }; + assert(!checkunused || i == len(args), "Too many parameters given"); return n; };