From 8730b145c8317fffe1ce4089b79f17551a9476ce Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Sat, 13 Jun 2026 01:31:14 +0100 Subject: [PATCH] Suppress gcc compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some reason gcc thinks q+3 might be out of bounds below. It isn't, but adding the strlen(q) >= 3 condition suppresses the warning. In function ‘sa_snmatch’, inlined from ‘sa_snmatch’ at /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:56:12, inlined from ‘sa_num_matches_by_ids’ at /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:190:48, inlined from ‘sa_unique_by_ids’ at /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:203:61, inlined from ‘sa_list_specs’ at /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:239:8, inlined from ‘sa_print_specs’ at /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:253:19: /home/srueger/etc/clock/avrdude/gcc-warning/src/serialadapter.c:57:63: warning: array subscript 3 is outside array bounds of ‘char[1]’ [-Warray-bounds=] 57 | return sn && (str_starts(sn, q) || (str_starts(q, "...") && str_ends(sn, q + 3))); | ^~~~~~~~~~~~~~~~~~~ --- src/serialadapter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/serialadapter.c b/src/serialadapter.c index c186cd96..07eedb87 100644 --- a/src/serialadapter.c +++ b/src/serialadapter.c @@ -54,7 +54,8 @@ static int sa_setport(char **portp, const char *sp_port) { // Is the actual serial number sn matched by the query q? static int sa_snmatch(const char *sn, const char *q) { - return sn && (str_starts(sn, q) || (str_starts(q, "...") && str_ends(sn, q + 3))); + return sn && (str_starts(sn, q) || + (str_starts(q, "...") && strlen(q) >= 3 /* suppress gcc warning */ && str_ends(sn, q + 3))); } #define null_len(s) ((s)? strlen(s): 0)