From af2d3b48c628666c61b1fa2c1814bdd1affd1068 Mon Sep 17 00:00:00 2001 From: Clark Rawlins Date: Sun, 14 Dec 2014 10:29:17 -0800 Subject: [PATCH] Use a temp to convert ut_time to time_t The localtime function takes a time_t* argument. Passing the ut_time member of the utmp struct as this argument doesn't work on 64 bit systems because the lengths of the arguments don't agree. So use a temproary variable to store the ut_time value in a time_t variable and pass the address of the time_t variable to localtime. Signed-off-by: Clark Rawlins --- timeoutd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/timeoutd.c b/timeoutd.c index 80b918a..ceed658 100644 --- a/timeoutd.c +++ b/timeoutd.c @@ -398,6 +398,7 @@ void read_wtmp() FILE *fp; struct utmp ut; struct tm *tm; + time_t time; #ifdef DEBUG openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON); @@ -418,7 +419,13 @@ void read_wtmp() while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) { - tm = localtime(&ut.ut_time); + /* On 64 bit systems time_t is a 64 bit integer + while ut_time is a 32 bit (unsigned) integer. + Copy the value to a time_t value so the pointer + types agree in the call to localtime. + */ + time = ut.ut_time; + tm = localtime(&time); if (tm->tm_year != now.tm_year || tm->tm_yday != now.tm_yday) break;