]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib: Eliminate dead code
authorTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 19 Sep 2024 20:10:17 +0000 (22:10 +0200)
committerAlejandro Colomar <alx@kernel.org>
Sun, 29 Sep 2024 10:23:05 +0000 (12:23 +0200)
The tz function is only called if ENV_TZ starts with a slash.

If the specified file cannot be read, the code implies that ENV_TZ
would be returned if it does not start with a slash.

Since we know that it DOES start with a slash, the code can be
simplified to state that "TZ=CST6CDT" is returned as a default if
the specified file cannot be read.

Benefit of this change is that strcpy's use case here can be
easier verified.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/tz.c

index 9506a8b16c92d5698262b6816a534ae1a6bd63d4..b854a593b558b5f9c830e1d1d76ef8f69e077ef2 100644 (file)
--- a/lib/tz.c
+++ b/lib/tz.c
 /*@observer@*/const char *tz (const char *fname)
 {
        FILE *fp = NULL;
+       const char *result;
        static char tzbuf[BUFSIZ];
-       const char *def_tz = "TZ=CST6CDT";
 
        fp = fopen (fname, "r");
        if (   (NULL == fp)
            || (fgets (tzbuf, sizeof (tzbuf), fp) == NULL)) {
-               def_tz = getdef_str ("ENV_TZ");
-               if ((NULL == def_tz) || ('/' == def_tz[0])) {
-                       def_tz = "TZ=CST6CDT";
-               }
-
-               strcpy (tzbuf, def_tz);
+               result = "TZ=CST6CDT";
        } else {
                stpsep(tzbuf, "\n");
+               result = tzbuf;
        }
 
        if (NULL != fp) {
                (void) fclose (fp);
        }
 
-       return tzbuf;
+       return result;
 }
 #else                          /* !USE_PAM */
 extern int ISO_C_forbids_an_empty_translation_unit;