adding a few asserts for ex19

cat-town
Dan Buch 13 years ago
parent 1695ec3796
commit 891013a781

@ -46,6 +46,7 @@ int Object_attack(void *self, int damage)
void *Object_new(size_t size, Object proto, char *description) void *Object_new(size_t size, Object proto, char *description)
{ {
assert(description != NULL);
// setup the default functions in case they aren't set // setup the default functions in case they aren't set
if(!proto.init) proto.init = Object_init; if(!proto.init) proto.init = Object_init;
if(!proto.describe) proto.describe = Object_describe; if(!proto.describe) proto.describe = Object_describe;
@ -56,6 +57,7 @@ void *Object_new(size_t size, Object proto, char *description)
// this seems weird, but we can make a struct of one size, // this seems weird, but we can make a struct of one size,
// then point a different pointer at it to "cast" it // then point a different pointer at it to "cast" it
Object *el = calloc(size, 1); Object *el = calloc(size, 1);
assert(el != NULL);
*el = proto; *el = proto;
// copy the description over // copy the description over

Loading…
Cancel
Save