compiz icon indicating copy to clipboard operation
compiz copied to clipboard

Add magic-fields to long-lasting data structures

Open KristianLyng opened this issue 10 years ago • 0 comments

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.

KristianLyng avatar Nov 20 '14 14:11 KristianLyng