Skip to content

Commit

Permalink
kernel: fix off by one error
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Aug 28, 2024
1 parent ea32c77 commit 15f8517
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/homos.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extern Obj LargestMovedPointPerms;

static Obj GAP_FUNC; // Variable to hold a GAP level hook function

static Obj (*HOOK)(void*, // HOOK function applied to every homo found
static Obj (*HOOK)(void*, // HOOK function applied to every homo found
const uint16_t,
const uint16_t*);
static void* USER_PARAM; // a USER_PARAM for the hook
Expand Down Expand Up @@ -1642,14 +1642,20 @@ static bool init_data_from_args(Obj digraph1_obj,
uint16_t calculated_max_verts =
MAX(DigraphNrVertices(digraph1_obj), DigraphNrVertices(digraph2_obj));
if (!homos_data_initialized
|| (calculated_max_verts > HOMOS_STRUCTURE_SIZE)) {
|| (calculated_max_verts >= HOMOS_STRUCTURE_SIZE)) {
FuncDIGRAPHS_FREE_HOMOS_DATA(0L);
homos_data_initialized = true;

// Rather arbitrary, but we multiply by 1.2 to avoid
// n = 1,2,3,4,5... causing constant reallocation
HOMOS_STRUCTURE_SIZE = calculated_max_verts + calculated_max_verts / 5;
// srand(time(0));
HOMOS_STRUCTURE_SIZE =
(calculated_max_verts + calculated_max_verts / 5) + 1;
// The previous line includes "+ 1" because below we do:
// "BLISS_GRAPH[3 * PERM_DEGREE]" but we only allocate bliss graphs in
// BLISS_GRAPH up to but not including 3 * HOMOS_STRUCTURE_SIZE. So if
// PERM_DEGREE = (# nodes in digraph2) = HOMOS_STRUCTURE_SIZE (the
// first equality always holds, the second if # nodes in digraph2 >
// # nodes in digraph1), then this is out of bounds.
#ifdef DIGRAPHS_ENABLE_STATS
STATS = safe_malloc(sizeof(HomoStats));
#endif
Expand Down

0 comments on commit 15f8517

Please sign in to comment.