commit 665c96e6ef6399f0e5da40fe40badc208b1eba47
parent b16e78a9086da907290ff39cc6321109a4f5d70b
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sun, 15 Jan 2023 05:57:29 +0900
initialize pointers with NULL
Diffstat:
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/ex9/main.c b/ex9/main.c
@@ -58,7 +58,7 @@ enum debug_msg {
/* variables */
enum next_menu next_menu = START_MENU;
-void (* col_func[NUM_OBJ_TYPE][NUM_OBJ_TYPE])(Object *, Object *);
+void (* col_func[NUM_OBJ_TYPE][NUM_OBJ_TYPE])(Object *, Object *) = {0};
/* function prototypes */
/* menus */
@@ -140,9 +140,9 @@ game_play(void)
enum key_state key_state[NUM_KEY];
long t0, t1, dt;
struct timespec ts;
- List *ol; // block list
- Object *player;
- List *olc; // cursor used to scan ol
+ List *ol = NULL; // block list
+ Object *player = NULL;
+ List *olc = NULL; // cursor used to scan ol
int scroll_dst = 0;
int scroll_margin = WIN_WIDTH * 2 / 5;
@@ -153,12 +153,7 @@ game_play(void)
struct rusage rusage; // for debuging of memory leak
- ol = NULL;
-
/* setup collision handler */
- for (int i = 0; i < NUM_OBJ_TYPE; i++)
- for (int j = 0; j < NUM_OBJ_TYPE; j++)
- col_func[i][j] = NULL;
col_func[TPLAYER][TFLAG] = col_func[TFLAG][TPLAYER] = &col_pf;
col_func[TPLAYER][TBLOCK] = col_func[TBLOCK][TPLAYER] = &col_pb;
col_func[TPLAYER][TENEMY] = col_func[TENEMY][TPLAYER] = &col_pe;
@@ -176,7 +171,7 @@ game_play(void)
BLOCK_SIZE * BLOCK_SIZE,
NULL));
if (olc == NULL) {
- fprintf(stderr, "error: adding item to list ol\n");
+ fprintf(stderr, "main: error. adding item to list ol\n");
} else {
ol = olc;
}
@@ -190,7 +185,7 @@ game_play(void)
NULL);
olc = laddfront(ol, player);
if (player == NULL || olc == NULL) {
- fprintf(stderr, "error: creating player\n");
+ fprintf(stderr, "main: error. creating player\n");
exit(1);
} else {
ol = olc;
@@ -204,7 +199,7 @@ game_play(void)
BLOCK_SIZE * BLOCK_SIZE,
NULL));
if (olc == NULL) {
- fprintf(stderr, "error: adding item to list ol\n");
+ fprintf(stderr, "main: error. adding item to list ol\n");
} else {
ol = olc;
}