Skip to content

Commit

Permalink
match: Fix false-positive snprintf size warning.
Browse files Browse the repository at this point in the history
GCC 14.1.1 of Fedora 41 thinks that 'i' can be in a full range and
so 8 bytes is not enough to print it.

 lib/match.c: In function 'match_format':
 lib/match.c:1631:45:
         error: '%d' directive output may be truncated writing
                between 1 and 11 bytes into a region of size 8
  1631 |             snprintf(str_i, sizeof(str_i), "%d", i);
       |                                             ^~
 lib/match.c:1631:44:
           note: directive argument in the range [-2147483646, 1]
  1631 |             snprintf(str_i, sizeof(str_i), "%d", i);
       |                                            ^~~~
 lib/match.c:1631:13:
           note: 'snprintf' output between 2 and 12 bytes into
                 a destination of size 8
  1631 |             snprintf(str_i, sizeof(str_i), "%d", i);
       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In practice that value can't be larger than 2, but it's not a
performance critical code, so let's just increase the size to
a maximum 12.

Acked-by: Mike Pattrick <mkp@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
  • Loading branch information
igsilya committed Jul 17, 2024
1 parent d548506 commit 7b58b6f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ match_format(const struct match *match,
ds_put_char(s, ',');
}
for (i = 0; i < FLOW_MAX_VLAN_HEADERS; i++) {
char str_i[8];
char str_i[12];

if (!wc->masks.vlans[i].tci) {
break;
Expand Down

0 comments on commit 7b58b6f

Please sign in to comment.