[Intel-wired-lan] [PATCH 1/4] ixgbe: Resolve truncation warning for q_vector->name

Bowers, AndrewX andrewx.bowers at intel.com
Wed May 17 21:50:22 UTC 2017


> -----Original Message-----
> From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On
> Behalf Of Tony Nguyen
> Sent: Friday, May 12, 2017 11:38 AM
> To: intel-wired-lan at lists.osuosl.org
> Subject: [Intel-wired-lan] [PATCH 1/4] ixgbe: Resolve truncation warning for
> q_vector->name
> 
> The following warning is now shown as a result of new checks added for gcc
> 7:
> 
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c: In function ‘ixgbe_open’:
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3118:13: warning: ‘%d’
> directive output may be truncated writing between 1 and 10 bytes into a
> region of size between 3 and 18 [-Wformat-truncation=]
>       "%s-%s-%d", netdev->name, "TxRx", ri++);
>              ^~
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3118:6: note: directive
> argument in the range [0, 2147483647]
>       "%s-%s-%d", netdev->name, "TxRx", ri++);
>       ^~~~~~~~~~
> drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:3117:4: note: ‘snprintf’
> output between 8 and 32 bytes into a destination of size 24
>     snprintf(q_vector->name, sizeof(q_vector->name) - 1,
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       "%s-%s-%d", netdev->name, "TxRx", ri++);
>       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Resolve this warning by making a couple of changes.
>  - Don't reserve space for the null terminator.  Since snprintf adds the
>    null terminator automatically, there is no need for us to reserve a byte
>    for it.
> 
>  - Change a couple variables that can never be negative from int to
>    unsigned int.
> 
> While we're making changes to the format string, move the constant strings
> into the format string instead of providing them as specifiers.
> 
> Signed-off-by: Tony Nguyen <anthony.l.nguyen at intel.com>
> ---
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Tested-by: Andrew Bowers <andrewx.bowers at intel.com>




More information about the Intel-wired-lan mailing list