changeset 30573:3b2558676d0e

inv: Improve input validation (bug #61728). * libinterp/corefcn/inv.cc (Finv): Exit earlier when argument type is not suitable for "inv".
author Antonius Burgers <arburgers@gmail.com>
date Thu, 23 Dec 2021 17:46:51 +0100
parents 6d96538052b9
children 33f77d94b4c9
files libinterp/corefcn/inv.cc
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/inv.cc	Thu Dec 30 16:11:55 2021 -0800
+++ b/libinterp/corefcn/inv.cc	Thu Dec 23 17:46:51 2021 +0100
@@ -70,11 +70,14 @@
 
   octave_value arg = args(0);
 
+  if (!(arg.isnumeric () || arg.islogical ()))
+    err_wrong_type_arg ("inv", arg);
+
   if (arg.isempty ())
     return ovl (Matrix ());
 
   if (arg.rows () != arg.columns ())
-    err_square_matrix_required ("inverse", "A");
+    err_square_matrix_required ("inv", "A");
 
   octave_value result;
   octave_idx_type info;
@@ -191,6 +194,8 @@
             }
         }
       else
+        // Shouldn't get here since we checked for suitable arg earlier.
+        // Maybe for some user-defined classes?
         err_wrong_type_arg ("inv", arg);
     }