views:

88

answers:

2

I've recently updated to a testing distribution, which is now using GCC 4.4.3. Now I've set everything up, I've returned to coding and have built my project and I get one of these horrible messages:

*** glibc detected *** ./boxyseq: free(): invalid pointer: 0x0000000001d873e8 ***

I absolutely know what is wrong here, but was rather confused as to when I saw my C code where I call a function which frees a dynamically allocated data structure - I had passed it an incompatible pointer type - a pointer to a completely different data structure.

warning: passing argument 1 of 'data_A_free' from incompatible pointer type
note: expected 'struct data_A *' but argument is of type 'struct data_B *'

I'm confused because I'm sure this would have been an error before and compilation would never have completed. Is this not just going to make life more difficult for C programmers?

Can I change it back to an error without making a whole bunch of other warnings errors too?

Or am I loosing the plot and it's always been a warning?

A: 

This is definitely one of the things that the clang analyzer would catch, and therefore you can make it an error building with clang.

Andrew McGregor
You can make it an error with gcc too (`-pedantic-errors`). The question is can you avoid making a bunch of other warnings errors.
Matthew Flaschen
Eurrgghh, just read the wikipedia page about it: "Its goal is to offer a replacement to the GNU Compiler Collection (GCC). Development is sponsored by Apple..." no thanks.
James Morris
+2  A: 

It's always been a warning. C allows you to implicitly cast any pointer to any other pointer, although any half-decent compiler will warn you.

It's an error in C++, though. Perhaps that's what you were thinking of?

In GCC, you can turn a warning into an error using -Werror=, but I don't see an option for this particular warning. You could just use -Werror to turn all warnings into errors, but that might do more than you want.

Daniel Stutzbach