Skip to contentSkip to conversation

syscalls/signalfd01.c: Fix compiler warnings

PATCH New Jinhui huang 2 participants 4 messages Jul 20, 2018 – Aug 17, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/signalfd01.c: Fix compiler warnings

---
 testcases/kernel/syscalls/signalfd/signalfd01.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/signalfd/signalfd01.c +9 -9
index 9859524..0c33603 100644
@@ -76,7 +76,7 @@ int TST_TOTAL = 1;
 #endif
 
 #ifdef USE_STUB
-int main(int argc, char **argv)
+int main(void)
 {
 	tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
 }
@@ -94,7 +94,7 @@ int signalfd(int fd, const sigset_t * mask, int flags)
 void cleanup(void);
 void setup(void);
 
-int do_test1(int ntst, int sig)
+int do_test1(int sig)
 {
 	int sfd_for_next;
 	int sfd;
@@ -145,7 +145,7 @@ int do_test1(int ntst, int sig)
 	if ((s > 0) && (s != sizeof(struct signalfd_siginfo))) {
 		tst_resm(TFAIL,
 			 "getting incomplete signalfd_siginfo data: "
-			 "actual-size=%" PRId32 ", expected-size=%" PRId32,
+			 "actual-size=%zd" PRId32 ", expected-size=%ld" PRId32,
 			 s, sizeof(struct signalfd_siginfo));
 		sfd_for_next = -1;
 		close(sfd);
@@ -170,7 +170,7 @@ int do_test1(int ntst, int sig)
 		goto out;
 	}
 
-	if (fdsi.SIGNALFD_PREFIX(signo) == sig) {
+	if ((int)fdsi.SIGNALFD_PREFIX(signo) == sig) {
 		tst_resm(TPASS, "got expected signal");
 		sfd_for_next = sfd;
 		goto out;
@@ -187,7 +187,7 @@ out:
 	return sfd_for_next;
 }
 
-void do_test2(int ntst, int fd, int sig)
+void do_test2(int fd, int sig)
 {
 	int sfd;
 	sigset_t mask;
@@ -235,7 +235,7 @@ void do_test2(int ntst, int fd, int sig)
 	if ((s > 0) && (s != sizeof(struct signalfd_siginfo))) {
 		tst_resm(TFAIL,
 			 "getting incomplete signalfd_siginfo data: "
-			 "actual-size=%" PRId32 ", expected-size= %" PRId32,
+			 "actual-size=%zd" PRId32 ", expected-size= %ld" PRId32,
 			 s, sizeof(struct signalfd_siginfo));
 		goto out;
 	} else if (s < 0) {
@@ -254,7 +254,7 @@ void do_test2(int ntst, int fd, int sig)
 		goto out;
 	}
 
-	if (fdsi.SIGNALFD_PREFIX(signo) == sig) {
+	if ((int)fdsi.SIGNALFD_PREFIX(signo) == sig) {
 		tst_resm(TPASS, "got expected signal");
 		goto out;
 	} else {
@@ -285,11 +285,11 @@ int main(int argc, char **argv)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		sfd = do_test1(lc, SIGUSR1);
+		sfd = do_test1(SIGUSR1);
 		if (sfd < 0)
 			continue;
 
-		do_test2(lc, sfd, SIGUSR2);
+		do_test2(sfd, SIGUSR2);
 		close(sfd);
 	}
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 syscalls/signalfd01.c: Fix compiler warnings

Hi!

testcases/kernel/syscalls/signalfd/signalfd01.c int do_test1(int ntst, int sig) · line 149

Quoted 5 lines
testcases/kernel/syscalls/signalfd/signalfd01.c +1 -1
 		tst_resm(TFAIL,
 			 "getting incomplete signalfd_siginfo data: "
-			 "actual-size=%" PRId32 ", expected-size=%" PRId32,
+			 "actual-size=%zd" PRId32 ", expected-size=%ld" PRId32,
 			 s, sizeof(struct signalfd_siginfo));

This is obviously wrong, you have to, at least, remove the PRId32 formatting strings here. Also sizeof() returns size_t hence it should be formatted with %zu.

testcases/kernel/syscalls/signalfd/signalfd01.c int do_test1(int ntst, int sig) · line 173

Quoted 8 lines
testcases/kernel/syscalls/signalfd/signalfd01.c +1 -1
 		sfd_for_next = -1;
 		close(sfd);
@@ -170,7 +170,7 @@ int do_test1(int ntst, int sig)
 		goto out;
 	}
 
-	if (fdsi.SIGNALFD_PREFIX(signo) == sig) {
+	if ((int)fdsi.SIGNALFD_PREFIX(signo) == sig) {

Maybe it would be clearner to defined the sig to be uint32_t rathe than sprinkle the code with int casts

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH v2 1/1 syscall/signalfd01: Fix compiler warnings

---
 testcases/kernel/syscalls/signalfd/signalfd01.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/signalfd/signalfd01.c +7 -7
index 9859524..72901ff 100644
@@ -76,7 +76,7 @@ int TST_TOTAL = 1;
 #endif
 
 #ifdef USE_STUB
-int main(int argc, char **argv)
+int main(void)
 {
 	tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
 }
@@ -94,7 +94,7 @@ int signalfd(int fd, const sigset_t * mask, int flags)
 void cleanup(void);
 void setup(void);
 
-int do_test1(int ntst, int sig)
+int do_test1(uint32_t sig)
 {
 	int sfd_for_next;
 	int sfd;
@@ -145,7 +145,7 @@ int do_test1(int ntst, int sig)
 	if ((s > 0) && (s != sizeof(struct signalfd_siginfo))) {
 		tst_resm(TFAIL,
 			 "getting incomplete signalfd_siginfo data: "
-			 "actual-size=%" PRId32 ", expected-size=%" PRId32,
+			 "actual-size=%zd, expected-size=%zu",
 			 s, sizeof(struct signalfd_siginfo));
 		sfd_for_next = -1;
 		close(sfd);
@@ -187,7 +187,7 @@ out:
 	return sfd_for_next;
 }
 
-void do_test2(int ntst, int fd, int sig)
+void do_test2(int fd, uint32_t sig)
 {
 	int sfd;
 	sigset_t mask;
@@ -235,7 +235,7 @@ void do_test2(int ntst, int fd, int sig)
 	if ((s > 0) && (s != sizeof(struct signalfd_siginfo))) {
 		tst_resm(TFAIL,
 			 "getting incomplete signalfd_siginfo data: "
-			 "actual-size=%" PRId32 ", expected-size= %" PRId32,
+			 "actual-size=%zd, expected-size= %zu",
 			 s, sizeof(struct signalfd_siginfo));
 		goto out;
 	} else if (s < 0) {
@@ -285,11 +285,11 @@ int main(int argc, char **argv)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		sfd = do_test1(lc, SIGUSR1);
+		sfd = do_test1(SIGUSR1);
 		if (sfd < 0)
 			continue;
 
-		do_test2(lc, sfd, SIGUSR2);
+		do_test2(sfd, SIGUSR2);
 		close(sfd);
 	}
 
Signature · 1 line
1.8.3.1