diff liboctave/util/lo-utils.h @ 28849:8b0675c2cfe0

Add functions to check for integer overflow on multiplication (bug #59094). * liboctave/wrappers/intprops-wrappers.c, intprops-wrappers.h: New files with functions to wrap around gnulib macros. * liboctave/wrappers/module.mk: Add new files to lists. * bootstrap.conf: Add gnulib module "intprops". * liboctave/util/lo-utils.cc, lo-utils.h (int_multiply_overflow): Add new (overloaded) functions to check for integer overflow on multiplication. * libinterp/dldfcn/__ode15__.cc (IDA::set_up): Check if multiplication would overflow.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 19 Sep 2020 12:09:57 +0200
parents a2cb3dec4bc5
children 6b3faa844395
line wrap: on
line diff
--- a/liboctave/util/lo-utils.h	Wed Sep 30 17:18:50 2020 -0400
+++ b/liboctave/util/lo-utils.h	Sat Sep 19 12:09:57 2020 +0200
@@ -123,6 +123,21 @@
   template <> void write_value (std::ostream& os, const Complex& value);
   template <> void write_value (std::ostream& os, const float& value);
   template <> void write_value (std::ostream& os, const FloatComplex& value);
+
+  namespace math
+  {
+    bool int_multiply_overflow (int a, int b);
+    bool int_multiply_overflow (long int a, long int b);
+#if defined (OCTAVE_HAVE_LONG_LONG_INT)
+    bool int_multiply_overflow (long long int a, long long int b);
+#endif
+    bool int_multiply_overflow (unsigned int a, unsigned int b);
+    bool int_multiply_overflow (unsigned long int a, unsigned long int b);
+#if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
+    bool int_multiply_overflow (unsigned long long int a,
+                                unsigned long long int b);
+#endif
+  }
 }
 
 OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")