]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 27 Mar 2025 10:52:33 +0000 (11:52 +0100)
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.

src/log.c

index f8e48ca861e6e810bb48f3d91521e3878fbc559b..0ab89a1e1b6f7234e4fa6bffd32ed5bdd9dccb0c 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -177,9 +177,8 @@ const char *log_levels[NB_LOG_LEVELS] = {
        "emerg", "alert", "crit", "err",
        "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 = { };
 
 
@@ -3473,9 +3472,8 @@ struct ist *build_log_header(struct log_header hdr, size_t *nbelem)
 
        return hdr_ctx.ist_vector;
 }
-
-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 */