From 02a0bef92b999c14083563d32a538693f681d4f2 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 28 Sep 2026 16:23:56 +0000 Subject: [PATCH] Copy all #s at once when multiple are seen before [ rather than only copying one at a time which can be very slow. (cherry picked from commit 5fbfaca6a87da13c56709182af6b53b5d77bae6d) --- format.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/format.c b/format.c index ecb9634f6..f35c9719c 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 @@ -6824,6 +6824,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 ',':