# HG changeset patch # User pt # Date 1686837862 -7200 # Thu Jun 15 16:04:22 2023 +0200 # Node ID 8b4b4162570e3475b70a010fb3210932215008ee # Parent b26e66800643e827b5ec09c093f991d35a1bc412 Fix problem with returning too many or too few octave_values from VM Don't tryp to display() undefined values in cs-lists. * libinterp/parse-tree/pt-bytecode-vm.cc: diff -r b26e66800643 -r 8b4b4162570e libinterp/parse-tree/pt-bytecode-vm.cc --- a/libinterp/parse-tree/pt-bytecode-vm.cc Thu Jun 15 16:03:54 2023 +0200 +++ b/libinterp/parse-tree/pt-bytecode-vm.cc Thu Jun 15 16:04:22 2023 +0200 @@ -1104,14 +1104,23 @@ { CHECK (m_output_ignore_data == nullptr); // This can't be active + // Make a ovl with the returnvalues. + // Skip %nargout, the first value, which is an integer. + // n_returns_callee includes %nargout, but root_nargout doesn't. + octave_value_list ret; - // Skip nargout, the first value, which is an integer - for (int i = 1; i < n_returns_callee; i++) + int j; + // nargout 0 should still give one return value, if there exists one + int n_root_wanted = std::max (root_nargout, 1); + for (j = 1; j < n_returns_callee && j < (n_root_wanted + 1); j++) { - ret.append(std::move (bsp[i].ov)); - bsp[i].ov.~octave_value (); + ret.append(std::move (bsp[j].ov)); + bsp[j].ov.~octave_value (); } + // Destroy rest of return values, if any + for (; j < n_returns_callee; j++) + bsp[j].ov.~octave_value (); //Note: Stack frame object popped by caller CHECK_STACK (0); @@ -1576,7 +1585,11 @@ for (int i = 0; i < ovl.length (); i++) { - octave_value_list el_ovl = octave_value_list {ovl(i)}; + octave_value el_ov = ovl(i); + // We are not printing undefined elements + if (el_ov.is_undefined ()) + continue; + octave_value_list el_ovl = octave_value_list {el_ov}; el_ovl.stash_name_tags (string_vector ("ans")); m_tw->set_active_bytecode_ip (ip - code); // Needed if display calls inputname()