Re: crash on __gmpz_init

2024-01-22 Thread Torbjörn Granlund
"igor pesando - Dept of Physics, University of Torino" writes: thanks for the quick answer on the first case. But the issue is also present if I use malloc in C. People have explained what you did wrong, which was several things. Something you might consider: It would have been pretty

Re: crash on __gmpz_init

2024-01-22 Thread igor pesando - Dept of Physics, University of Torino
Hi Marc, thanks for the quick answer on the first case. But the issue is also present if I use malloc in C. Bests Igor P On 22/01/24 11:02, Marc Glisse wrote: Hello,   mpz_class M[LINES][COLS]; you are trying to put an array with millions of elements on the stack, so the stack overflows.

Re: crash on __gmpz_init

2024-01-22 Thread Vincent Lefevre
On 2024-01-22 15:01:24 +0100, Vincent Lefevre wrote: > I'm just surprised that GCC doesn't emit any warning > (even with -O2 -Wall -Wextra), as some pointers are obviously > incorrect. The missing warning seems clearly a bug in GCC (I get a warning in similar code, but not for the combination of

Re: crash on __gmpz_init

2024-01-22 Thread Vincent Lefevre
On 2024-01-22 14:34:21 +0100, Torbjorn Granlund wrote: > Note that there are several typos for the dimensions in the examples, so > making sense of things is pretty hard. Indeed, mpz_init( M[ lin*LINES +col] ); should be lin*COLS + col. I suspect a buffer overflow due to that (the

Re: crash on __gmpz_init

2024-01-22 Thread Vincent Lefevre
On 2024-01-22 11:51:21 +0100, Vincent Lefevre wrote: > On 2024-01-22 11:02:21 +0100, Marc Glisse wrote: > > Hello, > > > > mpz_class M[LINES][COLS]; > > > > you are trying to put an array with millions of elements on the stack, so > > the stack overflows. Very large arrays need to be allocated

Re: crash on __gmpz_init

2024-01-22 Thread Torbjörn Granlund
Vincent Lefevre writes: On 2024-01-22 11:02:21 +0100, Marc Glisse wrote: > Hello, > > mpz_class M[LINES][COLS]; > > you are trying to put an array with millions of elements on the stack, so > the stack overflows. Very large arrays need to be allocated on the heap in > C++

Re: crash on __gmpz_init

2024-01-22 Thread Vincent Lefevre
On 2024-01-22 11:02:21 +0100, Marc Glisse wrote: > Hello, > > mpz_class M[LINES][COLS]; > > you are trying to put an array with millions of elements on the stack, so > the stack overflows. Very large arrays need to be allocated on the heap in > C++ (new, malloc, or some wrapper like

Re: crash on __gmpz_init

2024-01-22 Thread Marc Glisse
Hello, mpz_class M[LINES][COLS]; you are trying to put an array with millions of elements on the stack, so the stack overflows. Very large arrays need to be allocated on the heap in C++ (new, malloc, or some wrapper like std::vector). On Mon, 22 Jan 2024, igor pesando - Dept of Physics,

crash on __gmpz_init

2024-01-22 Thread igor pesando - Dept of Physics, University of Torino
Hi *, first of all thanks for your work. The programs are attached as required. Best regards Igor Pesando * The issue I have is that the allocation in of a matrix in c++ crashes the program with SEGFAULT if the dimension are