From c4eb4ab5df99fdfacefa792f7caf7f2ba40d3c0a Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 28 Sep 2026 16:00:28 +0000 Subject: [PATCH 1/2] Check time every iteration for expensive repeat loop. --- format.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index 6ce9f0a53..c6dba8a23 100644 --- a/format.c +++ b/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.418 2026/09/20 08:19:31 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.419 2026/09/28 16:00:28 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -6009,7 +6009,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, struct format_modifier **sub = NULL, *mexp = NULL, *fm; struct format_modifier *bool_op_n = NULL; u_int cycle_count = 1; - u_int i, count, nsub = 0, nrep, check = 0; + u_int i, count, nsub = 0, nrep; const char *loop_flags = ""; struct format_expand_state next; struct environ_entry *envent; @@ -6410,7 +6410,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, else { value = xstrdup(""); for (i = 0; i < nrep; i++) { - if (!format_check_time(es, &check)) { + if (!format_check_time(es, NULL)) { free(right); free(left); free(value); From 5fbfaca6a87da13c56709182af6b53b5d77bae6d Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 28 Sep 2026 16:23:56 +0000 Subject: [PATCH 2/2] Copy all #s at once when multiple are seen before [ rather than only copying one at a time which can be very slow. --- format.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/format.c b/format.c index c6dba8a23..bce6ea9ff 100644 --- a/format.c +++ b/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.419 2026/09/28 16:00:28 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.420 2026/09/28 16:23:56 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -6805,6 +6805,19 @@ format_expand1(struct format_expand_state *es, const char *fmt) fmt = ptr + 1; continue; } + if (ch == '#') { + while (len - off < (n / 2) + 1) { + buf = xreallocarray(buf, 2, len); + len *= 2; + } + memset(buf + off, '#', n / 2); + off += (n / 2); + if (n % 2 != 0) + fmt = ptr - 1; + else + fmt = ptr; + continue; + } /* FALLTHROUGH */ case '}': case ',':