summaryrefslogtreecommitdiffstats
path: root/sys-utils/hwclock.c
diff options
context:
space:
mode:
authorSami Kerola2016-07-17 14:25:40 +0200
committerSami Kerola2017-02-05 00:39:37 +0100
commita8775f4e7f3f7153120bba1f78211400f45b68c4 (patch)
tree090fb05ddd013f114e8ac1dc86a23d09abacbeef /sys-utils/hwclock.c
parenthwclock: alloate date_resp parsing buffer in interpret_date_string() (diff)
downloadkernel-qcow2-util-linux-a8775f4e7f3f7153120bba1f78211400f45b68c4.tar.gz
kernel-qcow2-util-linux-a8775f4e7f3f7153120bba1f78211400f45b68c4.tar.xz
kernel-qcow2-util-linux-a8775f4e7f3f7153120bba1f78211400f45b68c4.zip
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 <elseifthen@gmx.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/hwclock.c')
-rw-r--r--sys-utils/hwclock.c31
1 files changed, 5 insertions, 26 deletions
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"),