Page MenuHomeFreeBSD

Fix printf format warning in iflib.c
ClosedPublic

Authored by dim on Jul 20 2017, 7:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 29, 8:41 PM
Unknown Object (File)
May 9 2024, 8:01 PM
Unknown Object (File)
Feb 11 2024, 11:18 PM
Unknown Object (File)
Feb 6 2024, 12:28 PM
Unknown Object (File)
Dec 29 2023, 2:51 AM
Unknown Object (File)
Dec 20 2023, 3:07 AM
Unknown Object (File)
Nov 21 2023, 1:44 AM
Unknown Object (File)
Aug 31 2023, 1:31 PM
Subscribers

Details

Summary

Clang 5.0.0 got better warnings about printf format strings using %zd,
and this leads to the following -Werror warning on arm:

sys/net/iflib.c:1517:8: error: format specifies type 'ssize_t' (aka 'int') but the argument has type 'bus_size_t' (aka 'unsigned long') [-Werror,-Wformat]
                                          sctx->isc_tx_maxsize, nsegments, sctx->isc_tx_maxsegsize);
                                          ^~~~~~~~~~~~~~~~~~~~
sys/net/iflib.c:1517:41: error: format specifies type 'ssize_t' (aka 'int') but the argument has type 'bus_size_t' (aka 'unsigned long') [-Werror,-Wformat]
                                          sctx->isc_tx_maxsize, nsegments, sctx->isc_tx_maxsegsize);
                                                                           ^~~~~~~~~~~~~~~~~~~~~~~

Fix this by casting bus_size_t arguments to uintmax_t, and using
%ju instead.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dim retitled this revision from Summary: to Fix printf format warning in iflib.c.Jul 20 2017, 7:36 PM

aside, there's come crazy whitespace going on in iflib.c

What about an (unsigned long) cast and %lu? Since bus_size_t is already unsigned long that seems to be reasonable, and doesn't require an unnecessary 64-bit value on ILP32 archs.

This revision is now accepted and ready to land.Jul 20 2017, 8:08 PM

aside, there's come crazy whitespace going on in iflib.c

Yes, I thought to use the default 4 space continuation indent instead.

What about an (unsigned long) cast and %lu? Since bus_size_t is already unsigned long that seems to be reasonable, and doesn't require an unnecessary 64-bit value on ILP32 archs.

As discussed on irc, not all arches use unsigned long, unfortunately:

sys/amd64/include/_bus.h: typedef uint64_t bus_size_t;
sys/arm/include/_bus.h: typedef u_long bus_size_t;
sys/arm64/include/_bus.h: typedef u_long bus_size_t;
sys/i386/include/_bus.h: typedef uint32_t bus_size_t;
sys/mips/include/_bus.h: typedef uintptr_t bus_size_t;
sys/powerpc/include/_bus.h: typedef vm_size_t bus_size_t;
sys/riscv/include/_bus.h: typedef u_long bus_size_t;
sys/sparc64/include/_bus.h: typedef u_long bus_size_t;
This revision was automatically updated to reflect the committed changes.