diff --git a/lcthw-remnants-2/ex19.c b/lcthw-remnants-2/ex19.c index 682f8a1..814d734 100644 --- a/lcthw-remnants-2/ex19.c +++ b/lcthw-remnants-2/ex19.c @@ -3,11 +3,13 @@ #include #include #include +#include #include "ex19.h" int Monster_attack(void *self, int damage) { + assert(self != NULL); Monster *monster = self; printf("You attack %s!\n", monster->_(description)); @@ -25,6 +27,7 @@ int Monster_attack(void *self, int damage) int Monster_init(void *self) { + assert(self != NULL); Monster *monster = self; monster->hit_points = 10; return 1; @@ -38,6 +41,7 @@ Object MonsterProto = { void *Room_move(void *self, Direction direction) { + assert(self != NULL); Room *room = self; Room *next = NULL; @@ -68,6 +72,7 @@ void *Room_move(void *self, Direction direction) int Room_attack(void *self, int damage) { + assert(self != NULL); Room *room = self; Monster *monster = room->bad_guy; @@ -89,6 +94,7 @@ Object RoomProto = { void *Map_move(void *self, Direction direction) { + assert(self != NULL); Map *map = self; Room *location = map->location; Room *next = NULL; @@ -104,6 +110,7 @@ void *Map_move(void *self, Direction direction) int Map_attack(void *self, int damage) { + assert(self != NULL); Map *map = self; Room *location = map->location; @@ -113,6 +120,7 @@ int Map_attack(void *self, int damage) int Map_init(void *self) { + assert(self != NULL); Map *map = self; // make some rooms for a small map @@ -149,6 +157,7 @@ Object MapProto = { int process_input(Map *game) { + assert(game != NULL); printf("\n> "); char ch = getchar(); @@ -204,6 +213,7 @@ int main(int argc, char *argv[]) // make our map to work with Map *game = NEW(Map, "The Hall of the Minotaur."); + assert(game != NULL); printf("You enter the "); game->location->_(describe)(game->location); diff --git a/lcthw-remnants-2/object.c b/lcthw-remnants-2/object.c index 6f5df17..6e9d18e 100644 --- a/lcthw-remnants-2/object.c +++ b/lcthw-remnants-2/object.c @@ -16,6 +16,7 @@ void Object_destroy(void *self) void Object_describe(void *self) { + assert(self != NULL); Object *obj = self; printf("%s.\n", obj->description); } @@ -40,6 +41,8 @@ int Object_attack(void *self, int damage) void *Object_new(size_t size, Object proto, char *description) { + assert(description != NULL); + // setup the default functions in case they aren't set if(!proto.init) proto.init = Object_init; if(!proto.describe) proto.describe = Object_describe; @@ -50,6 +53,7 @@ void *Object_new(size_t size, Object proto, char *description) // this seems weird, but we can make a struct of one size, // then point a different pointer at it to "cast" it Object *el = calloc(1, size); + assert(el != NULL); *el = proto; // copy the description over