chiark / gitweb /
time: don't do comparison twice
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Oct 2014 17:10:09 +0000 (19:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Oct 2014 17:10:09 +0000 (19:10 +0200)
src/shared/time-util.c

index 33d0822..d3404af 100644 (file)
@@ -296,8 +296,14 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
         assert(buf);
         assert(l > 0);
 
-        if (t == USEC_INFINITY || t <= 0) {
-                strncpy(p, t == USEC_INFINITY ? "infinity" : "0", l);
+        if (t == USEC_INFINITY) {
+                strncpy(p, "infinity", l-1);
+                p[l-1] = 0;
+                return p;
+        }
+
+        if (t <= 0) {
+                strncpy(p, "0", l-1);
                 p[l-1] = 0;
                 return p;
         }