[PATCH] remove redundand address check in struct stat printing functions

Denys Vlasenko dvlasenk at redhat.com
Mon Apr 20 18:46:22 UTC 2009


Hi,

Various struct stat printing functions have duplicate
tests and printing code for NULL/invalid address.
We can remove this check from printstatsol, printstat_sparc64,
because callers (printoldstat, printstat, printoldstat64)
already do it, it only needs to be moved up a bit there.
--
vda



diff -d -urpN strace.3/file.c strace.4/file.c
--- strace.3/file.c	2009-04-20 18:07:34.000000000 +0200
+++ strace.4/file.c	2009-04-20 17:58:22.000000000 +0200
@@ -779,14 +779,6 @@ printstatsol(struct tcb *tcp, long addr)
 {
 	struct solstat statbuf;
 
-	if (!addr) {
-		tprintf("NULL");
-		return;
-	}
-	if (syserror(tcp) || !verbose(tcp)) {
-		tprintf("%#lx", addr);
-		return;
-	}
 	if (umove(tcp, addr, &statbuf) < 0) {
 		tprintf("{...}");
 		return;
@@ -831,14 +823,6 @@ printstat_sparc64(struct tcb *tcp, long 
 {
 	struct stat_sparc64 statbuf;
 
-	if (!addr) {
-		tprintf("NULL");
-		return;
-	}
-	if (syserror(tcp) || !verbose(tcp)) {
-		tprintf("%#lx", addr);
-		return;
-	}
 	if (umove(tcp, addr, &statbuf) < 0) {
 		tprintf("{...}");
 		return;
@@ -1024,28 +1008,28 @@ printstat(struct tcb *tcp, long addr)
 {
 	struct stat statbuf;
 
+	if (!addr) {
+		tprintf("NULL");
+		return;
+	}
+	if (syserror(tcp) || !verbose(tcp)) {
+		tprintf("%#lx", addr);
+		return;
+	}
+
 #ifdef LINUXSPARC
 	if (current_personality == 1) {
 		printstatsol(tcp, addr);
 		return;
 	}
-#ifdef SPARC64
+# ifdef SPARC64
 	else if (current_personality == 2) {
 		printstat_sparc64(tcp, addr);
 		return;
 	}
-#endif
+# endif
 #endif /* LINUXSPARC */
 
-	if (!addr) {
-		tprintf("NULL");
-		return;
-	}
-	if (syserror(tcp) || !verbose(tcp)) {
-		tprintf("%#lx", addr);
-		return;
-	}
-
 #if defined(S390X)
 	if (current_personality == 1) {
 		struct compat_stat compat_statbuf;
@@ -1120,31 +1104,32 @@ printstat64(struct tcb *tcp, long addr)
 {
 	struct stat64 statbuf;
 
-#ifdef	STAT64_SIZE
+#ifdef STAT64_SIZE
 	(void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
 #endif
 
+	if (!addr) {
+		tprintf("NULL");
+		return;
+	}
+	if (syserror(tcp) || !verbose(tcp)) {
+		tprintf("%#lx", addr);
+		return;
+	}
+
 #ifdef LINUXSPARC
 	if (current_personality == 1) {
 		printstatsol(tcp, addr);
 		return;
 	}
-#ifdef SPARC64
+# ifdef SPARC64
 	else if (current_personality == 2) {
 		printstat_sparc64(tcp, addr);
 		return;
 	}
-#endif
+# endif
 #endif /* LINUXSPARC */
 
-	if (!addr) {
-		tprintf("NULL");
-		return;
-	}
-	if (syserror(tcp) || !verbose(tcp)) {
-		tprintf("%#lx", addr);
-		return;
-	}
 	if (umove(tcp, addr, &statbuf) < 0) {
 		tprintf("{...}");
 		return;
@@ -1252,13 +1237,6 @@ printoldstat(struct tcb *tcp, long addr)
 	struct __old_kernel_stat statbuf;
 	struct stat newstatbuf;
 
-#ifdef LINUXSPARC
-	if (current_personality == 1) {
-		printstatsol(tcp, addr);
-		return;
-	}
-#endif /* LINUXSPARC */
-
 	if (!addr) {
 		tprintf("NULL");
 		return;
@@ -1267,6 +1245,14 @@ printoldstat(struct tcb *tcp, long addr)
 		tprintf("%#lx", addr);
 		return;
 	}
+
+#ifdef LINUXSPARC
+	if (current_personality == 1) {
+		printstatsol(tcp, addr);
+		return;
+	}
+#endif /* LINUXSPARC */
+
 	if (umove(tcp, addr, &statbuf) < 0) {
 		tprintf("{...}");
 		return;






More information about the Strace-devel mailing list