mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-22 17:13:25 +01:00
cleanup: fix some uninitialized memory warnings and clarify some logic
This commit is contained in:
parent
bf1e1b73fc
commit
3f18c6f8de
@ -517,10 +517,10 @@ static void game_draw_help_bar(const GameData *game, WINDOW *win)
|
||||
{
|
||||
int max_x;
|
||||
int max_y;
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
getmaxyx(win, max_y, max_x);
|
||||
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
wmove(win, max_y - 1, 1);
|
||||
|
||||
if (!game->is_multiplayer) {
|
||||
@ -937,10 +937,10 @@ int game_y_bottom_bound(const GameData *game)
|
||||
{
|
||||
int max_x;
|
||||
int max_y;
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
getmaxyx(game->window, max_y, max_x);
|
||||
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
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_y;
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
getmaxyx(game->window, max_y, max_x);
|
||||
|
||||
UNUSED_VAR(max_x);
|
||||
|
||||
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_y;
|
||||
UNUSED_VAR(max_y);
|
||||
|
||||
getmaxyx(game->window, max_y, max_x);
|
||||
|
||||
UNUSED_VAR(max_y);
|
||||
|
||||
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_y;
|
||||
UNUSED_VAR(max_y);
|
||||
|
||||
getmaxyx(game->window, max_y, max_x);
|
||||
|
||||
UNUSED_VAR(max_y);
|
||||
|
||||
return ((max_x - game->game_max_x) / 2) + 1;
|
||||
}
|
||||
|
||||
|
@ -804,11 +804,13 @@ static bool chess_mock_move_valid(ChessState *state, const Player *player, Tile
|
||||
{
|
||||
Board *board = &state->board;
|
||||
|
||||
const bool en_passant = player->en_passant_move_number == -1;
|
||||
bool in_check = false;
|
||||
Tile *ep_tile = NULL;
|
||||
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;
|
||||
ep_coords.N = player->colour == White ? to->chess_coords.N - 1 : to->chess_coords.N + 1;
|
||||
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);
|
||||
ep_tile->piece.type = NoPiece;
|
||||
ep_tile->piece.type = NoPiece; // temporarily remove 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;
|
||||
chess_copy_piece(&to->piece, &to_piece);
|
||||
|
||||
if (player->en_passant_move_number == -1) {
|
||||
ep_tile->piece.type = ep_piece.type;
|
||||
if (en_passant) {
|
||||
ep_tile->piece.type = ep_piece.type; // reset piece to original state
|
||||
}
|
||||
|
||||
return !in_check;
|
||||
|
@ -148,9 +148,10 @@ static int print_n_chars(WINDOW *win, const char *s, size_t n, int max_y)
|
||||
|
||||
int x;
|
||||
int y;
|
||||
UNUSED_VAR(x);
|
||||
getyx(win, y, x);
|
||||
|
||||
UNUSED_VAR(x);
|
||||
|
||||
// make sure cursor will wrap correctly after newline to prevent display bugs
|
||||
if (y + 1 >= max_y) {
|
||||
return -1;
|
||||
@ -324,10 +325,10 @@ static void line_info_init_line(ToxWindow *self, struct line_info *line)
|
||||
{
|
||||
int y2;
|
||||
int x2;
|
||||
UNUSED_VAR(y2);
|
||||
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
UNUSED_VAR(y2);
|
||||
|
||||
const int max_y = y2 - CHATBOX_HEIGHT - WINDOW_BAR_HEIGHT;
|
||||
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) {
|
||||
int y;
|
||||
int x;
|
||||
UNUSED_VAR(y);
|
||||
|
||||
getyx(win, y, x);
|
||||
|
||||
UNUSED_VAR(y);
|
||||
|
||||
if (x > 0) { // Prevents us from printing off the screen
|
||||
break;
|
||||
}
|
||||
|
@ -108,14 +108,15 @@ static int load_nameserver_list(const char *path)
|
||||
char line[MAX_SERVER_LINE];
|
||||
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line[linelen - 1] == '\n') {
|
||||
line[--linelen] = '\0';
|
||||
--linelen;
|
||||
line[linelen] = '\0';
|
||||
}
|
||||
|
||||
const char *name = strtok(line, " ");
|
||||
|
@ -685,10 +685,10 @@ void draw_window_bar(ToxWindow *self)
|
||||
|
||||
int cur_x;
|
||||
int cur_y;
|
||||
UNUSED_VAR(cur_y);
|
||||
|
||||
getyx(win, cur_y, cur_x);
|
||||
|
||||
UNUSED_VAR(cur_y);
|
||||
|
||||
wattron(win, COLOR_PAIR(BAR_TEXT));
|
||||
mvwhline(win, 0, cur_x, ' ', COLS - cur_x);
|
||||
wattroff(win, COLOR_PAIR(BAR_TEXT));
|
||||
|
Loading…
Reference in New Issue
Block a user