diff mbox series

parser: Print CTLBACKQ early in parsesub

Message ID Y7eSaxWkgoiFl8Lx@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series parser: Print CTLBACKQ early in parsesub | expand

Commit Message

Herbert Xu Jan. 6, 2023, 3:15 a.m. UTC
On Thu, Jan 05, 2023 at 02:42:04PM +0100, наб wrote:
>
> I think this means we also need to turn the USTPUTC() into STPUTC(),
> since the previous code explicitly over-accounted for it in growstackto().

Good catch.  However, we can easily get rid of it by moving the
USTPUTC to the top:

---8<---
As we are allowed to perform 4 USTPUTC's we can save a growstackstr
call by adding the CTLBACKQ before we save the string.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Ahelenia Ziemiańska Jan. 6, 2023, 11:49 a.m. UTC | #1
Hi!

On Fri, Jan 06, 2023 at 11:15:55AM +0800, Herbert Xu wrote:
> On Thu, Jan 05, 2023 at 02:42:04PM +0100, наб wrote:
> > I think this means we also need to turn the USTPUTC() into STPUTC(),
> > since the previous code explicitly over-accounted for it in growstackto().
> Good catch.  However, we can easily get rid of it by moving the
> USTPUTC to the top:

Yep, patch works for me and appears sound; that's the first USTPUTC()
for the new path and the second for the old path.

наб
diff mbox series

Patch

diff --git a/src/parser.c b/src/parser.c
index f5f76d5..299c260 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1360,6 +1360,7 @@  parsebackq: {
 	struct heredoc *saveheredoclist;
 	int uninitialized_var(saveprompt);
 
+	USTPUTC(CTLBACKQ, out);
 	str = stackblock();
 	savelen = out - (char *)stackblock();
 	grabstackblock(savelen);
@@ -1443,7 +1444,6 @@  done:
 	if (oldstyle)
 		tokpushback = 0;
 	out = stnputs(str, savelen, stackblock());
-	STPUTC(CTLBACKQ, out);
 	if (oldstyle)
 		goto parsebackq_oldreturn;
 	else