[hackers] [sent] Fix cmdline argument check || Markus Teich
commit b954ed4b9f1ef7e3d4ebb3bc964338726549bfab
Author: Markus Teich <markus.teich_AT_stusta.mhn.de>
AuthorDate: Sun Mar 6 20:49:18 2016 +0100
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Sun Mar 6 20:49:18 2016 +0100
Fix cmdline argument check
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.
diff --git a/README.md b/README.md
index 70f60f9..3583d33 100644
--- a/README.md
+++ b/README.md
_AT_@ -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
-`_AT_` in front of the filename as a single paragraph. Lines starting with `#` will
-be ignored. A `\` at the beginning of the line escapes `_AT_` and `#`. A
-presentation file could look like this:
+If FILE is omitted or equals `-`, stdin will be read. Produce image slides by
+prepending a `_AT_` in front of the filename as a single paragraph. Lines starting
+with `#` will be ignored. A `\` at the beginning of the line escapes `_AT_` and
+`#`. A presentation file could look like this:
sent
diff --git a/sent.c b/sent.c
index 6f5c139..9ad3636 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -689,7 +689,7 @@ void
usage()
{
die("sent " VERSION " (c) 2014-2015 markus.teich_AT_stusta.mhn.de\n" \
- "usage: sent FILE", argv0);
+ "usage: sent [FILE]", argv0);
}
int
_AT_@ -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();
Received on Sun Mar 06 2016 - 20:53:05 CET
This archive was generated by hypermail 2.3.0
: Sun Mar 06 2016 - 21:00:17 CET