compiz
compiz copied to clipboard
Add magic-fields to long-lasting data structures
This is a simple memory-corruption safeguard that's relatively common:
foo.h:
struct CompFoo { #define FOO_MAGIC 0x0112112 int magic; char *blatti; ... };
foo.c:
struct CompFoo *f = malloc.... f->magic = FOO_MAGIC; ...
other.c:
int otherFunc(CompFoo *f, char bah) { assert(f->magic == FOO_MAGIC); ... }
This is a very simple way to catch some basic corruption issues and it's virtually free.