Commit b642893f724b0e952ef7bbf72a2e0804fa1e1a7c
1 parent
72504c12d4
Exists in
master
and in
1 other branch
fixed the segfault
it was happening because of a dangling pointer in addp()
Showing 2 changed files with 8 additions and 8 deletions Side-by-side Diff
client/entities/player.c
View file @
b642893
client/main.c
View file @
b642893
... | ... | @@ -97,15 +97,15 @@ |
97 | 97 | addp(PLAYER *node,TCPsocket srv_sock) |
98 | 98 | { |
99 | 99 | Uint16 magic; |
100 | + PLAYER *cur_player = NULL; | |
100 | 101 | do |
101 | 102 | { |
102 | - PLAYER cur_player; | |
103 | - init_player(srv_sock, &cur_player); | |
104 | - add_player(node,&cur_player); | |
103 | + cur_player = calloc(1,sizeof(PLAYER)); | |
104 | + init_player(srv_sock,cur_player); | |
105 | + add_player(node,cur_player); | |
106 | + printf("Player %s (%d) connected, at (%d, %d)\n", cur_player->name, | |
107 | + cur_player->playerno, cur_player->x, cur_player->y); | |
105 | 108 | |
106 | - printf("Player %s (%d) connected, at (%d, %d)\n", cur_player.name, | |
107 | - cur_player.playerno, cur_player.x, cur_player.y); | |
108 | - | |
109 | 109 | } while ((magic = getshort(srv_sock)) == ADD_PLAYER); |
110 | 110 | |
111 | 111 | printf("players added\n"); |
... | ... | @@ -256,7 +256,7 @@ |
256 | 256 | */ |
257 | 257 | |
258 | 258 | SDLNet_TCP_Recv(srv_sock, &myno, 1); |
259 | - player = calloc(MAX_PLAYERNUM + 1, sizeof(PLAYER)); | |
259 | + player = calloc(1, sizeof(PLAYER)); | |
260 | 260 | draw_maze(MAZE.X, MAZE.Y); |
261 | 261 | |
262 | 262 |