]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: initialize struct adjtime members
authorSami Kerola <kerolasa@iki.fi>
Sun, 17 Jul 2016 12:25:40 +0000 (13:25 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 4 Feb 2017 23:39:37 +0000 (23:39 +0000)
Avoid any chance of using uninitialized values.  It looks like the earlier
code did take care of that, but it was less obvious about the fact.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/hwclock.c

index e78929260c314d571931e981216f542a14ff4d4a..7b363b5671be00a8742e17fc01f91800b3a43fa1 100644 (file)
@@ -118,7 +118,7 @@ struct adjtime {
         * authority (as opposed to just doing a drift adjustment)
         */
        /* line 3 */
-       enum a_local_utc { LOCAL, UTC, UNKNOWN } local_utc;
+       enum a_local_utc { UTC = 0, LOCAL, UNKNOWN } local_utc;
        /*
         * To which time zone, local or UTC, we most recently set the
         * hardware clock.
@@ -248,19 +248,9 @@ static int read_adjtime(const struct hwclock_control *ctl,
        char line1[81];         /* String: first line of adjtime file */
        char line2[81];         /* String: second line of adjtime file */
        char line3[81];         /* String: third line of adjtime file */
-       long timeval;
-
-       if (access(ctl->adj_file_name, R_OK) != 0) {
-               /* He doesn't have a adjtime file, so we'll use defaults. */
-               adjtime_p->drift_factor = 0;
-               adjtime_p->last_adj_time = 0;
-               adjtime_p->not_adjusted = 0;
-               adjtime_p->last_calib_time = 0;
-               adjtime_p->local_utc = UTC;
-               adjtime_p->dirty = FALSE;       /* don't create a zero adjfile */
 
+       if (access(ctl->adj_file_name, R_OK) != 0)
                return 0;
-       }
 
        adjfile = fopen(ctl->adj_file_name, "r");       /* open file for reading */
        if (adjfile == NULL) {
@@ -268,7 +258,6 @@ static int read_adjtime(const struct hwclock_control *ctl,
                return EX_OSFILE;
        }
 
-
        if (!fgets(line1, sizeof(line1), adjfile))
                line1[0] = '\0';        /* In case fgets fails */
        if (!fgets(line2, sizeof(line2), adjfile))
@@ -278,20 +267,12 @@ static int read_adjtime(const struct hwclock_control *ctl,
 
        fclose(adjfile);
 
-       /* Set defaults in case values are missing from file */
-       adjtime_p->drift_factor = 0;
-       adjtime_p->last_adj_time = 0;
-       adjtime_p->not_adjusted = 0;
-       adjtime_p->last_calib_time = 0;
-       timeval = 0;
-
        sscanf(line1, "%lf %ld %lf",
               &adjtime_p->drift_factor,
-              &timeval, &adjtime_p->not_adjusted);
-       adjtime_p->last_adj_time = timeval;
+              &adjtime_p->last_adj_time,
+              &adjtime_p->not_adjusted);
 
-       sscanf(line2, "%ld", &timeval);
-       adjtime_p->last_calib_time = timeval;
+       sscanf(line2, "%ld", &adjtime_p->last_calib_time);
 
        if (!strcmp(line3, "UTC\n")) {
                adjtime_p->local_utc = UTC;
@@ -305,8 +286,6 @@ static int read_adjtime(const struct hwclock_control *ctl,
                }
        }
 
-       adjtime_p->dirty = FALSE;
-
        if (ctl->debug) {
                printf(_
                       ("Last drift adjustment done at %ld seconds after 1969\n"),