diff --git a/src/box.c b/src/box.c index e014332..7c5c5c4 100644 --- a/src/box.c +++ b/src/box.c @@ -29,6 +29,8 @@ box * create_box(game *g, int x, int y, int w, int h) { box *b = malloc(sizeof(box)); + if(b == NULL) + exit(1); b->x = x; b->y = y; diff --git a/src/main.c b/src/main.c index 11afcb5..cbe6a7f 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,8 @@ static void start_game (game *); int main (int argc, char **argv) { game *g = malloc(sizeof(game)); + if(g == NULL) + exit(1); srand(time(NULL)); @@ -70,11 +72,19 @@ static void start_game (game *g) g->sf = create_starfield(g); g->wp = malloc(sizeof(weapons)); + if(g->wp == NULL) + exit(1); g->ex = malloc(sizeof(explosions)); + if(g->ex == NULL) + exit(1); g->bo = malloc(sizeof(bonus)); + if(g->bo == NULL) + exit(1); g->t = create_tunnel(g, g->w, g->h); g->p = create_player(g); g->al = malloc(sizeof(aliens)); + if(g->al == NULL) + exit(1); init_bonus(g, g->bo); init_weapons(g, g->wp); diff --git a/src/player.c b/src/player.c index 0daac48..2644438 100644 --- a/src/player.c +++ b/src/player.c @@ -32,6 +32,8 @@ struct ee_sprite *ship_sprite; player * create_player(game *g) { player *p = malloc(sizeof(player)); + if(p == NULL) + exit(1); p->x = g->w / 2; p->y = g->h - 3; diff --git a/src/starfield.c b/src/starfield.c index 60f408b..de4a24b 100644 --- a/src/starfield.c +++ b/src/starfield.c @@ -32,6 +32,8 @@ starfield * create_starfield(game *g) starfield *s; s = malloc(STARS * sizeof(starfield)); + if(s == NULL) + exit(1); for(i = 0; i < STARS; i++) { diff --git a/src/tunnel.c b/src/tunnel.c index b6f4c31..fb80333 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -31,9 +31,15 @@ tunnel * create_tunnel(game *g, int w, int h) { int i; tunnel *t = malloc(sizeof(tunnel)); + if(t == NULL) + exit(1); t->left = malloc(h*sizeof(int)); + if(t->left == NULL) + exit(1); t->right = malloc(h*sizeof(int)); + if(t->right == NULL) + exit(1); t->w = w; t->h = h; diff --git a/src/weapons.c b/src/weapons.c index 6420246..15eff17 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -169,7 +169,7 @@ void update_weapons(game *g, weapons *wp) /* Normalize direction */ if(dx | dy) { - int norm = ee_sqrt(dx * dx + 4 * dy * dy); + unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy); dx = dx * 32 / norm; dy = dy * 32 / norm; } @@ -181,7 +181,7 @@ void update_weapons(game *g, weapons *wp) /* Normalize speed */ if(dx | dy) { - int norm = ee_sqrt(dx * dx + 4 * dy * dy); + unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy); wp->vx[i] = dx * 32 / norm; wp->vy[i] = dy * 32 / norm; }