diff libinterp/corefcn/graphics.cc @ 19919:e814e202cd84

Account for whitespace and other anomalies in print function pipe/file string. * graphics.cc (Fdrawnow): Use two positions from standard string finds to address all whitespace and improper syntax in "file" variable, the first "|" character and the first non "| " character. * __osmesa_print__.cc (F__osmesa_print__): Ditto.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Sat, 28 Feb 2015 03:44:00 -0600
parents 6b7aee95c54c
children 0c32e02d60c3
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Mon Mar 02 14:51:23 2015 +0100
+++ b/libinterp/corefcn/graphics.cc	Sat Feb 28 03:44:00 2015 -0600
@@ -11069,15 +11069,34 @@
 
               if (! error_state)
                 {
-                  if (! file.empty () && file[0] == '|')
-                    file = file.substr (1);  // Strip leading pipe character
+                  size_t pos_p = file.find_first_of ("|");
+                  size_t pos_c = file.find_first_not_of ("| ");
+
+                  if (pos_p == std::string::npos &&
+                      pos_c == std::string::npos)
+                    {
+                      error ("drawnow: empty output ''");
+
+                      return retval;
+                    }
+                  else if (pos_c == std::string::npos)
+                    {
+                      error ("drawnow: empty pipe '|'");
+
+                      return retval;
+                    }
+                  else if (pos_p != std::string::npos && pos_p < pos_c)
+                    {
+                      // Strip leading pipe character
+                      file = file.substr (pos_c);
+                    }
                   else
                     {
                       size_t pos = file.find_last_of (file_ops::dir_sep_chars ());
 
                       if (pos != std::string::npos)
                         {
-                          std::string dirname = file.substr (0, pos+1);
+                          std::string dirname = file.substr (pos_c, pos+1);
 
                           file_stat fs (dirname);