]> jfr.im git - solanum.git/commitdiff
valid_temp_time: simplify/correct overflow check
authorEd Kellett <redacted>
Sun, 19 Jun 2022 21:07:20 +0000 (22:07 +0100)
committerEd Kellett <redacted>
Mon, 20 Jun 2022 15:35:03 +0000 (16:35 +0100)
the logic for trying to detect the maximum value of time_t was broken;
since we target a lower maximum time anyway, just use that for the
overflow check

ircd/s_newconf.c
tests/misc.c

index 6688c6ef3a68d37e926c9e00640631e1a7bab8d1..c755d6e3d2695b36ac02ad6c9b3ca2e19a345da7 100644 (file)
@@ -687,8 +687,6 @@ valid_temp_time(const char *p)
        time_t result = 0;
        long current = 0;
 
-       time_t max_time = (uintmax_t) (~(time_t)0) >> 1;
-
        while (*p) {
                char *endp;
                int mul;
@@ -726,7 +724,7 @@ valid_temp_time(const char *p)
 
                current *= mul;
 
-               if (current > max_time - result)
+               if (current > MAX_TEMP_TIME - result)
                        return MAX_TEMP_TIME;
 
                result += current;
index e588266e325005a2cb2c0093b55280fa878ce150..88e2c1e2974f55fd112483a40e80f844bf36a655 100644 (file)
@@ -60,15 +60,14 @@ static void valid_temp_time_invalid(void)
 
 static void valid_temp_time_overflow(void)
 {
-       time_t max_time = (uintmax_t) (~(time_t)0) >> 1;
        char s[100];
        time_t t;
 
-       snprintf(s, sizeof s, "%" PRIuMAX "m", (uintmax_t) max_time / 60 + 2);
+       snprintf(s, sizeof s, "%" PRIuMAX "m", UINTMAX_MAX / 60 + 2);
        t = valid_temp_time(s);
        is_int(52 * WEEK, t, MSG);
 
-       snprintf(s, sizeof s, "%" PRIuMAX "m%" PRIuMAX "m", (uintmax_t) max_time / 60 - 1, (uintmax_t) max_time / 60 - 1);
+       snprintf(s, sizeof s, "%" PRIuMAX "m%" PRIuMAX "m", UINTMAX_MAX / 60 - 1, UINTMAX_MAX / 60 - 1);
        t = valid_temp_time(s);
        is_int(52 * WEEK, t, MSG);
 }