From 32207926f33d845ec87053d8fb3e26317344d455 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 2 Oct 2012 14:03:10 +0200 Subject: [PATCH] fix dangerous use of pointer as value keeper in Obst_MoveUpDown --- src/levels/modules/dodger/actions.c | 3 ++- src/levels/modules/dodger/callbacks.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/levels/modules/dodger/actions.c b/src/levels/modules/dodger/actions.c index 3a89f77..5a1da5c 100644 --- a/src/levels/modules/dodger/actions.c +++ b/src/levels/modules/dodger/actions.c @@ -149,7 +149,8 @@ bool GenerateObstacles(struct Game *game, struct TM_Action *action, enum TM_Acti } else { obst->callback = &Obst_MoveUpDown; obst->bitmap = &(game->level.dodger.obst_bmps.screwball); - obst->data = (void*)(rand()%2); // FIXME: not portable! + obst->data = malloc(sizeof(bool)); + *((bool*)obst->data) = rand()%2; obst->rows = 4; obst->cols = 4; obst->speed = 1.1; diff --git a/src/levels/modules/dodger/callbacks.c b/src/levels/modules/dodger/callbacks.c index d5c1bab..394cf48 100644 --- a/src/levels/modules/dodger/callbacks.c +++ b/src/levels/modules/dodger/callbacks.c @@ -23,15 +23,15 @@ #include "callbacks.h" void Obst_MoveUpDown(struct Game *game, struct Obstacle *obstacle) { - if (obstacle->data) { + if (*((bool*)obstacle->data)) { obstacle->y -= 0.5; if (obstacle->y<=0) { - obstacle->data=NULL; + *((bool*)obstacle->data)=false; } } else { obstacle->y += 0.5; if (obstacle->y>=((game->viewportHeight-al_get_bitmap_height(*(obstacle->bitmap))/obstacle->rows)/(float)game->viewportHeight)*100) { - obstacle->data++; + *((bool*)obstacle->data)=true; } } }