changeset 33548:a12d26fababc

Array-base.cc: Move early returns before array construction (bug #65712) * Array-base.cc: Reorder some early returns so they happen before a local array variable is constructed.
author Arun Giridhar <arungiridhar@gmail.com>
date Wed, 08 May 2024 12:46:04 -0400
parents 47c798415504
children efbdbe7f3264 4495e4a23aa6
files liboctave/array/Array-base.cc
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Array-base.cc	Wed May 08 09:16:05 2024 -0400
+++ b/liboctave/array/Array-base.cc	Wed May 08 12:46:04 2024 -0400
@@ -1806,14 +1806,10 @@
   if (dim < 0)
     (*current_liboctave_error_handler) ("sort: invalid dimension");
 
-  Array<T, Alloc> m (dims ());
-
-  dim_vector dv = m.dims ();
-
-  if (m.numel () < 1)
-    return m;
-
-  if (dim >= dv.ndims ())
+  if (numel () < 1)  // input array is empty,
+    return *this;
+
+  if (dim >= ndims ())
     {
       // The dimension to sort along exceeds the array's dimensions,
       // ==> array is already trivially sorted in such higher dimensions,
@@ -1822,6 +1818,10 @@
       return *this;
     }
 
+  Array<T, Alloc> m (dims ());
+
+  dim_vector dv = m.dims ();
+
   octave_idx_type ns = dv(dim);
   octave_idx_type iter = dv.numel () / ns;
   octave_idx_type stride = 1;