From 815ffb7d3e0a8e1d78886dded65a5c6afd22c94e Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Fri, 13 Jun 2008 19:48:11 +0000 Subject: [PATCH] * libmisc/strtoday.c: Avoid implicit conversion of pointers to booleans. * libmisc/strtoday.c: Add brackets and parenthesis. --- ChangeLog | 6 ++++++ libmisc/strtoday.c | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 677b386a..4988e9e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-06-13 Nicolas François + + * libmisc/strtoday.c: Avoid implicit conversion of pointers to + booleans. + * libmisc/strtoday.c: Add brackets and parenthesis. + 2008-06-13 Nicolas François * libmisc/salt.c: Use a size_t for the size of strings instead of diff --git a/libmisc/strtoday.c b/libmisc/strtoday.c index 9646298b..7abbf108 100644 --- a/libmisc/strtoday.c +++ b/libmisc/strtoday.c @@ -69,14 +69,16 @@ long strtoday (const char *str) * which is not what we expect, unless you're a BOFH :-). * (useradd sets sp_expire = current date for new lusers) */ - if (!str || *str == '\0') + if ((NULL == str) || ('\0' == *str)) { return -1; + } t = get_date (str, (time_t *) 0); - if (t == (time_t) - 1) + if ((time_t) - 1 == t) { return -1; + } /* convert seconds to days since 1970-01-01 */ - return (t + DAY / 2) / DAY; + return (long) (t + DAY / 2) / DAY; } #else /* !USE_GETDATE */ @@ -129,14 +131,16 @@ long strtoday (const char *str) memzero (&tp, sizeof tp); for (fmt = date_formats; *fmt; fmt++) { cp = strptime ((char *) str, *fmt, &tp); - if (!cp || *cp != '\0') + if ((NULL == cp) || ('\0' != *cp)) { continue; + } result = mktime (&tp); - if (result == (time_t) - 1) + if ((time_t) - 1 == result) { continue; + } - return result / DAY; /* success */ + return (long) (result / DAY); /* success */ } return -1; #else @@ -151,8 +155,9 @@ long strtoday (const char *str) * is compiled in ... */ - if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3) + if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3) { return -1; + } /* * the month, day of the month, and year are checked for @@ -160,23 +165,28 @@ long strtoday (const char *str) * 1970 and 2069. */ - if (month < 1 || month > 12) + if ((month < 1) || (month > 12)) { return -1; + } - if (day < 1) + if (day < 1) { return -1; + } - if ((month != 2 || (year % 4) != 0) && day > days[month]) + if ( ((2 != month) || ((year % 4) != 0)) + && (day > days[month])) { return -1; - else if ((month == 2 && (year % 4) == 0) && day > 29) + } else if ((month == 2) && ((year % 4) == 0) && (day > 29)) { return -1; + } - if (year < 0) + if (year < 0) { return -1; - else if (year <= 69) + } else if (year <= 69) { year += 2000; - else if (year <= 99) + } else if (year <= 99) { year += 1900; + } /* * On systems with 32-bit signed time_t, time wraps around in 2038 @@ -184,8 +194,9 @@ long strtoday (const char *str) * This limit can be removed once no one is using 32-bit systems * anymore :-). --marekm */ - if (year < 1970 || year > 2037) + if ((year < 1970) || (year > 2037)) { return -1; + } /* * the total number of days is the total number of days in all