From a8775f4e7f3f7153120bba1f78211400f45b68c4 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 17 Jul 2016 13:25:40 +0100 Subject: hwclock: initialize struct adjtime members 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 Signed-off-by: Sami Kerola --- sys-utils/hwclock.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'sys-utils/hwclock.c') diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index e78929260..7b363b567 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -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"), -- cgit v1.2.3-55-g7522