changeset 19906:ed5ee3f610db

Correct tests using std::string::find_XXX which did not use std::string::npos. * symtab.cc (find_function): For old-style class syntax, avoid setting method == dispatch if there is no dir_sep_str. * __osmesa_print__.cc: Correctly check for pipe command versus filename. * audioread.cc: Correctly find extension of file after '.'.
author Rik <rik@octave.org>
date Fri, 27 Feb 2015 09:31:11 -0800
parents 815db217f6f4
children d575cd1e0da7
files libinterp/corefcn/symtab.cc libinterp/dldfcn/__osmesa_print__.cc libinterp/dldfcn/audioread.cc
diffstat 3 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symtab.cc	Fri Feb 27 11:24:12 2015 -0500
+++ b/libinterp/corefcn/symtab.cc	Fri Feb 27 09:31:11 2015 -0800
@@ -1280,9 +1280,10 @@
       std::string dispatch_type =
         name.substr (1, name.find_first_of (file_ops::dir_sep_str ()) - 1);
 
-      std::string method =
-        name.substr (name.find_last_of (file_ops::dir_sep_str ()) + 1,
-                     std::string::npos);
+      std::string method;
+      size_t pos = name.find_last_of (file_ops::dir_sep_str ());
+      if (pos != std::string::npos)
+        method = name.substr (pos + 1);
 
       retval = find_method (method, dispatch_type);
     }
--- a/libinterp/dldfcn/__osmesa_print__.cc	Fri Feb 27 11:24:12 2015 -0500
+++ b/libinterp/dldfcn/__osmesa_print__.cc	Fri Feb 27 09:31:11 2015 -0800
@@ -183,7 +183,7 @@
       if (! error_state)
         {
           size_t pos = file.find_first_not_of ("|");
-          if (pos > 0)
+          if (pos != std::string::npos)
             {
               // create process and pipe gl2ps output to it
               std::string cmd = file.substr (pos);
--- a/libinterp/dldfcn/audioread.cc	Fri Feb 27 11:24:12 2015 -0500
+++ b/libinterp/dldfcn/audioread.cc	Fri Feb 27 09:31:11 2015 -0800
@@ -331,7 +331,10 @@
   if (error_state)
     return retval;
 
-  std::string ext = filename.substr (filename.find_last_of (".") + 1);
+  std::string ext;
+  std::size_t dotpos = filename.find_last_of (".");
+  if (dotpos != std::string::npos)
+    ext = filename.substr (dotpos + 1);
   std::transform (ext.begin (), ext.end (), ext.begin (), ::tolower);
 
   sf_count_t items_to_write = audio.rows () * audio.columns ();