Index | Thread | Search

From:
Jeremy Mates <jmates@thrig.me>
Subject:
vi E_CLRFLAG not being used correctly?
To:
tech@openbsd.org
Date:
Sat, 31 Jan 2026 00:59:35 +0000

Download raw body.

Thread
  • Jeremy Mates:

    vi E_CLRFLAG not being used correctly?

	$ printf 'append\na\nb\nc\n.\nnumber\nnumber l\nq!\n' | ex         
		 3  c
		 3  c$
	c$

In ex mode, the "number" command when given the "l" (literal display)
flag causes an additional line to be printed by the autoprint code in
ex/ex.c. The autoprint code tries to turn off the various flags when
E_CLRFLAG is set by an ex command. However, it appears that E_CLRFLAG is
put into ecp->flags ("current flags") from the command flags,

    /* Add standard command flags. */
    F_SET(ecp, ecp->cmd->flags);

while the ex/ex.c autoprint code instead checks ecp->iflags ("User input
information") for E_CLRFLAG, hence the "number l" command causing an
additional ex_print line, as E_C_LIST is not turned off.

        /*
         * The print commands have already handled the `print' flags.
         * If so, clear them.
         */
        if (FL_ISSET(ecp->iflags, E_CLRFLAG))
            FL_CLR(ecp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT);

A fix might be to use ->flags (where E_CLRFLAG is) instead of ->iflags?

--- ex/ex.c
+++ ex/ex.c
@@ -1439,7 +1439,7 @@ addr_verify:
 		 * The print commands have already handled the `print' flags.
 		 * If so, clear them.
 		 */
-		if (FL_ISSET(ecp->iflags, E_CLRFLAG))
+		if (FL_ISSET(ecp->flags, E_CLRFLAG))
 			FL_CLR(ecp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT);
 
 		/* If hash set only because of the number option, discard it. */