changeset 33448:71317c258da9 default @

improve argument checking in base64_decode functions * data.cc (Fbase64_decode, F__base64_decode_bytes__): Use xstring_value to extract first argument and provide meaningful error message if first argument is not a character array. Update tests.
author John W. Eaton <jwe@octave.org>
date Sat, 20 Apr 2024 12:59:52 -0400
parents 7ea909c9818a
children 662938d6b684
files libinterp/corefcn/data.cc
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc	Wed Apr 17 22:50:37 2024 -0400
+++ b/libinterp/corefcn/data.cc	Sat Apr 20 12:59:52 2024 -0400
@@ -8618,7 +8618,7 @@
   if (nargin < 1 || nargin > 2)
     print_usage ();
 
-  std::string str = args(0).string_value ();
+  std::string str = args(0).xstring_value ("base64_decode: first argument must be a character array");
 
   Array<double> retval = base64_decode (str);
 
@@ -8652,7 +8652,7 @@
 %!error base64_decode ()
 %!error base64_decode (1,2,3)
 %!error base64_decode (1, "this is not a valid set of dimensions")
-%!error <input was not valid base64> base64_decode (1)
+%!error <first argument must be a character array> base64_decode (1)
 %!error <input was not valid base64> base64_decode ("AQ=")
 %!error <incorrect input size> base64_decode ("AQ==")
 */
@@ -8674,7 +8674,7 @@
   if (nargin < 1 || nargin > 2)
     print_usage ();
 
-  std::string str = args(0).string_value ();
+  std::string str = args(0).xstring_value ("__base64_decode_bytes__: first argument must be a character array");
 
   intNDArray<octave_uint8> retval = base64_decode_bytes (str);
 
@@ -8708,7 +8708,7 @@
 %!error __base64_decode_bytes__ ()
 %!error __base64_decode_bytes__ (1,2,3)
 %!error __base64_decode_bytes__ (1, "this is not a valid set of dimensions")
-%!error <input was not valid base64> __base64_decode_bytes__ (1)
+%!error <first argument must be a character array> __base64_decode_bytes__ (1)
 */
 
 OCTAVE_END_NAMESPACE(octave)