diff options
author | John Anthony <johnanthony@lavabit.com> | 2011-08-23 07:10:30 +0100 |
---|---|---|
committer | John Anthony <johnanthony@lavabit.com> | 2011-08-23 07:10:30 +0100 |
commit | 884d32d9eca26a3ca162a727384910db8d6430b8 (patch) | |
tree | 4eb0aab2644aacbbab3cd20bb4c04bd2e8c69340 | |
parent | d436b0653ace5049d08a89991093b657f745e478 (diff) | |
download | nyancat-884d32d9eca26a3ca162a727384910db8d6430b8.tar.gz nyancat-884d32d9eca26a3ca162a727384910db8d6430b8.tar.bz2 nyancat-884d32d9eca26a3ca162a727384910db8d6430b8.zip |
Added malloc abstraction
-rw-r--r-- | nyan.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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)
|