changeset 29604:44f0b8975fe5

Cast to wider resulting type before multiplication. * ov-cx-mat.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-re-mat.cc (load_binary), ls-mat4.cc (save_mat_binary_data): Cast to wider resulting type before multiplication. (Reported by CodeQL.)
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 04 May 2021 20:50:58 +0200
parents 74040b0ba403
children 7460baab17ad
files libinterp/corefcn/ls-mat4.cc libinterp/octave-value/ov-cx-mat.cc libinterp/octave-value/ov-flt-cx-mat.cc libinterp/octave-value/ov-flt-re-mat.cc libinterp/octave-value/ov-re-mat.cc
diffstat 5 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/ls-mat4.cc	Tue May 04 16:25:47 2021 +0200
+++ b/libinterp/corefcn/ls-mat4.cc	Tue May 04 20:50:58 2021 +0200
@@ -430,7 +430,7 @@
       int32_t imag = (tc.iscomplex () ? 1 : 0);
       os.write (reinterpret_cast<char *> (&imag), 4);
 
-      len = nr * nc;
+      len = static_cast<octave_idx_type> (nr) * nc;
     }
 
   // LEN includes the terminating character, and the file is also
--- a/libinterp/octave-value/ov-cx-mat.cc	Tue May 04 16:25:47 2021 +0200
+++ b/libinterp/octave-value/ov-cx-mat.cc	Tue May 04 20:50:58 2021 +0200
@@ -516,7 +516,7 @@
         return false;
       ComplexMatrix m (nr, nc);
       Complex *im = m.fortran_vec ();
-      octave_idx_type len = nr * nc;
+      octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
       read_doubles (is, reinterpret_cast<double *> (im),
                     static_cast<save_type> (tmp), 2*len, swap, fmt);
 
--- a/libinterp/octave-value/ov-flt-cx-mat.cc	Tue May 04 16:25:47 2021 +0200
+++ b/libinterp/octave-value/ov-flt-cx-mat.cc	Tue May 04 20:50:58 2021 +0200
@@ -480,7 +480,7 @@
         return false;
       FloatComplexMatrix m (nr, nc);
       FloatComplex *im = m.fortran_vec ();
-      octave_idx_type len = nr * nc;
+      octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
       read_floats (is, reinterpret_cast<float *> (im),
                    static_cast<save_type> (tmp), 2*len, swap, fmt);
 
--- a/libinterp/octave-value/ov-flt-re-mat.cc	Tue May 04 16:25:47 2021 +0200
+++ b/libinterp/octave-value/ov-flt-re-mat.cc	Tue May 04 20:50:58 2021 +0200
@@ -556,7 +556,7 @@
         return false;
       FloatMatrix m (nr, nc);
       float *re = m.fortran_vec ();
-      octave_idx_type len = nr * nc;
+      octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
       read_floats (is, re, static_cast<save_type> (tmp), len, swap, fmt);
 
       if (! is)
--- a/libinterp/octave-value/ov-re-mat.cc	Tue May 04 16:25:47 2021 +0200
+++ b/libinterp/octave-value/ov-re-mat.cc	Tue May 04 20:50:58 2021 +0200
@@ -670,7 +670,7 @@
         return false;
       Matrix m (nr, nc);
       double *re = m.fortran_vec ();
-      octave_idx_type len = nr * nc;
+      octave_idx_type len = static_cast<octave_idx_type> (nr) * nc;
       read_doubles (is, re, static_cast<save_type> (tmp), len, swap, fmt);
 
       if (! is)