Mercurial > octave-nkf
changeset 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 | 65e6207f7ae4 |
children | fa68a3f7dd8a |
files | libinterp/corefcn/graphics.cc libinterp/dldfcn/__osmesa_print__.cc |
diffstat | 2 files changed, 34 insertions(+), 8 deletions(-) [+] |
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);
--- a/libinterp/dldfcn/__osmesa_print__.cc Mon Mar 02 14:51:23 2015 +0100 +++ b/libinterp/dldfcn/__osmesa_print__.cc Sat Feb 28 03:44:00 2015 -0600 @@ -105,7 +105,7 @@ { if (! (args(1).is_string () && args(2).is_string ())) { - error ("__osmesa_print__: FILE and TERM has to be strings"); + error ("__osmesa_print__: FILE and TERM must be strings"); return retval; } @@ -119,7 +119,7 @@ graphics_object fobj = gh_manager::get_object (h); if (! (fobj && fobj.isa ("figure"))) { - error ("__osmesa_print__: H has to be a valid figure handle"); + error ("__osmesa_print__: H must be a valid figure handle"); return retval; } @@ -182,16 +182,23 @@ if (! error_state) { - if (! file.empty () && file[0] == '|') + 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 ("__osmesa_print__: empty output ''"); + else if (pos_c == std::string::npos) + error ("__osmesa_print__: empty pipe '|'"); + else if (pos_p != std::string::npos && pos_p < pos_c) { // create process and pipe gl2ps output to it - std::string cmd = file.substr (1); + std::string cmd = file.substr (pos_c); gl2ps_print (fobj, cmd, term); } else { // write gl2ps output directly to file - FILE *filep = gnulib::fopen (file.c_str (), "w"); + FILE *filep = gnulib::fopen (file.substr (pos_c).c_str (), "w"); if (filep) {