Merge pull request #458 from adrianschmutzler/fixcommit
[feed/routing.git] / nodogsplash / patches / 0001-fix-invalid-pointer-when-clock-is-turned-back.patch
1 From af548c1f885e46309baa6aa175a3822fd16afb2a Mon Sep 17 00:00:00 2001
2 From: Moritz Warning <moritzwarning@web.de>
3 Date: Thu, 14 Mar 2019 17:19:40 +0100
4 Subject: [PATCH] fix invalid pointer when clock is turned back
5
6 ---
7 src/util.c | 12 ++++++------
8 1 file changed, 6 insertions(+), 6 deletions(-)
9
10 diff --git a/src/util.c b/src/util.c
11 index 621062d..77228bf 100644
12 --- a/src/util.c
13 +++ b/src/util.c
14 @@ -362,14 +362,14 @@ format_duration(time_t from, time_t to, char buf[64])
15 {
16 int days, hours, minutes, seconds;
17 long long int secs;
18 + const char *neg = "";
19
20 if (from <= to) {
21 secs = to - from;
22 } else {
23 secs = from - to;
24 // Prepend minus sign
25 - buf[0] = '-';
26 - buf += 1;
27 + neg = "-";
28 }
29
30 days = secs / (24 * 60 * 60);
31 @@ -381,13 +381,13 @@ format_duration(time_t from, time_t to, char buf[64])
32 seconds = secs;
33
34 if (days > 0) {
35 - sprintf(buf, "%dd %dh %dm %ds", days, hours, minutes, seconds);
36 + snprintf(buf, 64, "%s%dd %dh %dm %ds", neg, days, hours, minutes, seconds);
37 } else if (hours > 0) {
38 - sprintf(buf, "%dh %dm %ds", hours, minutes, seconds);
39 + snprintf(buf, 64, "%s%dh %dm %ds", neg, hours, minutes, seconds);
40 } else if (minutes > 0) {
41 - sprintf(buf, "%dm %ds", minutes, seconds);
42 + snprintf(buf, 64, "%s%dm %ds", neg, minutes, seconds);
43 } else {
44 - sprintf(buf, "%ds", seconds);
45 + snprintf(buf, 64, "%s%ds", neg, seconds);
46 }
47
48 return buf;
49 --
50 2.20.1
51