From a114beb5551a982dd825247e1e02a901c05c725e Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 3 Feb 2023 15:55:59 +0000 Subject: [PATCH] Fix tput when compiled with clang-15 -O2 For some reason clang-15 doesn't like passing the uninitialized array of pointers nargv[] to the vararg function tparm(). With -O2 it optimizes the for loop preceding the tparm() call strangely, with the result that the argv[i] == NULL error is hit in most real-world usage. This broke naddy's fancy shell prompt among other things. Initialize nargv[] to appease the insatiable undefined behavior exploiter. ok jca millert --- usr.bin/tput/tput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c index 2832b979972..4357553afd8 100644 --- a/usr.bin/tput/tput.c +++ b/usr.bin/tput/tput.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tput.c,v 1.26 2022/12/22 19:53:24 kn Exp $ */ +/* $OpenBSD: tput.c,v 1.27 2023/02/03 15:55:59 tb Exp $ */ /* * Copyright (c) 1999 Todd C. Miller @@ -192,7 +192,7 @@ main(int argc, char *argv[]) static char ** process(char *cap, char *str, char **argv) { - char *cp, *s, *nargv[9]; + char *cp, *s, *nargv[9] = {0}; int arg_need, popcount, i; /* Count how many values we need for this capability. */ -- 2.20.1