Hi,

On my system, valgrind detects an invalid read in mpn_mul when the
operands have certain sizes. For example, it happens when both operand
lengths are 2601 limbs. I'm attaching a test .c program and valgrind
output.

I just re-ran "make check" to be sure no MPIR tests were failing.
System is an Intel Pentium T4400, 64 bit Ubuntu, and MPIR compile
flags included "-O2 -m64 -march=core2 -mtune=core2"

Fredrik

-- 
You received this message because you are subscribed to the Google Groups 
"mpir-devel" group.
To post to this group, send email to mpir-devel@googlegroups.com.
To unsubscribe from this group, send email to 
mpir-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/mpir-devel?hl=en.

fredrik@scv:~/src/fltest$ valgrind ./a.out
==30073== Memcheck, a memory error detector
==30073== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==30073== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for 
copyright info
==30073== Command: ./a.out
==30073== 
Version: 2.1.1
2601
==30073== Invalid read of size 8
==30073==    at 0x54B6700: __gmpn_copyi (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5492A03: mpn_mul_fft_internal (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493899: mpn_mul_fft_aux (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493B29: __gmpn_mul_fft (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493CDC: mpn_mul_fft_full_a (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5494C13: __gmpn_mul_n (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5489F4F: __gmpn_mul (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x400838: main (mpnbug.c:24)
==30073==  Address 0x5e2a188 is 0 bytes after a block of size 20,808 alloc'd
==30073==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==30073==    by 0x4007DB: main (mpnbug.c:16)
==30073== 
==30073== Invalid read of size 8
==30073==    at 0x54B6700: __gmpn_copyi (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5492C9B: mpn_mul_fft_internal (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493899: mpn_mul_fft_aux (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493B29: __gmpn_mul_fft (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493CDC: mpn_mul_fft_full_a (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5494C13: __gmpn_mul_n (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5489F4F: __gmpn_mul (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x400838: main (mpnbug.c:24)
==30073==  Address 0x5e2f318 is 0 bytes after a block of size 20,808 alloc'd
==30073==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==30073==    by 0x4007E8: main (mpnbug.c:17)
==30073== 
==30073== Invalid read of size 8
==30073==    at 0x54B6700: __gmpn_copyi (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5492A03: mpn_mul_fft_internal (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493899: mpn_mul_fft_aux (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493B09: mpn_mul_fft_mersenne (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493D27: mpn_mul_fft_full_a (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5494C13: __gmpn_mul_n (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5489F4F: __gmpn_mul (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x400838: main (mpnbug.c:24)
==30073==  Address 0x5e2a188 is 0 bytes after a block of size 20,808 alloc'd
==30073==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==30073==    by 0x4007DB: main (mpnbug.c:16)
==30073== 
==30073== Invalid read of size 8
==30073==    at 0x54B6700: __gmpn_copyi (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5492C9B: mpn_mul_fft_internal (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493899: mpn_mul_fft_aux (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493B09: mpn_mul_fft_mersenne (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5493D27: mpn_mul_fft_full_a (in 
/usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5494C13: __gmpn_mul_n (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x5489F4F: __gmpn_mul (in /usr/local/lib/libmpir.so.8.2.1)
==30073==    by 0x400838: main (mpnbug.c:24)
==30073==  Address 0x5e2f318 is 0 bytes after a block of size 20,808 alloc'd
==30073==    at 0x4C2815C: malloc (vg_replace_malloc.c:236)
==30073==    by 0x4007E8: main (mpnbug.c:17)
==30073== 
==30073== 
==30073== HEAP SUMMARY:
==30073==     in use at exit: 0 bytes in 0 blocks
==30073==   total heap usage: 6 allocs, 6 frees, 284,960 bytes allocated
==30073== 
==30073== All heap blocks were freed -- no leaks are possible
==30073== 
==30073== For counts of detected and suppressed errors, rerun with: -v
==30073== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 4 from 4)

#include <stdio.h>
#include <stdlib.h>
#include <mpir.h>

int
main(void)
{
    long N;

    printf("Version: %s\n", mpir_version);

    for (N = 2601; N <= 2601; N++)
    {
        printf("%ld\n", N);

        mp_ptr X = malloc(sizeof(mp_limb_t) * N);
        mp_ptr Y = malloc(sizeof(mp_limb_t) * N);
        mp_ptr Z = malloc(sizeof(mp_limb_t) * (N + N));

        mpn_zero(X, N);
        mpn_zero(Y, N);
        mpn_zero(Z, N+N);

        mpn_mul(Z, X, N, Y, N);

        free(X);
        free(Y);
        free(Z);

    }
}

Reply via email to