From 4ea4090788fbd0cdfb9e4c1cf2f8c96842132cb1 Mon Sep 17 00:00:00 2001 From: Joe Damato Date: Thu, 18 Jul 2013 22:35:45 -0700 Subject: [PATCH 1/2] Handle the case where nl_msec2str is passed 0 msecs (cherry picked from commit b3fb89f445108677d405c62865b25aeea209d10a) --- lib/utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/utils.c b/lib/utils.c index d7f6724..e04a7b7 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -552,6 +552,11 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len) #undef _SPLIT split[4] = msec; + if (msec == 0) { + snprintf(buf, len, "0msec"); + return buf_orig; + } + for (i = 0; i < ARRAY_SIZE(split) && len; i++) { int l; if (split[i] == 0) -- 1.8.5.3 From 58c7f957ca301c3ca65a3788ecb7412b32469ae1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 19 Feb 2014 19:22:13 +0100 Subject: [PATCH 2/2] utils: fix nl_msec2str() which always returned '0msec' for whole second durations If the duration was without subsecond part, the function always returned '0msec', instead of giving the time in days, hours, minutes or seconds. Regression introduced by commit b3fb89f445108677d405c62865b25aeea209d10a. Signed-off-by: Thomas Haller Acked-by: Thomas Graf (cherry picked from commit 3fb0aae0bc37eafe868d28f0f12ee8803d7ad266) --- lib/utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index e04a7b7..44350c3 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -544,6 +544,11 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len) static const char *units[5] = {"d", "h", "m", "s", "msec"}; char * const buf_orig = buf; + if (msec == 0) { + snprintf(buf, len, "0msec"); + return buf_orig; + } + #define _SPLIT(idx, unit) if ((split[idx] = msec / unit)) msec %= unit _SPLIT(0, 86400000); /* days */ _SPLIT(1, 3600000); /* hours */ @@ -552,11 +557,6 @@ char * nl_msec2str(uint64_t msec, char *buf, size_t len) #undef _SPLIT split[4] = msec; - if (msec == 0) { - snprintf(buf, len, "0msec"); - return buf_orig; - } - for (i = 0; i < ARRAY_SIZE(split) && len; i++) { int l; if (split[i] == 0) -- 1.8.5.3