#define free(x) free(x + 1)
#define malloc(x) malloc(random())
#define malloc(x) malloc(random())
#define free(x) do { free(x); x = NULL; } while (0)
Assuming you can turn it off just before shipping, this will hide many forms of double free during development which then show up when the evil line is deleted.There's also people doing stupid shit like free(&x), but those people don't need evil macros to dick up their code. :)
While this is C++, I've actually seen this particular construct: delete new SomeClass(...);
used as, basically, an eye-poppingly clever way of initializing something, doing work, and then cleaning up after.
{ SomeClass makeitso; }
:)Also, free(ptr++) is broken by design, the post increment value is useless. But free(*ptr++) is a good case.
Yes, of course - that's what I thought I'd written. Clearly not :)
And then later it passes that return value to some function that deallocates the block, by calling free(((char *)p) - n).