changeset 25927:d6581134daaa

Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781). * data.cc (Fones): Add BIST test with a fractional dimension in a dimension vector. * rand.cc (do_rand): Convert dimension vector to Array<octave_idx_type>, not an Array<int>. Call "octave_idx_type_vector_value (true)" to enable input validation. * rand.cc (Frand): Add BIST test with a fractional dimension in a dimension vector. * utils.cc (get_dimensions): Call "octave_idx_type_vector_value (true)" to enable input validation. * ov.cc (int_vector_value, octave_idx_type_vector_value): Change error message when conversion fails to print the original value that failed.
author Rik <rik@octave.org>
date Thu, 11 Oct 2018 15:48:51 -0700
parents 373fe1608f7c
children a533a7c4d2cc
files libinterp/corefcn/data.cc libinterp/corefcn/rand.cc libinterp/corefcn/utils.cc libinterp/octave-value/ov.cc
diffstat 4 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc	Thu Oct 11 14:04:47 2018 -0700
+++ b/libinterp/corefcn/data.cc	Thu Oct 11 15:48:51 2018 -0700
@@ -4309,6 +4309,7 @@
 ## Test input validation
 %!error <invalid data type specified> zeros (1, 1, "foobar")
 %!error <conversion of 1.1 .*failed> zeros (1, 1.1, 2)
+%!error <conversion of 1.1 .*failed> zeros ([1, 1.1, 2])
 
 */
 
--- a/libinterp/corefcn/rand.cc	Thu Oct 11 14:04:47 2018 -0700
+++ b/libinterp/corefcn/rand.cc	Thu Oct 11 15:48:51 2018 -0700
@@ -207,11 +207,11 @@
           }
         else if (tmp.is_matrix_type ())
           {
-            Array<int> iv;
+            Array<octave_idx_type> iv;
 
             try
               {
-                iv = tmp.int_vector_value (true);
+                iv = tmp.octave_idx_type_vector_value (true);
               }
             catch (octave::execution_exception& e)
               {
@@ -541,6 +541,7 @@
 
 ## Test input validation
 %!error <conversion of 1.1 to.* failed> rand (1, 1.1)
+%!error <dimensions must be .* array of integers> rand ([1, 1.1])
 */
 
 static std::string current_distribution = octave::rand::distribution ();
--- a/libinterp/corefcn/utils.cc	Thu Oct 11 14:04:47 2018 -0700
+++ b/libinterp/corefcn/utils.cc	Thu Oct 11 15:48:51 2018 -0700
@@ -1084,7 +1084,7 @@
     if (! a.dims ().isvector ())
       error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
 
-    const Array<octave_idx_type> v = a.octave_idx_type_vector_value ();
+    const Array<octave_idx_type> v = a.octave_idx_type_vector_value (true);
     const octave_idx_type n = v.numel ();
 
     dim.resize (n); // even if n < 2, resize sets it back to 2
--- a/libinterp/octave-value/ov.cc	Thu Oct 11 14:04:47 2018 -0700
+++ b/libinterp/octave-value/ov.cc	Thu Oct 11 15:48:51 2018 -0700
@@ -1805,7 +1805,7 @@
                 retval.xelem (i) = v;
               else
                 {
-                  error_with_cfn ("conversion to integer value failed");
+                  error_with_cfn ("conversion of %g to int value failed", ai);
                   break;
                 }
             }
@@ -1875,7 +1875,7 @@
                 retval.xelem (i) = v;
               else
                 {
-                  error_with_cfn ("conversion to integer value failed");
+                  error_with_cfn ("conversion of %g to octave_idx_type value failed", ai);
                   break;
                 }
             }