Skip to content

Commit

Permalink
fix incorrect function return type and do proper bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Jul 29, 2024
1 parent 86e3294 commit 062b9d5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/game_chess.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,20 +500,20 @@ static bool chess_path_diagonal_clear(Board *board, const Tile *from, const Tile
bool left_diag = (from->chess_coords.N > to->chess_coords.N && from->chess_coords.L < to->chess_coords.L)
|| (from->chess_coords.N < to->chess_coords.N && from->chess_coords.L > to->chess_coords.L);

size_t from_l_idx = chess_get_letter_index(from->chess_coords.L);
size_t to_l_idx = chess_get_letter_index(to->chess_coords.L);
size_t start_l_idx = left_diag ? MAX(from_l_idx, to_l_idx) - 1 : MIN(from_l_idx, to_l_idx) + 1;
const int from_l_idx = chess_get_letter_index(from->chess_coords.L);
const int to_l_idx = chess_get_letter_index(to->chess_coords.L);
int start_l_idx = left_diag ? MAX(from_l_idx, to_l_idx) - 1 : MIN(from_l_idx, to_l_idx) + 1;

if (start_l_idx == -1) {
return -1;
if (start_l_idx < 0) {
return false;
}

ChessCoords chess_coords;

for (size_t i = start; i < end; ++i) {
chess_coords.N = i;

if (start_l_idx >= CHESS_NUM_BOARD_LETTERS) {
if (start_l_idx >= CHESS_NUM_BOARD_LETTERS || start_l_idx < 0) {
return false;
}

Expand Down

0 comments on commit 062b9d5

Please sign in to comment.