Skip to content

Commit 941f056

Browse files
committed
fix out of bounds accesses in midgame and search by increasin size of 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.
1 parent 5b08cc9 commit 941f056

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

midgame.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ static int do_check_midgame_abort = TRUE;
8282
static int counter_phase;
8383
static int apply_perturbation = TRUE;
8484
static int perturbation_amplitude = 0;
85-
static int stage_reached[61], stage_score[61];
85+
static int stage_reached[62] = {};
86+
static int stage_score[62] ={};
8687
static int score_perturbation[100];
8788
static int feas_index_list[64][64];
8889

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

100101
allow_midgame_hash_probe = TRUE;
101102
allow_midgame_hash_update = TRUE;
102-
for ( i = 0; i <= 60; i++ )
103+
for ( i = 0; i <= 61; i++ )
103104
stage_reached[i] = FALSE;
104105

105106
calculate_perturbation();

search.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int root_eval;
3535
int force_return;
3636
int full_pv_depth;
3737
int full_pv[120];
38-
int list_inherited[61];
38+
int list_inherited[62];
3939
int sorted_move_order[64][64]; /* 61*60 used */
4040
Board evals[61];
4141
CounterType nodes, total_nodes;
@@ -82,7 +82,7 @@ init_move_lists( void ) {
8282
for ( j = 0; j < MOVE_ORDER_SIZE; j++ )
8383
sorted_move_order[i][j] = position_list[j];
8484
}
85-
for ( i = 0; i <= 60; i++ )
85+
for ( i = 0; i <= 61; i++ )
8686
list_inherited[i] = FALSE;
8787
}
8888

@@ -99,7 +99,9 @@ void
9999
inherit_move_lists( int stage ) {
100100
int i;
101101
int last;
102-
102+
if(stage >= 61) {
103+
return;
104+
}
103105
if ( list_inherited[stage] )
104106
return;
105107
list_inherited[stage] = TRUE;

0 commit comments

Comments
 (0)