From a738393ba6e3d8d8d14513428a7c4a8cbe37feb6 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 4 Jul 2011 10:36:43 +0200 Subject: [PATCH] fix passing item_coord ; check malloced pointers before using them --- star.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/star.c b/star.c index 068c2b1..d9a5201 100644 --- a/star.c +++ b/star.c @@ -436,7 +436,7 @@ void make_a_move( struct state *s, direction where ) { int motion[ 2 ] = { 0, 0 }; int item_coord[ 2 ]; - get_pos( s, &item_coord, s->moving ); /* get the coordinates of the moving actor */ + get_pos( s, item_coord, s->moving ); /* get the coordinates of the moving actor */ /* Setup the motion vector according to direction.*/ switch( where ) { @@ -555,6 +555,10 @@ int main( int argc, char* argv[] ) struct state *s = malloc( sizeof( struct state ) ); struct options *o = malloc( sizeof( struct options ) ); + if ( s == NULL || o == NULL ) { + return 1; /* Guys, we're out of memory */ + } + /* trick to count how many levels we have */ s->nb_levels = sizeof( levels ) / sizeof( levels[ 0 ] );