summaryrefslogtreecommitdiff
path: root/vtysh
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2022-12-21 08:04:34 -0500
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2023-01-05 08:32:35 +0000
commit8d472da36100a5b86f1d32d71b24c9163607daf8 (patch)
treef20161c4cf6cb8d3e91c3ac236958e940c2a4634 /vtysh
parent9594783741cc342d7612024bce57feb75813012f (diff)
vtysh: Remove double retrieve of env VTYSH_HISTFILE
The code is double checking the VTYSH_HISTFILE env variable, additionally clang-15 when running SA over it doesn't fully understand the code pattern. Reduce the double check to one check to reduce program run-time (ha!) and make SA happy. Signed-off-by: Donald Sharp <sharpd@nvidia.com> (cherry picked from commit 99a9f25ce8c1e070f7f37c4cbd439c11bb7432eb)
Diffstat (limited to 'vtysh')
-rw-r--r--vtysh/vtysh_main.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index ca119eb900..8149d62a58 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -352,6 +352,7 @@ int main(int argc, char **argv, char **env)
const char *pathspace_arg = NULL;
char pathspace[MAXPATHLEN] = "";
const char *histfile = NULL;
+ const char *histfile_env = getenv("VTYSH_HISTFILE");
/* SUID: drop down to calling user & go back up when needed */
elevuid = geteuid();
@@ -609,10 +610,8 @@ int main(int argc, char **argv, char **env)
* VTYSH_HISTFILE is preferred over command line
* argument (-H/--histfile).
*/
- if (getenv("VTYSH_HISTFILE")) {
- const char *file = getenv("VTYSH_HISTFILE");
-
- strlcpy(history_file, file, sizeof(history_file));
+ if (histfile_env) {
+ strlcpy(history_file, histfile_env, sizeof(history_file));
} else if (histfile) {
strlcpy(history_file, histfile, sizeof(history_file));
} else {