Skip to contentSkip to conversation

iproute2: fix build failure on sparc due to -Wformat and tv_usec

PATCH Applied Andreas Henriksson 2 participants 3 messages May 18, 2013 – Jun 25, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iproute2: fix build failure on sparc due to -Wformat and tv_usec

tv_usec is "suseconds_t" which is apparently usually a signed long, but sometimes not....
Change the printf modifier to use signed and cast the tv_usec to long in case it's not already long.

gcc -Wall -Wstrict-prototypes -Werror -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -O2 -I../include -DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib\" -DCONFDIR=\"/etc/iproute2\" -D_GNU_SOURCE -fPIC -c -o utils.o utils.c
utils.c: In function 'print_timestamp':
utils.c:802:2: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__suseconds_t' [-Werror=format]
cc1: all warnings being treated as errors

---
 lib/utils.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/utils.c +1 -1
index bcd6002..dae1b51 100644
@@ -799,7 +799,7 @@ int print_timestamp(FILE *fp)
 
 	tstr = asctime(localtime(&tv.tv_sec));
 	tstr[strlen(tstr)-1] = 0;
-	fprintf(fp, "Timestamp: %s %lu usec\n", tstr, tv.tv_usec);
+	fprintf(fp, "Timestamp: %s %ld usec\n", tstr, (long)tv.tv_usec);
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · On Sat, 18 May 2013 18:18:51 +0200 Andreas Henriksson <[email protected]> wrote:

tv_usec is "suseconds_t" which is apparently usually a signed long, but sometimes not....
Change the printf modifier to use signed and cast the tv_usec to long in case it's not already long.

Quoted 7 lines

gcc -Wall -Wstrict-prototypes -Werror -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -O2 -I../include -DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib\" -DCONFDIR=\"/etc/iproute2\" -D_GNU_SOURCE -fPIC -c -o utils.o utils.c
utils.c: In function 'print_timestamp':
utils.c:802:2: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__suseconds_t' [-Werror=format]
cc1: all warnings being treated as errors

Applied, seems like a wierd Sparc/Solaris legacy issue.

#2 lore raw
In reply to Andreas Henriksson
Quoted 11 lines · On Sat, 18 May 2013 18:18:51 +0200 Andreas Henriksson <[email protected]> wrote:

tv_usec is "suseconds_t" which is apparently usually a signed long, but sometimes not....
Change the printf modifier to use signed and cast the tv_usec to long in case it's not already long.

gcc -Wall -Wstrict-prototypes -Werror -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -O2 -I../include -DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib\" -DCONFDIR=\"/etc/iproute2\" -D_GNU_SOURCE -fPIC -c -o utils.o utils.c
utils.c: In function 'print_timestamp':
utils.c:802:2: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type '__suseconds_t' [-Werror=format]
cc1: all warnings being treated as errors

Sure applied.