BUG/MINOR: log: fix gcc warn about truncating NUL terminator while init char arrays
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Thu, 27 Mar 2025 09:16:03 +0000 (10:16 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 15 Apr 2025 18:09:42 +0000 (20:09 +0200)
gcc 15 throws such kind of warnings about initialization of some char arrays:

src/log.c:181:33: error: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (17 chars into 16 available) [-Werror=unterminated-string-initialization]
  181 | const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */
      |                                 ^~~~~~~~~~~~~~~~~~
src/log.c:182:33: error: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (9 chars into 8 available) [-Werror=unterminated-string-initialization]
  182 | const char sess_fin_state[8]  = "-RCHDLQT";     /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */

So, let's make it happy by not giving the sizes of these char arrays
explicitly, thus he can accomodate there NUL terminators.

Reported in GitHub issue #2910.

This should be backported up to 2.6.

(cherry picked from commit 44f98f1747e8b2ef400dafa249b3f70a2844e8fe)
Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com>
(cherry picked from commit d77be2405b6cd5d0cc6c29953cf43315967f02d2)
[ada: patch was applied manually because of multiple context conflicts]
Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com>

src/log.c

index 7b651b4..3cbbabf 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -117,8 +117,8 @@ const char *log_levels[NB_LOG_LEVELS] = {
        "warning", "notice", "info", "debug"
 };
 
-const char sess_term_cond[16] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */
-const char sess_fin_state[8]  = "-RCHDLQT";    /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
+const char sess_term_cond[] = "-LcCsSPRIDKUIIII"; /* normal, Local, CliTo, CliErr, SrvTo, SrvErr, PxErr, Resource, Internal, Down, Killed, Up, -- */
+const char sess_fin_state[]  = "-RCHDLQT";        /* cliRequest, srvConnect, srvHeader, Data, Last, Queue, Tarpit */
 const struct buffer empty = { };
 
 
@@ -3208,8 +3208,8 @@ void __send_log(struct list *loggers, struct buffer *tagb, int level,
        return process_send_log(loggers, level, -1, metadata, message, size);
 }
 
-const char sess_cookie[8]     = "NIDVEOU7";    /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, Unused, unknown */
-const char sess_set_cookie[8] = "NPDIRU67";    /* No set-cookie, Set-cookie found and left unchanged (passive),
+const char sess_cookie[]     = "NIDVEOU7";      /* No cookie, Invalid cookie, cookie for a Down server, Valid cookie, Expired cookie, Old cookie, Unused, unknown */
+const char sess_set_cookie[] = "NPDIRU67";      /* No set-cookie, Set-cookie found and left unchanged (passive),
                                                   Set-cookie Deleted, Set-Cookie Inserted, Set-cookie Rewritten,
                                                   Set-cookie Updated, unknown, unknown */