diff --git a/libinterp/corefcn/pr-output.cc b/libinterp/corefcn/pr-output.cc --- a/libinterp/corefcn/pr-output.cc +++ b/libinterp/corefcn/pr-output.cc @@ -3572,6 +3572,24 @@ set_format_style (int argc, const string int idx = 1; std::string format; + octave::unwind_protect frame; + + frame.protect_var (bank_format); + frame.protect_var (bit_format); + frame.protect_var (format); + frame.protect_var (free_format); + frame.protect_var (hex_format); + frame.protect_var (plus_format); + frame.protect_var (plus_format_chars); + frame.protect_var (print_e); + frame.protect_var (print_eng); + frame.protect_var (print_g); + frame.protect_var (rat_format); + frame.protect_var (uppercase_format); + frame.protect_var (Vcompact_format); + int prec = output_precision (); + frame.add ([prec] (void) { set_output_prec (prec); }); + argc--; if (argc == 0) { @@ -3793,6 +3811,9 @@ set_format_style (int argc, const string } format_string = format; + + // Don't reset format state if successful. + frame.discard (); } DEFUN (format, args, nargout,