mirror of
https://github.com/gwenhael-le-moine/c-urs_-toil-s.git
synced 2024-12-27 09:58:44 +01:00
fix passing item_coord ; check malloced pointers before using them
This commit is contained in:
parent
373979459b
commit
a738393ba6
1 changed files with 5 additions and 1 deletions
6
star.c
6
star.c
|
@ -436,7 +436,7 @@ void make_a_move( struct state *s, direction where )
|
||||||
{
|
{
|
||||||
int motion[ 2 ] = { 0, 0 };
|
int motion[ 2 ] = { 0, 0 };
|
||||||
int item_coord[ 2 ];
|
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.*/
|
/* Setup the motion vector according to direction.*/
|
||||||
switch( where ) {
|
switch( where ) {
|
||||||
|
@ -555,6 +555,10 @@ int main( int argc, char* argv[] )
|
||||||
struct state *s = malloc( sizeof( struct state ) );
|
struct state *s = malloc( sizeof( struct state ) );
|
||||||
struct options *o = malloc( sizeof( struct options ) );
|
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 */
|
/* trick to count how many levels we have */
|
||||||
s->nb_levels = sizeof( levels ) / sizeof( levels[ 0 ] );
|
s->nb_levels = sizeof( levels ) / sizeof( levels[ 0 ] );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue