Re: [hackers] [sent] Fix cmdline argument check

From: Quentin Rameau <quinq_AT_fifth.space>
Date: Sun, 6 Mar 2016 10:00:46 +0100

There was a segfault when sent was called without arguments.
Now we use stdin when there's no argument or - is used.
Thanks to izabera for the report.
---
 sent.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/sent.c b/sent.c
index 6f5c139..5bd2c8e 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -703,13 +703,16 @@ main(int argc, char *argv[])
 		usage();
 	} ARGEND;
 
-	if ((fp = strcmp(argv[0], "-") ? fopen(argv[0], "r") : stdin)) {
-		load(fp);
-		fclose(fp);
+	if (argv[0] && strcmp(argv[0], "-")) {
+		if (!(fp = fopen(argv[0], "r")))
+			die("Unable to open '%s' for reading:", argv[0]);
 	} else {
-		die("Unable to open '%s' for reading:", argv[0]);
+		fp = stdin;
 	}
 
+	load(fp);
+	fclose(fp);
+
 	if (!slidecount)
 		usage();
 
-- 
2.7.2
Received on Sun Mar 06 2016 - 10:00:46 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 06 2016 - 10:12:13 CET