Mercurial > octave
comparison libinterp/corefcn/data.cc @ 33448:71317c258da9
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 | 5fded8395daa |
children | 85c8686b78e9 |
comparison
equal
deleted
inserted
replaced
33447:7ea909c9818a | 33448:71317c258da9 |
---|---|
8616 int nargin = args.length (); | 8616 int nargin = args.length (); |
8617 | 8617 |
8618 if (nargin < 1 || nargin > 2) | 8618 if (nargin < 1 || nargin > 2) |
8619 print_usage (); | 8619 print_usage (); |
8620 | 8620 |
8621 std::string str = args(0).string_value (); | 8621 std::string str = args(0).xstring_value ("base64_decode: first argument must be a character array"); |
8622 | 8622 |
8623 Array<double> retval = base64_decode (str); | 8623 Array<double> retval = base64_decode (str); |
8624 | 8624 |
8625 if (nargin == 2) | 8625 if (nargin == 2) |
8626 { | 8626 { |
8650 %! assert (outm, in); | 8650 %! assert (outm, in); |
8651 | 8651 |
8652 %!error base64_decode () | 8652 %!error base64_decode () |
8653 %!error base64_decode (1,2,3) | 8653 %!error base64_decode (1,2,3) |
8654 %!error base64_decode (1, "this is not a valid set of dimensions") | 8654 %!error base64_decode (1, "this is not a valid set of dimensions") |
8655 %!error <input was not valid base64> base64_decode (1) | 8655 %!error <first argument must be a character array> base64_decode (1) |
8656 %!error <input was not valid base64> base64_decode ("AQ=") | 8656 %!error <input was not valid base64> base64_decode ("AQ=") |
8657 %!error <incorrect input size> base64_decode ("AQ==") | 8657 %!error <incorrect input size> base64_decode ("AQ==") |
8658 */ | 8658 */ |
8659 | 8659 |
8660 DEFUN (__base64_decode_bytes__, args, , | 8660 DEFUN (__base64_decode_bytes__, args, , |
8672 int nargin = args.length (); | 8672 int nargin = args.length (); |
8673 | 8673 |
8674 if (nargin < 1 || nargin > 2) | 8674 if (nargin < 1 || nargin > 2) |
8675 print_usage (); | 8675 print_usage (); |
8676 | 8676 |
8677 std::string str = args(0).string_value (); | 8677 std::string str = args(0).xstring_value ("__base64_decode_bytes__: first argument must be a character array"); |
8678 | 8678 |
8679 intNDArray<octave_uint8> retval = base64_decode_bytes (str); | 8679 intNDArray<octave_uint8> retval = base64_decode_bytes (str); |
8680 | 8680 |
8681 if (nargin == 2) | 8681 if (nargin == 2) |
8682 { | 8682 { |
8706 %! assert (outm, in); | 8706 %! assert (outm, in); |
8707 | 8707 |
8708 %!error __base64_decode_bytes__ () | 8708 %!error __base64_decode_bytes__ () |
8709 %!error __base64_decode_bytes__ (1,2,3) | 8709 %!error __base64_decode_bytes__ (1,2,3) |
8710 %!error __base64_decode_bytes__ (1, "this is not a valid set of dimensions") | 8710 %!error __base64_decode_bytes__ (1, "this is not a valid set of dimensions") |
8711 %!error <input was not valid base64> __base64_decode_bytes__ (1) | 8711 %!error <first argument must be a character array> __base64_decode_bytes__ (1) |
8712 */ | 8712 */ |
8713 | 8713 |
8714 OCTAVE_END_NAMESPACE(octave) | 8714 OCTAVE_END_NAMESPACE(octave) |