From f1a7683c93facd0fcbc9e75fcf7da7cd611c6715 Mon Sep 17 00:00:00 2001 From: David Wehr <dawehr@iastate.edu> Date: Sat, 1 Apr 2017 12:33:35 -0500 Subject: [PATCH] Fixed error with reading/writing wrong bit location in ID exist array. --- quad/src/computation_graph/computation_graph.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/quad/src/computation_graph/computation_graph.c b/quad/src/computation_graph/computation_graph.c index 8720fcb98..6422d5b11 100644 --- a/quad/src/computation_graph/computation_graph.c +++ b/quad/src/computation_graph/computation_graph.c @@ -11,9 +11,9 @@ static double exec_input_vals[GRAPH_MAX_INPUTS]; // Macro functions for setting and clearing single bits in int array // From http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html -#define setBit(A,k) ( A[(k / sizeof(int))] |= (1 << (k % sizeof(int))) ) -#define clearBit(A,k) ( A[(k / sizeof(int))] &= ~(1 << (k % sizeof(int))) ) -#define testBit(A,k) ( A[(k / sizeof(int))] & (1 << (k % sizeof(int))) ) +#define setBit(A,k) ( A[(k / (8*sizeof(int)))] |= (1 << (k % (8*sizeof(int)))) ) +#define clearBit(A,k) ( A[(k / (8*sizeof(int)))] &= ~(1 << (k % (8*sizeof(int)))) ) +#define testBit(A,k) ( A[(k / (8*sizeof(int)))] & (1 << (k % (8*sizeof(int)))) ) struct computation_graph *create_graph() { struct computation_graph *the_graph = malloc(sizeof(struct computation_graph)); @@ -120,16 +120,16 @@ int graph_add_node_id(struct computation_graph *graph, if (!node_arr) { return -1; } // Number of integers needed to hold new_size bits size_t new_exist_size = ceil((float)new_size / (8 * sizeof(int))); // ceil(new_size / (bits per int)) - int* exist_arr = realloc(graph->node_existence, sizeof(int) * new_exist_size); - if (!exist_arr) {return -1;} // Set the newly allocated memory to 0 size_t old_exist_size = ceil((float)old_size / (8 * sizeof(int))); if (old_exist_size != new_exist_size) { + int* exist_arr = realloc(graph->node_existence, sizeof(int) * new_exist_size); + if (!exist_arr) {return -1;} memset(exist_arr + old_exist_size, 0, (new_exist_size - old_exist_size) * sizeof(int)); + graph->node_existence = exist_arr; } graph->size = new_size; graph->nodes = node_arr; - graph->node_existence = exist_arr; } struct graph_node *new_node = &graph->nodes[id]; new_node->name = strdup(name); -- GitLab