From 884d32d9eca26a3ca162a727384910db8d6430b8 Mon Sep 17 00:00:00 2001 From: John Anthony Date: Tue, 23 Aug 2011 07:10:30 +0100 Subject: Added malloc abstraction --- nyan.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/nyan.c b/nyan.c index 48ecaea..b3e7c1b 100644 --- a/nyan.c +++ b/nyan.c @@ -45,6 +45,7 @@ static void cleanup(void); static void clear_screen(void); static void draw_cats(unsigned int frame); static void draw_sparkles(void); +static void* ec_malloc(unsigned int size); static void errout(char *str); static void fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col); static void handle_args(int argc, char** argv); @@ -95,9 +96,7 @@ add_sparkle(void) { sparkle_instance* s = sparkles_list; sparkle_instance* new; - new = malloc(sizeof(sparkle_instance)); - if(!new) - errout("Could not allocate new sparkle instance memory in add_sparkle."); + new = ec_malloc(sizeof(sparkle_instance)); new->loc.x = screen->w + 80; new->loc.y = (rand() % (screen->h + sparkle_img[0]->h)) - sparkle_img[0]->h; @@ -123,9 +122,7 @@ add_cat(unsigned int x, unsigned int y) { cat_instance* c = cat_list; cat_instance* new; - new = malloc(sizeof(cat_instance)); - if(!new) - errout("Could not allocate new cat instance memory in add_cat."); + new = ec_malloc(sizeof(cat_instance)); new->loc.x = x; new->loc.y = y; @@ -198,6 +195,15 @@ draw_sparkles() { } } +static void* +ec_malloc(unsigned int size) { + void *ptr; + ptr = malloc(size); + if (!ptr) + errout("In ec_malloc -- unable to allocate memory."); + return ptr; +} + static void errout (char *str) { if (str) -- cgit v1.2.3