# HG changeset patch # User Avinoam Kalma # Date 1485808958 -3600 # Node ID 46b914a213db939d750acead908d717427c0d694 # Parent 8cb4a2c07bce14a14475c2e969e8caf709c3476d Workaround segfault when an error occurs while printing (bug #49779) * print.m: check early that the requested directory exists and the requested file is writable * __print_parse_opts__.m: error out if the specified device/extension is unknown diff -r 8cb4a2c07bce -r 46b914a213db scripts/plot/util/print.m --- a/scripts/plot/util/print.m Wed Jan 25 16:08:52 2017 -0800 +++ b/scripts/plot/util/print.m Mon Jan 30 21:42:38 2017 +0100 @@ -314,6 +314,18 @@ opts = __print_parse_opts__ (varargin{:}); + folder = fileparts (opts.name); + if (! isempty (folder) && ! exist (folder,"dir")) + error ("print: directory %s does not exist", folder); + endif + + fid = fopen (opts.name, "w+"); + if (fid == -1) + error ("print: cannot open file %s for writing", opts.name); + endif + fclose (fid); + unlink (opts.name); + opts.pstoedit_cmd = @pstoedit; opts.fig2dev_cmd = @fig2dev; opts.latex_standalone = @latex_standalone; diff -r 8cb4a2c07bce -r 46b914a213db scripts/plot/util/private/__print_parse_opts__.m --- a/scripts/plot/util/private/__print_parse_opts__.m Wed Jan 25 16:08:52 2017 -0800 +++ b/scripts/plot/util/private/__print_parse_opts__.m Mon Jan 30 21:42:38 2017 +0100 @@ -262,7 +262,7 @@ if (any (match)) default_suffix = suffixes{match}; else - default_suffix = arg_st.devopt; + error ("print: unknown device %s", arg_st.devopt); endif if (dot == 0 && ! isempty (arg_st.name))