diff options
author | Aaron Gyes <me@aaron.gy> | 2016-06-10 07:39:05 -0700 |
---|---|---|
committer | Aaron Gyes <me@aaron.gy> | 2016-06-10 08:02:12 -0700 |
commit | c4e322d3ad04fbaa9d33bfbb086a7d387011da5e (patch) | |
tree | b29b1f93355464525460fe482bd33ef3be2ce181 | |
parent | 222a07e907c239f7dab541512b109730a07828dc (diff) |
Fix crash when fish_indent is using stdin with -w
When given no path, the logic was happy to try to use
an unitialized output_location.
$ fish_indent -w < test.fish
Opening "(null)" failed: Bad address
Initialize the string, and repair the logic to catch this case
and report the problem correctly.
-rw-r--r-- | src/fish_indent.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index cab9df03..67201975 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -348,7 +348,7 @@ int main(int argc, char *argv[]) { output_type_ansi, output_type_html } output_type = output_type_plain_text; - const char *output_location; + const char *output_location = ""; bool do_indent = true; const char *short_opts = "+dhvwi"; @@ -410,6 +410,10 @@ int main(int argc, char *argv[]) { wcstring src; if (argc == 0) { src = read_file(stdin); + if (output_type == output_type_file) { + fwprintf(stderr, _(L"You cannot use -w without providing the path to read from and write to.")); + exit(1); + } } else if (argc == 1) { FILE *fh = fopen(*argv, "r"); if (fh) { |