changeset 19250:4b6f87c6739f gui-release

Fix out_of_range from substr in short_disp for GUI symtab (bug #43351) * ov-base-mat.cc, ov-base-scalar.cc::short_disp: Return single space if the printed string consists only of spaces.
author Andreas Weber <andy.weber.aw@gmail.com>
date Sun, 05 Oct 2014 11:36:29 +0200
parents e85203f41402
children 3978a5509f40
files libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-base-scalar.cc
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base-mat.cc	Sun Sep 28 17:30:38 2014 +0200
+++ b/libinterp/octave-value/ov-base-mat.cc	Sun Oct 05 11:36:29 2014 +0200
@@ -476,7 +476,10 @@
               octave_print_internal (buf, matrix(j*nr+i));
               std::string tmp = buf.str ();
               size_t pos = tmp.find_first_not_of (" ");
-              os << tmp.substr (pos);
+              if (pos != std::string::npos)
+                os << tmp.substr (pos);
+              else if (! tmp.empty ())
+                os << tmp[0];
 
               if (++elts >= max_elts)
                 goto done;
--- a/libinterp/octave-value/ov-base-scalar.cc	Sun Sep 28 17:30:38 2014 +0200
+++ b/libinterp/octave-value/ov-base-scalar.cc	Sun Oct 05 11:36:29 2014 +0200
@@ -176,7 +176,10 @@
   octave_print_internal (buf, scalar);
   std::string tmp = buf.str ();
   size_t pos = tmp.find_first_not_of (" ");
-  os << tmp.substr (pos);
+  if (pos != std::string::npos)
+    os << tmp.substr (pos);
+  else if (! tmp.empty ())
+    os << tmp[0];
 }
 
 template <class ST>