diff scripts/ode/ode15i.m @ 28041:5e44268dca6f

Replace input validation relying on str2func with alternatives (bug #57351). * ode15i.m, ode15s.m, ode23.m, ode45.m, check_default_input.m: Replace try/catch blocks around str2func with a call to exist() to check whether function exists before calling str2func.
author Rik <rik@octave.org>
date Mon, 03 Feb 2020 20:22:19 -0800
parents c20b7290c778
children ace8dc642e4d
line wrap: on
line diff
--- a/scripts/ode/ode15i.m	Mon Feb 03 13:46:20 2020 -0800
+++ b/scripts/ode/ode15i.m	Mon Feb 03 20:22:19 2020 -0800
@@ -117,44 +117,43 @@
 
   if (! isempty (options.Jacobian))
     if (ischar (options.Jacobian))
-      try
-        options.Jacobian = str2func (options.Jacobian);
-      catch
-        warning (lasterr);
-      end_try_catch
-      if (! is_function_handle (options.Jacobian))
+      if (! exist (options.Jacobian))
         error ("Octave:invalid-input-arg",
-               [solver ": invalid value assigned to field 'Jacobian'"]);
+               [solver ": function '" options.Jacobian "' not found"]);
       endif
+      options.Jacobian = str2func (options.Jacobian);
+    endif
+    if (! is_function_handle (options.Jacobian))
+      error ("Octave:invalid-input-arg",
+             [solver ": invalid value assigned to field 'Jacobian'"]);
     endif
   endif
 
   if (! isempty (options.OutputFcn))
     if (ischar (options.OutputFcn))
-      try
-        options.OutputFcn = str2func (options.OutputFcn);
-      catch
-        warning (lasterr);
-      end_try_catch
-      if (! is_function_handle (options.OutputFcn))
+      if (! exist (options.OutputFcn))
         error ("Octave:invalid-input-arg",
-               [solver ": invalid value assigned to field 'OutputFcn'"]);
+               [solver ": function '" options.OutputFcn "' not found"]);
       endif
+      options.OutputFcn = str2func (options.OutputFcn);
+    endif
+    if (! is_function_handle (options.OutputFcn))
+      error ("Octave:invalid-input-arg",
+             [solver ": invalid value assigned to field 'OutputFcn'"]);
     endif
   endif
 
   if (! isempty (options.Events))
     if (ischar (options.Events))
-      try
-        options.Events = str2func (options.Events);
-      catch
-        warning (lasterr);
-      end_try_catch
-      if (! is_function_handle (options.Events)
-          && ! ismatrix (options.Events))
+      if (! exist (options.Events))
         error ("Octave:invalid-input-arg",
-               [solver ": invalid value assigned to field 'Events'"]);
+               [solver ": function '" options.Events "' not found"]);
       endif
+      options.Events = str2func (options.Events);
+    endif
+    if (! is_function_handle (options.Events))
+      error ("Octave:invalid-input-arg",
+             [solver ": invalid value assigned to field 'Events'"]);
     endif
   endif