[GiNaC-devel] make check failed

Alexei Sheplyakov varg at theor.jinr.ru
Thu Oct 23 15:57:26 CEST 2008


Dear Vladimir,

On Wed, Oct 22, 2008 at 03:06:02PM +0100, Vladimir V. Kisil wrote:
> (gdb) r
> Starting program: /usr/local/distrib/math/ginac/check/.libs/lt-exam_cra 
> examining Garner's integer chinese remainder algorithm 
> Program received signal SIGSEGV, Segmentation fault.
> 0xb7bed2d0 in cln::find_modint_ring () from /usr/lib/libcln.so.5
> (gdb) where
> #0  0xb7bed2d0 in cln::find_modint_ring () from /usr/lib/libcln.so.5
> #1  0xb7ecd21f in compute_mix_radix_coeffs (dst=@0xbff5c570, residues=@0xbff5c728, 
>     moduli=@0xbff5c734, recips=@0xbff5c57c) at polynomial/cra_garner.cpp:44
> #2  0xb7ece857 in cln::integer_cra (residues=@0xbff5c728, moduli=@0xbff5c734)
>     at polynomial/cra_garner.cpp:81
> #3  0x0804a140 in run_test_once (lim=<value optimized out>) at exam_cra.cpp:40
> #4  0x0804aa57 in main () at exam_cra.cpp:65

Thanks, I've managed to reproduce the bug. The patch below should fix it.
Could you please check if it works for you?

From: Alexei Sheplyakov <varg at theor.jinr.ru>
Subject: [PATCH] [bugfix] integer_cra: check if arguments contain at least 2 moduli

While at it, also fix exam_cra so it does not produce pointless inputs.

---
 check/exam_cra.cpp              |    4 +++-
 ginac/polynomial/cra_garner.cpp |    3 +++
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/check/exam_cra.cpp b/check/exam_cra.cpp
index 2c6163e..6e24770 100644
--- a/check/exam_cra.cpp
+++ b/check/exam_cra.cpp
@@ -102,12 +102,14 @@ make_random_moduli(const cln::cl_I& limit)
 	std::vector<cln::cl_I> moduli;
 	cln::cl_I prod(1);
 	cln::cl_I next = random_I(std::min(limit >> 1, cln::cl_I(128)));
+	unsigned count = 0;
 	do {
 		cln::cl_I tmp = nextprobprime(next);
 		next = tmp + random_I(cln::cl_I(10)) + 1;
 		prod = prod*tmp;
 		moduli.push_back(tmp);
-	} while (prod < limit);
+		++count;
+	} while (prod < limit || (count < 2));
 	return moduli;
 }
 
diff --git a/ginac/polynomial/cra_garner.cpp b/ginac/polynomial/cra_garner.cpp
index b400adb..76d1e07 100644
--- a/ginac/polynomial/cra_garner.cpp
+++ b/ginac/polynomial/cra_garner.cpp
@@ -3,6 +3,7 @@
 #include <vector>
 #include <cstddef>
 #include "cra_garner.hpp"
+#include "compiler.h"
 
 namespace cln
 {
@@ -73,6 +74,8 @@ mixed_radix_2_ordinary(const vector<cl_I>& mixed_radix_coeffs,
 cl_I integer_cra(const vector<cl_I>& residues,
 	         const vector<cl_I>& moduli)
 {
+	if (unlikely(moduli.size() < 2))
+		throw std::invalid_argument("integer_cra: need at least 2 moduli");
 
 	vector<cl_MI> recips(moduli.size() - 1);
 	compute_recips(recips, moduli);
-- 
1.5.6.5

Best regards,
	Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-devel/attachments/20081023/4d1a855b/attachment.sig 


More information about the GiNaC-devel mailing list