Debian Codegraph @

debian/patches/gcc8.patch

raw symbols SCIP
1 Description: fix compilation with GCC 8
2 The following fragment of code:
3 .
4 char current_date[50];
5 {
6 char buf[50];
7 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", lt);
8 snprintf(current_date, sizeof(current_date), "%s.%03d", buf, (int)(1000 * (time-seconds)));
9 }
10 .
11 leads to the following error when compiled with format string fortification
12 flags (default on Debian):
13 .
14 server/log.c: In function 'get_current_date':
15 server/log.c:64:54: error: '%03d' directive output may be truncated writing
16 between 3 and 11 bytes into a region of size between 0 and 49 [-Werror=format-truncation=]
17 snprintf(current_date, sizeof(current_date), "%s.%03d", buf, (int)(1000 * (time-seconds)));
18 ^~~~
19 .
20 the reason is that in the 'snprintf' call, the %s item is of maximum
21 length of 50, which leads to insufficient room for the %03d item. The 'buf'
22 string doesn't need the room for 50 characters, so decreasing that to 25 seems
23 like a good fix.
24
25 --- a/server/log.c
26 +++ b/server/log.c
27 @@ -56,7 +56,7 @@ char current_date[50];
28 char* get_current_date(void)
29 {
30 struct tm * lt;
31 - char buf[50];
32 + char buf[25];
33 double time = get_current_time_exact();
34 time_t seconds = (time_t)time;
35 lt = localtime(&seconds);