changeset 29445:b5f3ae7610cf

Use gnulib macros that account for the output type in integer overflow checks. * liboctave/wrappers/intprops-wrappers.c, intprops-wrappers.h: Use gnulib macro INT_MULTIPLY_WRAPV instead of INT_MULTIPLY_OVERFLOW. Change function prototypes accordingly * liboctave/util/lo-utils.cc, lo-utils.h (int_multiply_ok): Change function prototypes. * libinterp/dldfcn/__ode15__.cc (IDA::set_up): Adapt for changed function.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 16 Mar 2021 18:17:42 +0100
parents be09ae42ba96
children 435fc29162c0
files libinterp/dldfcn/__ode15__.cc liboctave/util/lo-utils.cc liboctave/util/lo-utils.h liboctave/wrappers/intprops-wrappers.c liboctave/wrappers/intprops-wrappers.h
diffstat 5 files changed, 55 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__ode15__.cc	Mon Mar 15 19:57:54 2021 +0100
+++ b/libinterp/dldfcn/__ode15__.cc	Tue Mar 16 18:17:42 2021 +0100
@@ -405,10 +405,11 @@
         // entries.
         m_sunJacMatrix = SUNSparseMatrix (m_num, m_num, 0, CSC_MAT);
 #    else
-        if (math::int_multiply_overflow (m_num, m_num))
+        octave_f77_int_type max_elems;
+        if (math::int_multiply_overflow (m_num, m_num, &max_elems))
           error ("Unable to allocate memory for sparse Jacobian");
 
-        m_sunJacMatrix = SUNSparseMatrix (m_num, m_num, m_num*m_num, CSC_MAT);
+        m_sunJacMatrix = SUNSparseMatrix (m_num, m_num, max_elems, CSC_MAT);
 #    endif
         if (! m_sunJacMatrix)
           error ("Unable to create sparse Jacobian for Sundials");
--- a/liboctave/util/lo-utils.cc	Mon Mar 15 19:57:54 2021 +0100
+++ b/liboctave/util/lo-utils.cc	Tue Mar 16 18:17:42 2021 +0100
@@ -478,38 +478,42 @@
 
   namespace math
   {
-    bool int_multiply_overflow (int a, int b)
+    bool int_multiply_overflow (int a, int b, int *r)
     {
-      return octave_i_multiply_overflow_wrapper (a, b);
+      return octave_i_multiply_overflow_wrapper (a, b, r);
     }
 
-    bool int_multiply_overflow (long int a, long int b)
+    bool int_multiply_overflow (long int a, long int b, long int *r)
     {
-      return octave_li_multiply_overflow_wrapper (a, b);
+      return octave_li_multiply_overflow_wrapper (a, b, r);
     }
 
 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
-    bool int_multiply_overflow (long long int a, long long int b)
+    bool int_multiply_overflow (long long int a, long long int b,
+                                long long int *r)
     {
-      return octave_lli_multiply_overflow_wrapper (a, b);
+      return octave_lli_multiply_overflow_wrapper (a, b, r);
     }
 #endif
 
-    bool int_multiply_overflow (unsigned int a, unsigned int b)
+    bool int_multiply_overflow (unsigned int a, unsigned int b,
+                                unsigned int *r)
     {
-      return octave_ui_multiply_overflow_wrapper (a, b);
+      return octave_ui_multiply_overflow_wrapper (a, b, r);
     }
 
-    bool int_multiply_overflow (unsigned long int a, unsigned long int b)
+    bool int_multiply_overflow (unsigned long int a, unsigned long int b,
+                          unsigned long int *r)
     {
-      return octave_uli_multiply_overflow_wrapper (a, b);
+      return octave_uli_multiply_overflow_wrapper (a, b, r);
     }
 
 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
     bool int_multiply_overflow (unsigned long long int a,
-                                unsigned long long int b)
+                          unsigned long long int b,
+                          unsigned long long int *r)
     {
-      return octave_ulli_multiply_overflow_wrapper (a, b);
+      return octave_ulli_multiply_overflow_wrapper (a, b, r);
     }
 #endif
 
--- a/liboctave/util/lo-utils.h	Mon Mar 15 19:57:54 2021 +0100
+++ b/liboctave/util/lo-utils.h	Tue Mar 16 18:17:42 2021 +0100
@@ -114,24 +114,27 @@
 
   namespace math
   {
-    extern OCTAVE_API bool int_multiply_overflow (int a, int b);
+    extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r);
 
