]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: Remove double retrieve of env VTYSH_HISTFILE 12557/head
authorDonald Sharp <sharpd@nvidia.com>
Wed, 21 Dec 2022 13:04:34 +0000 (08:04 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 21 Dec 2022 13:04:34 +0000 (08:04 -0500)
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>
vtysh/vtysh_main.c

index a72cb6e809d8e7c888ab0b5189e8017cd915562c..be7eb3ecdfd666860a76220aacf84f7bd7597f6b 100644 (file)
@@ -354,6 +354,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();
@@ -611,10 +612,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 {