Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add magic-fields to long-lasting data structures #29

Open
KristianLyng opened this issue Nov 20, 2014 · 0 comments
Open

Add magic-fields to long-lasting data structures #29

KristianLyng opened this issue Nov 20, 2014 · 0 comments

Comments

@KristianLyng
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant