diff mbox series

tools/locktest: Use intmax_t to print off_t

Message ID 20230726065653.1336464-1-raj.khem@gmail.com (mailing list archive)
State New, archived
Headers show
Series tools/locktest: Use intmax_t to print off_t | expand

Commit Message

Khem Raj July 26, 2023, 6:56 a.m. UTC
off_t could be 64bit on 32bit architectures which means using %z printf
modifier is not enough to print it and compiler will complain about
format mismatch

Fixes
| testlk.c:84:66: error: format '%zd' expects argument of type 'signed size_t', but argument 4 has type '__off64_t' {aka 'long long int'} [-Werror=format=]
|    84 |                         printf("%s: conflicting lock by %d on (%zd;%zd)\n",
|       |                                                                ~~^
|       |                                                                  |
|       |                                                                  int
|       |                                                                %lld
|    85 |                                 fname, fl.l_pid, fl.l_start, fl.l_len);
|       |                                                  ~~~~~~~~~~
|       |                                                    |
|       |                                                    __off64_t {aka long long int}

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 tools/locktest/testlk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/locktest/testlk.c b/tools/locktest/testlk.c
index ea51f788..9d4c88c4 100644
--- a/tools/locktest/testlk.c
+++ b/tools/locktest/testlk.c
@@ -2,6 +2,7 @@ 
 #include <config.h>
 #endif
 
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -81,8 +82,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 (%jd;%jd)\n",
+				fname, fl.l_pid, (intmax_t)fl.l_start, (intmax_t)fl.l_len);
 		}
 		return 0;
 	}