summaryrefslogtreecommitdiff
path: root/src/shutdownd
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-21 19:20:41 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-21 22:39:23 -0400
commit7a4b2eab6d1d0e4b67cbcb87b84588edd34aabb5 (patch)
tree480b03b0b6a5cfdc37048bee2cde60d12c6ecf42 /src/shutdownd
parent40c2cce772ed74e7c6d302a6143ad818e9a2720d (diff)
shutdownd: shut up bogus gcc warning
This one is fake. But let's kill it, avoiding two condition checks in the process. src/shutdownd/shutdownd.c: In function 'when_wall': src/shutdownd/shutdownd.c:182:44: warning: 'sub' may be used uninitialized in this function [-Wmaybe-uninitialized] return elapse > sub ? elapse - sub : 1; ^
Diffstat (limited to 'src/shutdownd')
-rw-r--r--src/shutdownd/shutdownd.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 0464c89187..119385d67f 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -157,29 +157,26 @@ static usec_t when_wall(usec_t n, usec_t elapse) {
usec_t delay;
usec_t interval;
} table[] = {
- { 10 * USEC_PER_MINUTE, USEC_PER_MINUTE },
- { USEC_PER_HOUR, 15 * USEC_PER_MINUTE },
- { 3 * USEC_PER_HOUR, 30 * USEC_PER_MINUTE }
+ { 0, USEC_PER_MINUTE },
+ { 10 * USEC_PER_MINUTE, 15 * USEC_PER_MINUTE },
+ { USEC_PER_HOUR, 30 * USEC_PER_MINUTE },
+ { 3 * USEC_PER_HOUR, USEC_PER_HOUR },
};
usec_t left, sub;
- unsigned i;
+ unsigned i = ELEMENTSOF(table) - 1;
/* If the time is already passed, then don't announce */
if (n >= elapse)
return 0;
left = elapse - n;
- for (i = 0; i < ELEMENTSOF(table); i++)
- if (n + table[i].delay >= elapse) {
- sub = ((left / table[i].interval) * table[i].interval);
- break;
- }
-
- if (i >= ELEMENTSOF(table))
- sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR);
+ while (left < table[i].delay)
+ i--;
+ sub = (left / table[i].interval) * table[i].interval;
- return elapse > sub ? elapse - sub : 1;
+ assert(sub < elapse);
+ return elapse - sub;
}
static usec_t when_nologin(usec_t elapse) {