Skip to contentSkip to conversation

syscalls: Fix tst_res() format string for 64-bit offset

PATCH Superseded Randolph Lin 2 participants 3 messages Sep 7, 2022 – Sep 13, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls: Fix tst_res() format string for 64-bit offset

From: Mina Hui-Min Chou <[email protected]>

When compiling as 32-bit with _FILE_OFFSET_BITS=64, the format string needs to be specified as 64-bit long (%lld).
Fix format string for type block_size.

ref:
https://github.com/linux-test-project/ltp/commit/98e25434db561e69624bc34b0fab456ca2e501ea

---
 testcases/kernel/syscalls/lseek/lseek01.c       | 8 ++++----
 testcases/kernel/syscalls/lseek/lseek07.c       | 8 ++++----
 testcases/kernel/syscalls/lseek/lseek11.c       | 6 +++---
 testcases/kernel/syscalls/sendfile/sendfile05.c | 2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/lseek/lseek01.c +4 -4
index 22d9fbfd7..db973d7c4 100644
@@ -46,13 +46,13 @@ static void verify_lseek(unsigned int n)
 
 	TEST(lseek(fd, tc->off, tc->whence));
 	if (TST_RET == (off_t) -1) {
-		tst_res(TFAIL | TTERRNO, "lseek(%s, %ld, %s) failed", TFILE,
+		tst_res(TFAIL | TTERRNO, "lseek(%s, %lld, %s) failed", TFILE,
 			tc->off, tc->wname);
 		return;
 	}
 
 	if (TST_RET != tc->exp_off) {
-		tst_res(TFAIL, "lseek(%s, %ld, %s) returned %ld, expected %ld",
+		tst_res(TFAIL, "lseek(%s, %lld, %s) returned %ld, expected %lld",
 			TFILE, tc->off, tc->wname, TST_RET, tc->exp_off);
 		return;
 	}
@@ -60,10 +60,10 @@ static void verify_lseek(unsigned int n)
 	SAFE_READ(1, fd, read_buf, tc->exp_size);
 
 	if (tc->exp_data && strcmp(read_buf, tc->exp_data)) {
-		tst_res(TFAIL, "lseek(%s, %ld, %s) read incorrect data",
+		tst_res(TFAIL, "lseek(%s, %lld, %s) read incorrect data",
 			TFILE, tc->off, tc->wname);
 	} else {
-		tst_res(TPASS, "lseek(%s, %ld, %s) read correct data",
+		tst_res(TPASS, "lseek(%s, %lld, %s) read correct data",
 			TFILE, tc->off, tc->wname);
 	}
 }
testcases/kernel/syscalls/lseek/lseek07.c +4 -4
index ae6f48f37..e35d5c772 100644
@@ -43,13 +43,13 @@ static void verify_lseek(unsigned int n)
 
 	TEST(lseek(*tc->fd, tc->off, SEEK_SET));
 	if (TST_RET == (off_t) -1) {
-		tst_res(TFAIL | TTERRNO, "lseek(%s, %ld, SEEK_SET) failed",
+		tst_res(TFAIL | TTERRNO, "lseek(%s, %lld, SEEK_SET) failed",
 			tc->fname, tc->off);
 		return;
 	}
 
 	if (TST_RET != tc->exp_off) {
-		tst_res(TFAIL, "lseek(%s, %ld, SEEK_SET) returned %ld, expected %ld",
+		tst_res(TFAIL, "lseek(%s, %lld, SEEK_SET) returned %ld, expected %lld",
 			tc->fname, tc->off, TST_RET, tc->exp_off);
 		return;
 	}
@@ -63,10 +63,10 @@ static void verify_lseek(unsigned int n)
 	SAFE_READ(1, *tc->fd, read_buf, tc->exp_size);
 
 	if (strcmp(read_buf, tc->exp_data)) {
-		tst_res(TFAIL, "lseek(%s, %ld, SEEK_SET) wrote incorrect data %s",
+		tst_res(TFAIL, "lseek(%s, %lld, SEEK_SET) wrote incorrect data %s",
 			tc->fname, tc->off, read_buf);
 	} else {
-		tst_res(TPASS, "lseek(%s, %ld, SEEK_SET) wrote correct data %s",
+		tst_res(TPASS, "lseek(%s, %lld, SEEK_SET) wrote correct data %s",
 			tc->fname, tc->off, read_buf);
 	}
 }
testcases/kernel/syscalls/lseek/lseek11.c +3 -3
index 14435f617..1292ae165 100644
@@ -159,7 +159,7 @@ static void setup(void)
 	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0666);
 
 	get_blocksize();
-	tst_res(TINFO, "The block size is %lu", block_size);
+	tst_res(TINFO, "The block size is %d", block_size);
 
 	/*
 	 * truncate to the expected file size directly, to keep away the effect
@@ -202,12 +202,12 @@ static void test_lseek(unsigned int n)
 
 	if (rc != 0) {
 		tst_res(TFAIL,
-		        "The %uth test failed: %s from startblock %ld offset %ld, expect \'%s\' return \'%s\'",
+		        "The %uth test failed: %s from startblock %lld offset %lld, expect \'%s\' return \'%s\'",
 		        n, (tp->whence == SEEK_DATA) ? "SEEK_DATA" : "SEEK_HOLE",
 		        tp->startblock, tp->offset, tp->data ? tp->data : "", buf);
 	} else {
 		tst_res(TPASS,
-		        "The %uth test passed: %s from startblock %ld offset %ld",
+		        "The %uth test passed: %s from startblock %lld offset %lld",
 		        n, (tp->whence == SEEK_DATA) ? "SEEK_DATA" : "SEEK_HOLE",
 		        tp->startblock, tp->offset);
 	}
testcases/kernel/syscalls/sendfile/sendfile05.c +1 -1
index e271a47d4..1b1dd8f00 100644
@@ -39,7 +39,7 @@ static void run(void)
 	off_t offset = -1;
 
 	TST_EXP_FAIL(sendfile(out_fd, in_fd, &offset, 1), EINVAL,
-		     "sendfile(out, in, &offset, ..) with offset=%ld", offset);
+		     "sendfile(out, in, &offset, ..) with offset=%lld", offset);
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 3 lines

When compiling as 32-bit with _FILE_OFFSET_BITS=64, the format string needs to be specified as 64-bit long (%lld).
Fix format string for type block_size.

This change introduces warnings on 64bit platform instead. Unfortunatelly unlike the size_t and ssize_t which can be printed with %zu and %zi there is no such thing for off_t. So the only way how to actually print off_t correctly is to cast it to (long long int) in addintion to changing the format string to %lli or %lld.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Cyril Hrubis,
Thanks for your suggestion.
We will follow your comment to do the cast for off_t, and test on 64/32bit system. After test pass, we will send patch v2.

Randolph
Sincerely

Quoted 11 lines

Hi!

Quoted 3 lines

When compiling as 32-bit with _FILE_OFFSET_BITS=64, the format string needs to be specified as 64-bit long (%lld).
Fix format string for type block_size.

This change introduces warnings on 64bit platform instead. Unfortunatelly unlike the size_t and ssize_t which can be printed with %zu and %zi there is no such thing for off_t. So the only way how to actually print off_t correctly is to cast it to (long long int) in addintion to changing the format string to %lli or %lld.

Quoted 3 lines

--
Cyril Hrubis
[email protected]

CONFIDENTIALITY NOTICE:

This e-mail (and its attachments) may contain confidential and legally privileged information or information protected from disclosure. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein is strictly prohibited. In this case, please immediately notify the sender by return e-mail, delete the message (and any accompanying documents) and destroy all printed hard copies. Thank you for your cooperation.

Copyright ANDES TECHNOLOGY CORPORATION - All Rights Reserved.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp