]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: condition (secs == 0) - now handled correctly
authorcoastal-hiker <coastal-hiker@users.noreply.github.com>
Tue, 27 Jun 2017 12:14:49 +0000 (14:14 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 10 Jul 2017 08:03:41 +0000 (10:03 +0200)
Changed comparison "if (secs > 0)" to "if (secs >= 0)" to handle
condition (secs == 0) correctly.  Suggestions to improve the
less-than-elegant if-else chain are welcome.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/last.c

index ad70b38fb14ab7b42d353f6d61e7688cc9fd6c3e..2d7eb049f70e58f592f40d75ce4311701ac7916b 100644 (file)
@@ -457,7 +457,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t
                sprintf(length, "(%d+%02d:%02d)", days, abs(hours), abs(mins)); /* hours and mins always shown as positive (w/o minus sign!) even if secs < 0 */
        } else if (hours) {
                sprintf(length, " (%02d:%02d)", hours, abs(mins));  /* mins always shown as positive (w/o minus sign!) even if secs < 0 */
-       } else if (secs > 0) {
+       } else if (secs >= 0) {
                sprintf(length, " (%02d:%02d)", hours, mins); 
        } else {
                sprintf(length, " (-00:%02d)", abs(mins));  /* mins always shown as positive (w/o minus sign!) even if secs < 0 */