tags:

views:

47

answers:

3

I have a software, code of which I have modified and run make again.

If I run the modified code in a black QtCreator project it runs well (nothing specific to Qt, just an example), but if I compile with software's original makefile, I get error on a line as:

(*F)=(double**) malloc((size_arr)*sizeof(double*));

Not in compile time, but a segmentation fault at runtime. F is a ***double by the way.

What should I check in makefile? Any guess?

A: 

Without the rest of the code, I can't see anything wrong with that allocation per se. Be sure you've allocated space for F itself, and initialize all of the pointers in the block *F before dereferencing them.

+2  A: 

Probably F is NULL or pointing to an invalid memory location. Since F gets dereferenced on the left side of the assignment, it needs to be properly initialized, so that it points to a memory location that can store the double** returned by malloc.

sth
Oops, knew I should have turned my second comment into an answer.
Brian Campbell
A: 

*F needs to point to something before you use it. Please check that it is not null and has a reasonable value. If it is on the stack then check the address is a reasonable stack address. If it is pointing at something dynamic (returned by malloc) then then that it is a reasonable heap address. Either use a debuger to print out F or use printf. I know that printf is not real popular with a lot of folks for debugging like this but you can print the address of something else on the stack and something returned by malloc and see if F has a similar value. Try printf("%08x",F);

Philip Schlump