Skip to content

Commit e79b947

Browse files
JustinStittklassert
authored andcommitted
net: ipv4: fix clang -Wformat warnings
When building with Clang we encounter these warnings: | 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); - | net/ipv4/esp4.c:1114:5: 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. Link: ClangBuiltLinux#378 Signed-off-by: Justin Stitt <[email protected]> Suggested-by: Joe Perches <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Suggested-by: Nick Desaulniers <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent f85daf0 commit e79b947

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

net/ipv4/ah4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ static int ah_init_state(struct xfrm_state *x)
507507

508508
if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
509509
crypto_ahash_digestsize(ahash)) {
510-
pr_info("%s: %s digestsize %u != %hu\n",
510+
pr_info("%s: %s digestsize %u != %u\n",
511511
__func__, x->aalg->alg_name,
512512
crypto_ahash_digestsize(ahash),
513513
aalg_desc->uinfo.auth.icv_fullbits / 8);

net/ipv4/esp4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ static int esp_init_authenc(struct xfrm_state *x)
11081108
err = -EINVAL;
11091109
if (aalg_desc->uinfo.auth.icv_fullbits / 8 !=
11101110
crypto_aead_authsize(aead)) {
1111-
pr_info("ESP: %s digestsize %u != %hu\n",
1111+
pr_info("ESP: %s digestsize %u != %u\n",
11121112
x->aalg->alg_name,
11131113
crypto_aead_authsize(aead),
11141114
aalg_desc->uinfo.auth.icv_fullbits / 8);

0 commit comments

Comments
 (0)