From d53c27404d916dbb7686add4173acc57861889da Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 22 Feb 2022 12:59:53 -0800 Subject: bit: avoid calling strdup(NULL) It seems the behavior of strdup is undefined when NULL is passed in. Clang's static analyzer complains about this: > frameworks/base/tools/bit/command.cpp:195:25: warning: Null pointer passed to 1st parameter expecting 'nonnull' [clang-analyzer-core.NonNullParamChecker] Since we don't seem to care about malloc failures (which is a good thing IMO), adding a second check for the successful completion of `strdup` seems pointless. Bug: 206470603 Test: TreeHugger Change-Id: Ib621659e6fb600203694974f02d96ba0acb3362f --- tools/bit/command.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/bit/command.cpp b/tools/bit/command.cpp index f95ea117a96e..6c68e0b0ff6b 100644 --- a/tools/bit/command.cpp +++ b/tools/bit/command.cpp @@ -192,10 +192,11 @@ exec_with_path_search(const char* prog, char const* const* argv, char const* con if (strchr(prog, '/') != NULL) { return execve(prog, (char*const*)argv, (char*const*)envp); } else { - char* pathEnv = strdup(getenv("PATH")); - if (pathEnv == NULL) { + const char* pathEnvRaw = getenv("PATH"); + if (pathEnvRaw == NULL) { return 1; } + char* pathEnv = strdup(pathEnvRaw); char* dir = pathEnv; while (dir) { char* next = strchr(dir, ':'); -- cgit v1.2.3-59-g8ed1b