Fix cmdline argument check
authorMarkus Teich <markus.teich@stusta.mhn.de>
Sun, 6 Mar 2016 19:49:18 +0000 (20:49 +0100)
committerMarkus Teich <markus.teich@stusta.mhn.de>
Sun, 6 Mar 2016 19:49:18 +0000 (20:49 +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.

README.md
sent.c

index 70f60f9a46187309fe750680fba0e1d7940e3f20..3583d33edf906dee4e5319d5b17e84a9b755e833 100644 (file)
--- a/README.md
+++ b/README.md
@@ -25,12 +25,12 @@ You can navigate with the arrow keys and quit with `q`.
 
 Usage
 
-       sent FILE
+       sent [FILE]
 
-If FILE equals `-`, stdin will be read. Produce image slides by prepending a
-`@` in front of the filename as a single paragraph. Lines starting with `#` will
-be ignored. A `\` at the beginning of the line escapes `@` and `#`. A
-presentation file could look like this:
+If FILE is omitted or equals `-`, stdin will be read. Produce image slides by
+prepending a `@` in front of the filename as a single paragraph. Lines starting
+with `#` will be ignored. A `\` at the beginning of the line escapes `@` and
+`#`. A presentation file could look like this:
 
        sent
        
diff --git a/sent.c b/sent.c
index 6f5c1392db03d5573a39e9c11ef8c555a9c7651a..9ad3636e07768b67208286725d6ade37850a8229 100644 (file)
--- a/sent.c
+++ b/sent.c
@@ -689,7 +689,7 @@ void
 usage()
 {
        die("sent " VERSION " (c) 2014-2015 markus.teich@stusta.mhn.de\n" \
-       "usage: sent FILE", argv0);
+       "usage: sent [FILE]", argv0);
 }
 
 int
@@ -703,12 +703,13 @@ main(int argc, char *argv[])
                usage();
        } ARGEND;
 
-       if ((fp = strcmp(argv[0], "-") ? fopen(argv[0], "r") : stdin)) {
-               load(fp);
-               fclose(fp);
-       } else {
+       if (!argv[0] || !strcmp(argv[0], "-"))
+               fp = stdin;
+       else if (!(fp = fopen(argv[0], "r")))
                die("Unable to open '%s' for reading:", argv[0]);
-       }
+
+       load(fp);
+       fclose(fp);
 
        if (!slidecount)
                usage();