Messages in this thread | | | Subject | Re: [PATCH] net: ipv4: fix clang -Wformat warning | From | Joe Perches <> | Date | Thu, 07 Jul 2022 10:40:29 -0700 |
| |
On Thu, 2022-07-07 at 10:30 -0700, Justin Stitt wrote: > When building with Clang we encounter this warning: > > net/ipv4/ah4.c:513:4: error: format specifies type 'unsigned short' but > > the argument has type 'int' [-Werror,-Wformat] > > aalg_desc->uinfo.auth.icv_fullbits / 8); > > `aalg_desc->uinfo.auth.icv_fullbits` is a u16 but due to default > argument promotion becomes an int. > > Variadic functions (printf-like) undergo default argument promotion. > Documentation/core-api/printk-formats.rst specifically recommends using > the promoted-to-type's format flag. > > As per C11 6.3.1.1: > (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) `If an int > can represent all values of the original type ..., the value is > converted to an int; otherwise, it is converted to an unsigned int. > These are called the integer promotions.` Thus it makes sense to change > %hu to %d not only to follow this standard but to suppress the warning > as well.
I think it also makes sense to use %u and not %d as the original type is unsigned.
> diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c [] > @@ -507,7 +507,7 @@ static int ah_init_state(struct xfrm_state *x) > > if (aalg_desc->uinfo.auth.icv_fullbits/8 != > crypto_ahash_digestsize(ahash)) { > - pr_info("%s: %s digestsize %u != %hu\n", > + pr_info("%s: %s digestsize %u != %d\n", > __func__, x->aalg->alg_name, > crypto_ahash_digestsize(ahash), > aalg_desc->uinfo.auth.icv_fullbits / 8);
| |