Skip to content

Commit

Permalink
fix memory handling bug, fixes #341
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Mar 13, 2019
1 parent 4a85989 commit 544701b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ format_duration(time_t from, time_t to, char buf[64])
{
int days, hours, minutes, seconds;
long long int secs;
const char *neg = "";

if (from <= to) {
secs = to - from;
} else {
secs = from - to;
// Prepend minus sign
buf[0] = '-';
buf += 1;
neg = "-";
}

days = secs / (24 * 60 * 60);
Expand All @@ -348,13 +348,13 @@ format_duration(time_t from, time_t to, char buf[64])
seconds = secs;

if (days > 0) {
snprintf(buf, 64, "%dd %dh %dm %ds", days, hours, minutes, seconds);
snprintf(buf, 64, "%s%dd %dh %dm %ds", neg, days, hours, minutes, seconds);
} else if (hours > 0) {
snprintf(buf, 64, "%dh %dm %ds", hours, minutes, seconds);
snprintf(buf, 64, "%s%dh %dm %ds", neg, hours, minutes, seconds);
} else if (minutes > 0) {
snprintf(buf, 64, "%dm %ds", minutes, seconds);
snprintf(buf, 64, "%s%dm %ds", neg, minutes, seconds);
} else {
snprintf(buf, 64, "%ds", seconds);
snprintf(buf, 64, "%s%ds", neg, seconds);
}

return buf;
Expand Down

0 comments on commit 544701b

Please sign in to comment.