-    extern OCTAVE_API bool int_multiply_overflow (long int a, long int b);
+    extern OCTAVE_API bool
+    int_multiply_overflow (long int a, long int b, long int *r);
 
 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
     extern OCTAVE_API bool
-    int_multiply_overflow (long long int a, long long int b);
+    int_multiply_overflow (long long int a, long long int b, long long int *r);
 #endif
 
     extern OCTAVE_API bool
-    int_multiply_overflow (unsigned int a, unsigned int b);
+    int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r);
 
     extern OCTAVE_API bool
-    int_multiply_overflow (unsigned long int a, unsigned long int b);
+    int_multiply_overflow (unsigned long int a, unsigned long int b,
+                           unsigned long int *r);
 
 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
     extern OCTAVE_API bool
-    int_multiply_overflow (unsigned long long int a, unsigned long long int b);
+    int_multiply_overflow (unsigned long long int a, unsigned long long int b,
+                           unsigned long long int *r);
 #endif
   }
 }
--- a/liboctave/wrappers/intprops-wrappers.c	Mon Mar 15 19:57:54 2021 +0100
+++ b/liboctave/wrappers/intprops-wrappers.c	Tue Mar 16 18:17:42 2021 +0100
@@ -33,43 +33,46 @@
 // functions.
 
 int
-octave_i_multiply_overflow_wrapper (int a, int b)
+octave_i_multiply_overflow_wrapper (int a, int b, int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 
 int
-octave_li_multiply_overflow_wrapper (long int a, long int b)
+octave_li_multiply_overflow_wrapper (long int a, long int b, long int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 
 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
 int
-octave_lli_multiply_overflow_wrapper (long long int a, long long int b)
+octave_lli_multiply_overflow_wrapper (long long int a, long long int b,
+                                      long long int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 #endif
 
 int
-octave_ui_multiply_overflow_wrapper (unsigned int a, unsigned int b)
+octave_ui_multiply_overflow_wrapper (unsigned int a, unsigned int b,
+                                     unsigned int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 
 int
-octave_uli_multiply_overflow_wrapper (unsigned long int a,
-                                      unsigned long int b)
+octave_uli_multiply_overflow_wrapper (unsigned long int a, unsigned long int b,
+                                      unsigned long int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 
 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
 int
 octave_ulli_multiply_overflow_wrapper (unsigned long long int a,
-                                       unsigned long long int b)
+                                       unsigned long long int b,
+                                       unsigned long long int *r)
 {
-  return INT_MULTIPLY_OVERFLOW (a, b);
+  return INT_MULTIPLY_WRAPV (a, b, r);
 }
 #endif
--- a/liboctave/wrappers/intprops-wrappers.h	Mon Mar 15 19:57:54 2021 +0100
+++ b/liboctave/wrappers/intprops-wrappers.h	Tue Mar 16 18:17:42 2021 +0100
@@ -35,26 +35,31 @@
 // These functions return 1 if the operation between the input arguments would
 // overflow.
 
-extern OCTAVE_API int octave_i_multiply_overflow_wrapper (int a, int b);
+extern OCTAVE_API int
+octave_i_multiply_overflow_wrapper (int a, int b, int *r);
 
 extern OCTAVE_API int
-octave_li_multiply_overflow_wrapper (long int a, long int b);
+octave_li_multiply_overflow_wrapper (long int a, long int b, long int *r);
 
 #  if defined (OCTAVE_HAVE_LONG_LONG_INT)
 extern OCTAVE_API int
-octave_lli_multiply_overflow_wrapper (long long int a, long long int b);
+octave_lli_multiply_overflow_wrapper (long long int a, long long int b,
+                                      long long int *r);
 #  endif
 
 extern OCTAVE_API int
-octave_ui_multiply_overflow_wrapper (unsigned int a, unsigned int b);
+octave_ui_multiply_overflow_wrapper (unsigned int a, unsigned int b,
+                                     unsigned int *r);
 
 extern OCTAVE_API int
-octave_uli_multiply_overflow_wrapper (unsigned long int a, unsigned long int b);
+octave_uli_multiply_overflow_wrapper (unsigned long int a, unsigned long int b,
+                                      unsigned long int *r);
 
 #  if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
 extern OCTAVE_API int
 octave_ulli_multiply_overflow_wrapper (unsigned long long int a,
-                                       unsigned long long int b);
+                                       unsigned long long int b,
+                                       unsigned long long int *r);
 #  endif
 
 #if defined __cplusplus