diff mbox series

[nfs-utils,v2,2/2] testlk: format off_t as llong instead of ssize_t

Message ID 9d2b8bdc146a1fb48b391ae1adda0b6249ba9c5b.1700601199.git.nabijaczleweli@nabijaczleweli.xyz (mailing list archive)
State New
Headers show
Series [nfs-utils,v2,1/2] fsidd: call anonymous sockets by their name only, don't fill with NULs to 108 bytes | expand

Commit Message

Ahelenia Ziemiańska Nov. 21, 2023, 9:15 p.m. UTC
This, naturally, produces a warning on x32 (and other ILP32 platforms
with 64-bit off_t, presumably, but you need to ask for it explicitly
there usually):
gcc -DHAVE_CONFIG_H -I. -I../../support/include  -D_GNU_SOURCE -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -c -o testlk-testlk.o `test -f 'testlk.c' || echo './'`testlk.c
testlk.c: In function ‘main’:
testlk.c:84:66: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
   84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
      |                                                                ~~^
      |                                                                  |
      |                                                                  int
      |                                                                %lld
   85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
      |                                                  ~~~~~~~~~~
      |                                                    |
      |                                                    __off_t {aka long long int}
testlk.c:84:70: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 5 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
   84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
      |                                                                    ~~^
      |                                                                      |
      |                                                                      int
      |                                                                    %lld
   85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
      |                                                              ~~~~~~~~
      |                                                                |
      |                                                                __off_t {aka long long int}

Upcast to long long, doesn't really matter.

It does, of course, raise the question of whether other bits of
nfs-utils do something equally broken that just isn't caught by the
format validator.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
---
Same as v1: <44adec629186e220ee5d8fd936980ac4a33dc510.1693754442.git.nabijaczleweli@nabijaczleweli.xyz>

 tools/locktest/testlk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

NeilBrown Nov. 21, 2023, 9:19 p.m. UTC | #1
On Wed, 22 Nov 2023, Ahelenia Ziemiańska wrote:
> This, naturally, produces a warning on x32 (and other ILP32 platforms
> with 64-bit off_t, presumably, but you need to ask for it explicitly
> there usually):
> gcc -DHAVE_CONFIG_H -I. -I../../support/include  -D_GNU_SOURCE -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -c -o testlk-testlk.o `test -f 'testlk.c' || echo './'`testlk.c
> testlk.c: In function ‘main’:
> testlk.c:84:66: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
>    84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
>       |                                                                ~~^
>       |                                                                  |
>       |                                                                  int
>       |                                                                %lld
>    85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
>       |                                                  ~~~~~~~~~~
>       |                                                    |
>       |                                                    __off_t {aka long long int}
> testlk.c:84:70: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 5 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
>    84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
>       |                                                                    ~~^
>       |                                                                      |
>       |                                                                      int
>       |                                                                    %lld
>    85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
>       |                                                              ~~~~~~~~
>       |                                                                |
>       |                                                                __off_t {aka long long int}
> 
> Upcast to long long, doesn't really matter.
> 
> It does, of course, raise the question of whether other bits of
> nfs-utils do something equally broken that just isn't caught by the
> format validator.
> 
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
> ---
> Same as v1: <44adec629186e220ee5d8fd936980ac4a33dc510.1693754442.git.nabijaczleweli@nabijaczleweli.xyz>
> 
>  tools/locktest/testlk.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/locktest/testlk.c b/tools/locktest/testlk.c
> index ea51f788..c9bd6bac 100644
> --- a/tools/locktest/testlk.c
> +++ b/tools/locktest/testlk.c
> @@ -81,8 +81,8 @@ main(int argc, char **argv)
>  		if (fl.l_type == F_UNLCK) {
>  			printf("%s: no conflicting lock\n", fname);
>  		} else {
> -			printf("%s: conflicting lock by %d on (%zd;%zd)\n",
> -				fname, fl.l_pid, fl.l_start, fl.l_len);
> +			printf("%s: conflicting lock by %d on (%lld;%lld)\n",
> +				fname, fl.l_pid, (long long)fl.l_start, (long long)fl.l_len);
>  		}
>  		return 0;
>  	}
> -- 
> 2.39.2
> 

Reviewed-by: NeilBrown <neilb@suse.de>

Thanks,
NeilBrown
Steve Dickson Nov. 29, 2023, 12:34 p.m. UTC | #2
On 11/21/23 4:15 PM, Ahelenia Ziemiańska wrote:
> This, naturally, produces a warning on x32 (and other ILP32 platforms
> with 64-bit off_t, presumably, but you need to ask for it explicitly
> there usually):
> gcc -DHAVE_CONFIG_H -I. -I../../support/include  -D_GNU_SOURCE -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -ffile-prefix-map=/tmp/nfs-utils-2.6.3=. -specs=/usr/share/dpkg/pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -c -o testlk-testlk.o `test -f 'testlk.c' || echo './'`testlk.c
> testlk.c: In function ‘main’:
> testlk.c:84:66: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 4 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
>     84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
>        |                                                                ~~^
>        |                                                                  |
>        |                                                                  int
>        |                                                                %lld
>     85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
>        |                                                  ~~~~~~~~~~
>        |                                                    |
>        |                                                    __off_t {aka long long int}
> testlk.c:84:70: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 5 has type ‘__off_t’ {aka ‘long long int’} [-Wformat=]
>     84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
>        |                                                                    ~~^
>        |                                                                      |
>        |                                                                      int
>        |                                                                    %lld
>     85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
>        |                                                              ~~~~~~~~
>        |                                                                |
>        |                                                                __off_t {aka long long int}
> 
> Upcast to long long, doesn't really matter.
> 
> It does, of course, raise the question of whether other bits of
> nfs-utils do something equally broken that just isn't caught by the
> format validator.
> 
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Committed... (tag: nfs-utils-2-7-1-rc1)

steved
> ---
> Same as v1: <44adec629186e220ee5d8fd936980ac4a33dc510.1693754442.git.nabijaczleweli@nabijaczleweli.xyz>
> 
>   tools/locktest/testlk.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/locktest/testlk.c b/tools/locktest/testlk.c
> index ea51f788..c9bd6bac 100644
> --- a/tools/locktest/testlk.c
> +++ b/tools/locktest/testlk.c
> @@ -81,8 +81,8 @@ main(int argc, char **argv)
>   		if (fl.l_type == F_UNLCK) {
>   			printf("%s: no conflicting lock\n", fname);
>   		} else {
> -			printf("%s: conflicting lock by %d on (%zd;%zd)\n",
> -				fname, fl.l_pid, fl.l_start, fl.l_len);
> +			printf("%s: conflicting lock by %d on (%lld;%lld)\n",
> +				fname, fl.l_pid, (long long)fl.l_start, (long long)fl.l_len);
>   		}
>   		return 0;
>   	}
diff mbox series

Patch

diff --git a/tools/locktest/testlk.c b/tools/locktest/testlk.c
index ea51f788..c9bd6bac 100644
--- a/tools/locktest/testlk.c
+++ b/tools/locktest/testlk.c
@@ -81,8 +81,8 @@  main(int argc, char **argv)
 		if (fl.l_type == F_UNLCK) {
 			printf("%s: no conflicting lock\n", fname);
 		} else {
-			printf("%s: conflicting lock by %d on (%zd;%zd)\n",
-				fname, fl.l_pid, fl.l_start, fl.l_len);
+			printf("%s: conflicting lock by %d on (%lld;%lld)\n",
+				fname, fl.l_pid, (long long)fl.l_start, (long long)fl.l_len);
 		}
 		return 0;
 	}