On Fri, Apr 22, 2022 at 09:26:39AM -0600, Todd C. Miller wrote:
> Another thing I noticed while testing the fix is that in cl_term_init()
> while processing the command mapping there is a missing NULL check.
> However, the check _is_ present for the input mapping loop. The
> following diff makes the two loops consistent.
>
> I'm not sure whether this is worth doing since I don't think we can
> end up with a NULL command mapping unless c_tklist[] is modified
> directly.
I would use an extra variable. The simplification alone is a good
argument to do it:
Index: cl/cl_term.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/cl/cl_term.c,v
retrieving revision 1.28
diff -u -p -r1.28 cl_term.c
--- cl/cl_term.c 20 Jul 2017 08:37:48 -0000 1.28
+++ cl/cl_term.c 22 Apr 2022 15:34:29 -0000
@@ -78,14 +78,18 @@ cl_term_init(SCR *sp)
{
SEQ *qp;
TKLIST const *tkp;
+ size_t output_len;
char *t;
/* Command mappings. */
for (tkp = c_tklist; tkp->name != NULL; ++tkp) {
if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
continue;
+ output_len = 0;
+ if (tkp->output != NULL)
+ output_len = strlen(tkp->output);
if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
- tkp->output, strlen(tkp->output), SEQ_COMMAND,
+ tkp->output, output_len, SEQ_COMMAND,
SEQ_NOOVERWRITE | SEQ_SCREEN))
return (1);
}
@@ -103,16 +107,13 @@ cl_term_init(SCR *sp)
*/
if (!strcmp(t, "\b"))
continue;
- if (tkp->output == NULL) {
- if (seq_set(sp, tkp->name, strlen(tkp->name),
- t, strlen(t), NULL, 0,
- SEQ_INPUT, SEQ_NOOVERWRITE | SEQ_SCREEN))
- return (1);
- } else
- if (seq_set(sp, tkp->name, strlen(tkp->name),
- t, strlen(t), tkp->output, strlen(tkp->output),
- SEQ_INPUT, SEQ_NOOVERWRITE | SEQ_SCREEN))
- return (1);
+ output_len = 0;
+ if (tkp->output != NULL)
+ output_len = strlen(tkp->output);
+ if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
+ tkp->output, output_len, SEQ_INPUT,
+ SEQ_NOOVERWRITE | SEQ_SCREEN))
+ return (1);
}
/*