changeset 33497:ece9fb6398c3

toplev.cc: Improve input validation for system () (bug #65665) * toplev.cc (Fsystem ()): Use strict_bool_value () to convert input argument to boolean. Add BISTs.
author Arun Giridhar <arungiridhar@gmail.com>
date Wed, 01 May 2024 12:30:06 -0400
parents 02845015966d
children a57844d3919e 0f2257136d9c
files libinterp/corefcn/toplev.cc
diffstat 1 files changed, 4 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/toplev.cc	Wed May 01 10:33:07 2024 -0400
+++ b/libinterp/corefcn/toplev.cc	Wed May 01 12:30:06 2024 -0400
@@ -262,16 +262,7 @@
   bool return_output = (nargin == 1 && nargout > 1);
 
   if (nargin > 1)
-    {
-      try
-        {
-          return_output = args(1).is_true ();
-        }
-      catch (execution_exception& ee)
-        {
-          error (ee, "system: RETURN_OUTPUT must be boolean value true or false");
-        }
-    }
+    return_output = args(1).strict_bool_value ("system: RETURN_OUTPUT must be boolean value true or false");
 
   if (return_output && type == et_async)
     error ("system: can't return output from commands run asynchronously");
@@ -322,6 +313,9 @@
 
 %!error system ()
 %!error system (1, 2, 3)
+%!error <RETURN_OUTPUT must be boolean value> system (ls_command (), "foo")
+%!error <TYPE must be .*sync.* or .*async> system (ls_command (), true, "foo")
+%!warning <converted to logical 1> system (ls_command (), 0.5);
 */
 
 static octave_value