From c4e322d3ad04fbaa9d33bfbb086a7d387011da5e Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Fri, 10 Jun 2016 07:39:05 -0700 Subject: 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. --- src/fish_indent.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) { -- cgit v1.2.3