[Gmp-commit] /var/hg/gmp: Let mpn_mul assert that output area doesn't overlap...

mercurial at gmplib.org mercurial at gmplib.org
Sun Jul 23 18:11:32 UTC 2017


details:   /var/hg/gmp/rev/67de299c262d
changeset: 17476:67de299c262d
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sun Jul 23 20:09:32 2017 +0200
description:
Let mpn_mul assert that output area doesn't overlap with the input.

diffstat:

 mini-gmp/ChangeLog  |  6 ++++++
 mini-gmp/mini-gmp.c |  8 ++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diffs (38 lines):

diff -r 3bb8f681d349 -r 67de299c262d mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Sun Jul 23 19:55:38 2017 +0200
+++ b/mini-gmp/ChangeLog	Sun Jul 23 20:09:32 2017 +0200
@@ -1,3 +1,9 @@
+2017-07-23  Niels Möller  <nisse at lysator.liu.se>
+
+	* mini-gmp.c (GMP_MPN_OVERLAP_P): New macro, copy of
+	MPN_OVERLAP_P, from gmp-impl.h.
+	(mpn_mul): Assert that output area doesn't overlap with the input.
+
 2017-02-03 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp.c (mpz_sizeinbase, mpz_get_str, mpz_set_str): Support
diff -r 3bb8f681d349 -r 67de299c262d mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Sun Jul 23 19:55:38 2017 +0200
+++ b/mini-gmp/mini-gmp.c	Sun Jul 23 20:09:32 2017 +0200
@@ -71,6 +71,12 @@
 
 #define GMP_CMP(a,b) (((a) > (b)) - ((a) < (b)))
 
+/* Return non-zero if xp,xsize and yp,ysize overlap.
+   If xp+xsize<=yp there's no overlap, or if yp+ysize<=xp there's no
+   overlap.  If both these are false, there's an overlap. */
+#define GMP_MPN_OVERLAP_P(xp, xsize, yp, ysize)				\
+  ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
+
 #define gmp_assert_nocarry(x) do { \
     mp_limb_t __cy = (x);	   \
     assert (__cy == 0);		   \
@@ -576,6 +582,8 @@
 {
   assert (un >= vn);
   assert (vn >= 1);
+  assert (!GMP_MPN_OVERLAP_P(rp, un + vn, up, un));
+  assert (!GMP_MPN_OVERLAP_P(rp, un + vn, vp, vn));
 
   /* We first multiply by the low order limb. This result can be
      stored, not added, to rp. We also avoid a loop for zeroing this


More information about the gmp-commit mailing list