Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000140400008
0x0000000100002a88 in tqli (d=0x7fff5fbffaa4, e=0x7fff5fbffa98, n=3, z=0x140400000)
at ac_nr.c:402
402 f=z[k][i+1];
As you see, your z
pointer is 0x140400000, and the error happens at 0x0000000140400008, which is 8 bytes later. This is in all probability a buffer overflow against z
(array out of bounds).
Why does it work in Linux: that may have to do with allocation strategies, for example if the alloc library allocates memory in blocks of 16 bytes to improve performances, and you request a block of 8 bytes, then 16 bytes will be allocated. Without protectors or canaries, nothing will stop you from addressing one item beyond the bounds, and having allocated what amounts to one extra item, you won't get a segfault.
But on a machine that allocates 8 bytes blocks, the same code will crash.
I strongly endorse Andreas Florath's suggestion: run valgrind against your program in Linux and check for out-of-bounds accesses. Or you may want to verify the size of z
and where you actually access it.