My program has a function for generating random numbers, and started crashing. Valgrind produces this error:
==6952== Stack overflow in thread #1: can't grow stack to 0xffe801000
==6952==
==6952== Process terminating with default action of signal 11 (SIGSEGV)
==6952== Access not within mapped region at address 0xFFE801FF8
==6952== Stack overflow in thread #1: can't grow stack to 0xffe801000
==6952== at 0x403B19: int std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul> >(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>&, std::uniform_int_distribution<int>::param_type const&) (random.tcc:881)
==6952== If you believe this happened as a result of a stack
==6952== overflow in your program's main thread (unlikely but
==6952== possible), you can try to increase the size of the
==6952== main thread stack using the --main-stacksize= flag.
==6952== The main thread stack size used in this run was 8388608.
My code:
std::random_device rd;
std::mt19937 rng(rd());
int rnd(int min, int max, std::mt19937& rng) {
std::uniform_int_distribution<int> uni(min,max);
return uni(rng);
}
rnd(0, 1000, rng);
I tried to look at the file it's referring to, but I don't understand a line of it. What is causing the segfault?
Aucun commentaire:
Enregistrer un commentaire