Skip to contentSkip to conversation

builtin-fmt-merge-msg: fix bugs in --file option

PATCH New Michael Coleman 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 builtin-fmt-merge-msg: fix bugs in --file option

If --file's argument is missing, don't crash. If it cannot be opened, die with an error message.

---
 builtin-fmt-merge-msg.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
builtin-fmt-merge-msg.c +3 -1
index 1489883..5c145d2 100644
@@ -259,13 +259,15 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 		else if (!strcmp(argv[1], "--no-summary"))
 			merge_summary = 0;
 		else if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--file")) {
-			if (argc < 2)
+			if (argc < 3)
 				die ("Which file?");
 			if (!strcmp(argv[2], "-"))
 				in = stdin;
 			else {
 				fclose(in);
 				in = fopen(argv[2], "r");
+				if (!in)
+					die("cannot open %s", argv[2]);
 			}
 			argc--; argv++;
 		} else
Signature · 1 line
1.5.0.rc3