summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAMMJohnson <john_anthony@lavabit.com>2011-06-20 02:20:59 +0100
committerLAMMJohnson <john_anthony@lavabit.com>2011-06-20 02:20:59 +0100
commit4204021d94a0840fb1c5859c0d125a9e258f8214 (patch)
treedea2fa643a81b42e0dd13e3f4ed41f5ae665b77f
parentd8b7cb2578182a4aca5b9ee0fab8187d0d471642 (diff)
downloadnyancat-4204021d94a0840fb1c5859c0d125a9e258f8214.tar.gz
nyancat-4204021d94a0840fb1c5859c0d125a9e258f8214.tar.bz2
nyancat-4204021d94a0840fb1c5859c0d125a9e258f8214.zip
Added memory error handling
-rw-r--r--nyan.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/nyan.c b/nyan.c
index 923548f..b9e943e 100644
--- a/nyan.c
+++ b/nyan.c
@@ -46,6 +46,7 @@ static void cleanup(void);
static void clear_screen(void);
static void draw_cats(unsigned int frame);
static void draw_sparkles(void);
+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);
static void handle_input(void);
@@ -87,6 +88,8 @@ add_sparkle(void) {
sparkle_instance* new;
new = malloc(sizeof(sparkle_instance));
+ if(!new)
+ errout("Could not allocate new sparkle instance memory in add_sparkle.");
new->loc.x = screen->w + 80;
new->loc.y = (rand() % (screen->h + sparkle_img[0]->h)) - sparkle_img[0]->h;
@@ -114,6 +117,9 @@ add_cat(unsigned int x, unsigned int y) {
cat_instance* new;
new = malloc(sizeof(cat_instance));
+ if(!new)
+ errout("Could not allocate new cat instance memory in add_cat.");
+
new->loc.x = x;
new->loc.y = y;
new->next = NULL;
@@ -188,6 +194,13 @@ draw_sparkles() {
}
static void
+errout (char *str) {
+ if (str)
+ puts(str);
+ exit(1);
+}
+
+static void
fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col) {
int i, e;