Skip to content

Commit

Permalink
fix #458, occasional crash in sampleIndividuals()
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Jul 19, 2024
1 parent fb60b1c commit 15c27fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ development head (in the master branch):
update Robin Hood Hashing to 3.11.5 to get some minor fixes
update zlib from 1.2.13 to 1.3.1 to get some minor fixes
some fixes under the hood to make filesystem paths on Windows, using \ instead of /, be better understood by Eidos
fix an occasional crash in sampleIndividuals() due to an off-by-one error in buffer sizing


version 4.2.2 (Eidos version 3.2.2):
Expand Down
4 changes: 2 additions & 2 deletions core/subpopulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7734,9 +7734,9 @@ EidosValue_SP Subpopulation::ExecuteMethod_sampleIndividuals(EidosGlobalStringID
static int *index_buffer = nullptr;
static int buffer_capacity = 0;

if (last_candidate_index > buffer_capacity) // just make it big enough for last_candidate_index, not worth worrying
if (last_candidate_index + 1 > buffer_capacity) // just make it big enough for last_candidate_index, not worth worrying
{
buffer_capacity = last_candidate_index * 2; // double whenever we go over capacity, to avoid reallocations
buffer_capacity = (last_candidate_index + 1) * 2; // double whenever we go over capacity, to avoid reallocations
if (index_buffer)
free(index_buffer);
index_buffer = (int *)malloc(buffer_capacity * sizeof(int)); // no need to realloc, we don't need the old data
Expand Down

0 comments on commit 15c27fd

Please sign in to comment.