commit f09e65c5c66fcfc6472bd85a050175c0fef98a37
parent 7a559c1b9f753308b96da769e4ed14313592fe18
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Tue, 25 Jan 2022 04:44:04 +0100
fmt: print a diagnostic message if there aren't enough parameters
instead of just aborting with the generic OOB message
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fmt/fmt.ha b/fmt/fmt.ha
@@ -184,19 +184,22 @@ export fn fprintf(
yield r;
};
- let arg = if (r == '{') {
+ if (r == '{') {
n += io::write(h, utf8::encoderune('{'))?;
continue;
- } else if (ascii::isdigit(r)) {
+ };
+
+ const idx = if (ascii::isdigit(r)) {
strings::push(&iter, r);
- yield args[scan_uint(&iter)];
+ yield scan_uint(&iter): size;
} else {
strings::push(&iter, r);
i += 1;
- yield args[i - 1];
+ yield i - 1;
};
+ assert(idx < len(args), "Not enough parameters given");
- const arg = match (arg) {
+ const arg = match (args[idx]) {
case let arg: formattable =>
yield arg;
case =>