From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH v2 03/28] clang-tidy: Fix spurious null pointer warning in pasta_start_ns() Date: Thu, 29 Sep 2022 13:38:07 +1000 Message-ID: <20220929033832.923149-4-david@gibson.dropbear.id.au> In-Reply-To: <20220929033832.923149-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4994279706284689575==" --===============4994279706284689575== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit clang-tidy isn't quite clever enough to figure out that getenv("SHELL") will return the same thing both times here, which makes it conclude that shell could be NULL, causing problems later. It's a bit ugly that we call getenv() twice in any case, so rework this in a way that clang-tidy can figure out shell won't be NULL. Signed-off-by: David Gibson --- pasta.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pasta.c b/pasta.c index e233762..1dd8267 100644 --- a/pasta.c +++ b/pasta.c @@ -184,7 +184,7 @@ void pasta_start_ns(struct ctx *c, int argc, char *argv[]) struct pasta_setup_ns_arg arg = { .argv = argv, }; - char *shell = getenv("SHELL") ? getenv("SHELL") : "/bin/sh"; + char *shell = getenv("SHELL"); char *sh_argv[] = { shell, NULL }; char *bash_argv[] = { shell, "-l", NULL }; char ns_fn_stack[NS_FN_STACK_SIZE]; @@ -193,6 +193,9 @@ void pasta_start_ns(struct ctx *c, int argc, char *argv[]) if (!c->debug) c->quiet = 1; + if (!shell) + shell = "/bin/sh"; + if (argc == 0) { if (strstr(shell, "/bash")) { arg.argv = bash_argv; -- 2.37.3 --===============4994279706284689575==--