Skip to contentSkip to conversation

src/show: remove dead offset check code

PATCH In review Hangbin Liu 2 participants 4 messages May 17, 2021 – May 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src/show: remove dead offset check code

At first the offset will always be 0. So the check of offset ? ", " : "" is useless.

---
 src/show.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/show.c +1 -1
index 761858b..83d4d6b 100644
@@ -141,7 +141,7 @@ static size_t pretty_time(char *buf, const size_t len, unsigned long long left)
 	seconds = left % 60;
 
 	if (years)
-		offset += snprintf(buf + offset, len - offset, "%s%llu " TERMINAL_FG_CYAN "year%s" TERMINAL_RESET, offset ? ", " : "", years, years == 1 ? "" : "s");
+		offset = snprintf(buf, len, "%llu " TERMINAL_FG_CYAN "year%s" TERMINAL_RESET, years, years == 1 ? "" : "s");
 	if (days)
 		offset += snprintf(buf + offset, len - offset, "%s%llu " TERMINAL_FG_CYAN  "day%s" TERMINAL_RESET, offset ? ", " : "", days, days == 1 ? "" : "s");
 	if (hours)
Signature · 1 line
2.26.3
#1 lore raw

The compiler will optimize this out, right? In which case, I like the consistency, in case lines are ever reordered or copy and pasted.

#2 lore raw
Quoted 2 lines · Jason A. Donenfeld

The compiler will optimize this out, right? In which case, I like the consistency, in case lines are ever reordered or copy and pasted.

Not sure if compiler will optimize. I just got the complain when do covscan checking. I'm OK to keep the format.

Thanks
Hangbin