Skip to content

Commit b5bc748

Browse files
authored
T7156: suppress sprintf format warnings at the source level (#13)
rather than with CFLAGS, so that it applies only to locations where it was proven safe and is protected against CFLAGS overrides
1 parent 6ab2990 commit b5bc748

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AM_CFLAGS = --pedantic -Wall -Werror -Wno-error=format-overflow= -std=c99 -O2
1+
AM_CFLAGS = --pedantic -Wall -Werror -std=c99 -O2
22
AM_LDFLAGS =
33

44
ipaddrcheck_SOURCES = ipaddrcheck.c ipaddrcheck_functions.c

src/ipaddrcheck_functions.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,13 @@ int is_ipv4_range(char* range_str, int prefix_length, int verbose)
578578
{
579579
char left_pref_str[19];
580580

581-
/* XXX: Prefix length size is checked elsewhere, so it can't be more than 2 characters (32)
581+
/* XXX: Prefix length size is checked elsewhere with a regex, so it can't be more than 2 characters (32)
582582
and overflow cannot occur.
583583
*/
584+
#pragma GCC diagnostic push
585+
#pragma GCC diagnostic ignored "-Wformat-overflow="
584586
sprintf(left_pref_str, "%s/%u", left, prefix_length);
587+
#pragma GCC diagnostic pop
585588
CIDR* left_addr_with_pref = cidr_from_str(left_pref_str);
586589
CIDR* left_net = cidr_addr_network(left_addr_with_pref);
587590
if( cidr_contains(left_net, right_addr) == 0 )
@@ -679,10 +682,13 @@ int is_ipv6_range(char* range_str, int prefix_length, int verbose)
679682
{
680683
char left_pref_str[44];
681684

682-
/* XXX: Prefix length size is checked elsewhere, so it can't be more than 3 characters (128)
685+
/* XXX: Prefix length size is checked elsewhere with a regex, so it can't be more than 3 characters (128)
683686
and overflow cannot occur.
684687
*/
688+
#pragma GCC diagnostic push
689+
#pragma GCC diagnostic ignored "-Wformat-overflow="
685690
sprintf(left_pref_str, "%s/%u", left, prefix_length);
691+
#pragma GCC diagnostic pop
686692
CIDR* left_addr_with_pref = cidr_from_str(left_pref_str);
687693
CIDR* left_net = cidr_addr_network(left_addr_with_pref);
688694
if( cidr_contains(left_net, right_addr) == 0 )

0 commit comments

Comments
 (0)