1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 10:03:01 +01:00

cleanup: fix some uninitialized memory warnings and clarify some logic

This commit is contained in:
jfreegman 2021-12-13 12:33:52 -05:00
parent bf1e1b73fc
commit 3f18c6f8de
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 27 additions and 23 deletions

View File

@ -517,10 +517,10 @@ static void game_draw_help_bar(const GameData *game, WINDOW *win)
{ {
int max_x; int max_x;
int max_y; int max_y;
UNUSED_VAR(max_x);
getmaxyx(win, max_y, max_x); getmaxyx(win, max_y, max_x);
UNUSED_VAR(max_x);
wmove(win, max_y - 1, 1); wmove(win, max_y - 1, 1);
if (!game->is_multiplayer) { if (!game->is_multiplayer) {
@ -937,10 +937,10 @@ int game_y_bottom_bound(const GameData *game)
{ {
int max_x; int max_x;
int max_y; int max_y;
UNUSED_VAR(max_x);
getmaxyx(game->window, max_y, max_x); getmaxyx(game->window, max_y, max_x);
UNUSED_VAR(max_x);
return ((max_y + game->game_max_y) / 2) - 1; return ((max_y + game->game_max_y) / 2) - 1;
} }
@ -948,10 +948,10 @@ int game_y_top_bound(const GameData *game)
{ {
int max_x; int max_x;
int max_y; int max_y;
UNUSED_VAR(max_x);
getmaxyx(game->window, max_y, max_x); getmaxyx(game->window, max_y, max_x);
UNUSED_VAR(max_x);
return ((max_y - game->game_max_y) / 2) + 1; return ((max_y - game->game_max_y) / 2) + 1;
} }
@ -959,10 +959,10 @@ int game_x_right_bound(const GameData *game)
{ {
int max_x; int max_x;
int max_y; int max_y;
UNUSED_VAR(max_y);
getmaxyx(game->window, max_y, max_x); getmaxyx(game->window, max_y, max_x);
UNUSED_VAR(max_y);
return ((max_x + game->game_max_x) / 2) - 1; return ((max_x + game->game_max_x) / 2) - 1;
} }
@ -970,10 +970,10 @@ int game_x_left_bound(const GameData *game)
{ {
int max_x; int max_x;
int max_y; int max_y;
UNUSED_VAR(max_y);
getmaxyx(game->window, max_y, max_x); getmaxyx(game->window, max_y, max_x);
UNUSED_VAR(max_y);
return ((max_x - game->game_max_x) / 2) + 1; return ((max_x - game->game_max_x) / 2) + 1;
} }

View File

@ -804,11 +804,13 @@ static bool chess_mock_move_valid(ChessState *state, const Player *player, Tile
{ {
Board *board = &state->board; Board *board = &state->board;
const bool en_passant = player->en_passant_move_number == -1;
bool in_check = false; bool in_check = false;
Tile *ep_tile = NULL; Tile *ep_tile = NULL;
Piece ep_piece; Piece ep_piece;
memset(&ep_piece, 0, sizeof(ep_piece));
if (player->en_passant_move_number == -1) { // remove piece that was captured via en passant if (en_passant) { // remove piece that was captured via en passant
ChessCoords ep_coords; ChessCoords ep_coords;
ep_coords.N = player->colour == White ? to->chess_coords.N - 1 : to->chess_coords.N + 1; ep_coords.N = player->colour == White ? to->chess_coords.N - 1 : to->chess_coords.N + 1;
ep_coords.L = to->chess_coords.L; ep_coords.L = to->chess_coords.L;
@ -819,7 +821,7 @@ static bool chess_mock_move_valid(ChessState *state, const Player *player, Tile
} }
chess_copy_piece(&ep_piece, &ep_tile->piece); chess_copy_piece(&ep_piece, &ep_tile->piece);
ep_tile->piece.type = NoPiece; ep_tile->piece.type = NoPiece; // temporarily remove piece
} }
Piece from_piece; Piece from_piece;
@ -835,8 +837,8 @@ static bool chess_mock_move_valid(ChessState *state, const Player *player, Tile
from->piece.type = from_piece.type; from->piece.type = from_piece.type;
chess_copy_piece(&to->piece, &to_piece); chess_copy_piece(&to->piece, &to_piece);
if (player->en_passant_move_number == -1) { if (en_passant) {
ep_tile->piece.type = ep_piece.type; ep_tile->piece.type = ep_piece.type; // reset piece to original state
} }
return !in_check; return !in_check;

View File

@ -148,9 +148,10 @@ static int print_n_chars(WINDOW *win, const char *s, size_t n, int max_y)
int x; int x;
int y; int y;
UNUSED_VAR(x);
getyx(win, y, x); getyx(win, y, x);
UNUSED_VAR(x);
// make sure cursor will wrap correctly after newline to prevent display bugs // make sure cursor will wrap correctly after newline to prevent display bugs
if (y + 1 >= max_y) { if (y + 1 >= max_y) {
return -1; return -1;
@ -324,10 +325,10 @@ static void line_info_init_line(ToxWindow *self, struct line_info *line)
{ {
int y2; int y2;
int x2; int x2;
UNUSED_VAR(y2);
getmaxyx(self->window, y2, x2); getmaxyx(self->window, y2, x2);
UNUSED_VAR(y2);
const int max_y = y2 - CHATBOX_HEIGHT - WINDOW_BAR_HEIGHT; const int max_y = y2 - CHATBOX_HEIGHT - WINDOW_BAR_HEIGHT;
const int max_x = self->show_peerlist ? x2 - 1 - SIDEBAR_WIDTH : x2; const int max_x = self->show_peerlist ? x2 - 1 - SIDEBAR_WIDTH : x2;
@ -522,10 +523,10 @@ void line_info_print(ToxWindow *self)
while (line && numlines++ <= max_y && print_ret == 0) { while (line && numlines++ <= max_y && print_ret == 0) {
int y; int y;
int x; int x;
UNUSED_VAR(y);
getyx(win, y, x); getyx(win, y, x);
UNUSED_VAR(y);
if (x > 0) { // Prevents us from printing off the screen if (x > 0) { // Prevents us from printing off the screen
break; break;
} }

View File

@ -108,14 +108,15 @@ static int load_nameserver_list(const char *path)
char line[MAX_SERVER_LINE]; char line[MAX_SERVER_LINE];
while (fgets(line, sizeof(line), fp) && Nameservers.lines < MAX_SERVERS) { while (fgets(line, sizeof(line), fp) && Nameservers.lines < MAX_SERVERS) {
int linelen = strlen(line); size_t linelen = strlen(line);
if (linelen < SERVER_KEY_SIZE * 2 + 5) { if (linelen < SERVER_KEY_SIZE * 2 + 5) {
continue; continue;
} }
if (line[linelen - 1] == '\n') { if (line[linelen - 1] == '\n') {
line[--linelen] = '\0'; --linelen;
line[linelen] = '\0';
} }
const char *name = strtok(line, " "); const char *name = strtok(line, " ");

View File

@ -685,10 +685,10 @@ void draw_window_bar(ToxWindow *self)
int cur_x; int cur_x;
int cur_y; int cur_y;
UNUSED_VAR(cur_y);
getyx(win, cur_y, cur_x); getyx(win, cur_y, cur_x);
UNUSED_VAR(cur_y);
wattron(win, COLOR_PAIR(BAR_TEXT)); wattron(win, COLOR_PAIR(BAR_TEXT));
mvwhline(win, 0, cur_x, ' ', COLS - cur_x); mvwhline(win, 0, cur_x, ' ', COLS - cur_x);
wattroff(win, COLOR_PAIR(BAR_TEXT)); wattroff(win, COLOR_PAIR(BAR_TEXT));