Skip to content

Commit

Permalink
fix out of bounds accesses in midgame and search by increasin size of…
Browse files Browse the repository at this point in the history
… used arrays

This changes the behaviour of the program in certain cases, which means there was some undefined behaviour present before, because those lengths are literals and they are never used anywhere, except for setting the length at the definition.
  • Loading branch information
panstromek committed Feb 20, 2022
1 parent a2e4fef commit 881be18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions midgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ static int do_check_midgame_abort = TRUE;
static int counter_phase;
static int apply_perturbation = TRUE;
static int perturbation_amplitude = 0;
static int stage_reached[61], stage_score[61];
static int stage_reached[62] = {};
static int stage_score[62] ={};
static int score_perturbation[100];
static int feas_index_list[64][64];

Expand All @@ -99,7 +100,7 @@ setup_midgame( void ) {

allow_midgame_hash_probe = TRUE;
allow_midgame_hash_update = TRUE;
for ( i = 0; i <= 60; i++ )
for ( i = 0; i <= 61; i++ )
stage_reached[i] = FALSE;

calculate_perturbation();
Expand Down
8 changes: 5 additions & 3 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int root_eval;
int force_return;
int full_pv_depth;
int full_pv[120];
int list_inherited[61];
int list_inherited[62];
int sorted_move_order[64][64]; /* 61*60 used */
Board evals[61];
CounterType nodes, total_nodes;
Expand Down Expand Up @@ -82,7 +82,7 @@ init_move_lists( void ) {
for ( j = 0; j < MOVE_ORDER_SIZE; j++ )
sorted_move_order[i][j] = position_list[j];
}
for ( i = 0; i <= 60; i++ )
for ( i = 0; i <= 61; i++ )
list_inherited[i] = FALSE;
}

Expand All @@ -99,7 +99,9 @@ void
inherit_move_lists( int stage ) {
int i;
int last;

if(stage >= 61) {
return;
}
if ( list_inherited[stage] )
return;
list_inherited[stage] = TRUE;
Expand Down

0 comments on commit 881be18

Please sign in to comment.