[OpenWrt-Devel] [PATCH ucert 08/13] usign-exec: remove redundant return statements

Matthias Schiffer mschiffer at universe-factory.net
Sat May 16 17:13:58 EDT 2020


All switch() cases were already returning value or exiting. Instead,
move the default case out of the switch to reduce indentation (only
relevant for usign_f()).

Signed-off-by: Matthias Schiffer <mschiffer at universe-factory.net>
---
 usign-exec.c | 43 +++++++++++++++++--------------------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/usign-exec.c b/usign-exec.c
index 294c794b1c50..c9aecf99f9c0 100644
--- a/usign-exec.c
+++ b/usign-exec.c
@@ -76,13 +76,10 @@ int usign_s(const char *msgfile, const char *seckeyfile, const char *sigfile, bo
 		if (!quiet)
 			perror("Failed to execute usign");
 		_exit(1);
-
-	default:
-		waitpid(pid, &status, 0);
-		return WEXITSTATUS(status);
 	}
 
-	return -1;
+	waitpid(pid, &status, 0);
+	return WEXITSTATUS(status);
 }
 #else
 int usign_s(const char *msgfile, const char *seckeyfile, const char *sigfile, bool quiet) {
@@ -137,26 +134,23 @@ static int usign_f(char fingerprint[17], const char *pubkeyfile, const char *sec
 		if (!quiet)
 			perror("Failed to execute usign");
 		_exit(1);
+	}
 
-	default:
-		waitpid(pid, &status, 0);
-		status = WEXITSTATUS(status);
-		if (fingerprint && !WEXITSTATUS(status)) {
-			ssize_t r;
-			memset(fingerprint, 0, 17);
-			r = read(fds[0], fingerprint, 17);
-			if (r < 16)
-				status = -1;
+	waitpid(pid, &status, 0);
+	status = WEXITSTATUS(status);
+	if (fingerprint && !WEXITSTATUS(status)) {
+		ssize_t r;
+		memset(fingerprint, 0, 17);
+		r = read(fds[0], fingerprint, 17);
+		if (r < 16)
+			status = -1;
 
-			fingerprint[16] = '\0';
+		fingerprint[16] = '\0';
 
-		}
-		close(fds[0]);
-		close(fds[1]);
-		return status;
 	}
-
-	return -1;
+	close(fds[0]);
+	close(fds[1]);
+	return status;
 }
 
 /*
@@ -237,11 +231,8 @@ int usign_v(const char *msgfile, const char *pubkeyfile,
 		if (!quiet)
 			perror("Failed to execute usign");
 		_exit(1);
-
-	default:
-		waitpid(pid, &status, 0);
-		return WEXITSTATUS(status);
 	}
 
-	return -1;
+	waitpid(pid, &status, 0);
+	return WEXITSTATUS(status);
 }
-- 
2.26.2


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list