From: Valentine Krasnobaeva Date: Thu, 27 Mar 2025 09:16:03 +0000 (+0100) Subject: BUG/MINOR: log: fix gcc warn about truncating NUL terminator while init char arrays X-Git-Tag: v3.2-dev9~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44f98f1747e8b2ef400dafa249b3f70a2844e8fe;p=thirdparty%2Fhaproxy.git BUG/MINOR: log: fix gcc warn about truncating NUL terminator while init char arrays 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. --- diff --git a/src/log.c b/src/log.c index f8e48ca86..0ab89a1e1 100644 --- 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 */