diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index f558664..75eee24 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -11,7 +11,7 @@ on: - devel env: - BUILD_TYPE: Release + BUILD_TYPE: Debug jobs: build: @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -S . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install + run: cmake -B ${{github.workspace}}/build -S . -L -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install - name: Build run: cmake --build ${{github.workspace}}/build --target install --config ${{env.BUILD_TYPE}} diff --git a/CHANGELOG b/CHANGELOG index cd07237..f643e56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ All changes to the repository will be reported here +## [0.2.2] +### Fixed +- Number of nodes allocated in create_graph + ## [0.2.1] ### Updated - cmake exports diff --git a/CMakeLists.txt b/CMakeLists.txt index e9fcc33..b056659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ Author Marco M. Mosca, email: marcomichele.mosca@gmail.com ]] cmake_minimum_required(VERSION 3.5.0) -project(graphoc VERSION 0.2.1 LANGUAGES C) +project(graphoc VERSION 0.2.2 LANGUAGES C) include(CTest) diff --git a/README.md b/README.md index d495606..9814293 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ int main(int argc, char* argv[]) { ## Tests (only on static build) ``` cmake -B build -S . -L -DCMAKE_INSTALL_PREFIX= -cmake --build .\build --target install --config Release +cmake --build .\build --target install --config Debug cd build -ctest --build-config Release --build-target install +ctest --build-config Debug --build-target install ``` diff --git a/graphoc/include/graph.h b/graphoc/include/graph.h index 4b327b3..098f46f 100755 --- a/graphoc/include/graph.h +++ b/graphoc/include/graph.h @@ -167,11 +167,11 @@ int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g); /** Create a graph \param n Number of Nodes - \param labels Pointer to array of labels: + \param labels Pointer to array of labels with NULL terminator: static const char* labels[] = { "CAMBRIDGE", "LONDON", - "MACHESTER", + "MANCHESTER", "LIVERPOOL", NULL, }; diff --git a/graphoc/src/graph.c b/graphoc/src/graph.c index e713309..74bd627 100755 --- a/graphoc/src/graph.c +++ b/graphoc/src/graph.c @@ -98,23 +98,21 @@ graph_t * create_graph (unsigned int n, char **labels) errno = EINVAL; if ((labels == NULL) || (n==0)) {return NULL;}; errno = ENOMEM; - if ((k=malloc(sizeof(graph_t))) == NULL) {return NULL;}; - nodo=malloc(n * sizeof(node_t)); - if (nodo == NULL) {free(k);return NULL;}; + if ((k=(graph_t*)malloc(sizeof(graph_t))) == NULL) {return NULL;}; + if ((nodo=(node_t*)malloc((n+1) * sizeof(node_t))) == NULL) {free(k);return NULL;}; k->size = n; while (ilabel = s; - + (nodo+i)->label = s; (nodo+i)->adj = NULL; i++; } (nodo+i)->label=NULL; + (nodo+i)->adj = NULL; k->node = nodo; return k; } @@ -462,16 +460,13 @@ graph_t* load_graph (FILE * nodefile, FILE * edgefile) int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g) { - int i=0, len; + int i=0; node_t* node; edge_t* ag; double d; unsigned int j; - char* s; if((nodefile==NULL) || (edgefile==NULL) || g==NULL) {errno=EINTR;return -1;}; - - s=malloc(3 * sizeof(char)); errno=EIO; node = g->node; while((node+i)->label != NULL) @@ -481,14 +476,11 @@ int save_graph (FILE * nodefile, FILE * edgefile, graph_t* g) while(ag != NULL) { d=ag->weight; - sprintf(s,"%f",d); j=ag->label; - len = strlen((node+i)->label)+strlen((node+j)->label)+strlen(s); if((fprintf(edgefile, "%s:%s:%.1f\n", (node+i)->label,(node+j)->label,d))<0) {return -1;}; ag=ag->next; } i++; } - free(s); return 0; } diff --git a/tests/test_get_degree.c b/tests/test_get_degree.c index f57f72e..7949f45 100644 --- a/tests/test_get_degree.c +++ b/tests/test_get_degree.c @@ -23,7 +23,7 @@ void test_get_degree() { graph_t* graph; if ( ( graph = create_graph(5, labels) ) == NULL ) { - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } for(char** p=edges; *p!=NULL; p++){ if ( add_edge(graph,*p) == -1 ) { @@ -40,6 +40,6 @@ void test_get_degree() int main() { - test_get_degree(); - return 0; + test_get_degree(); + return 0; } diff --git a/tests/test_get_edge_count.c b/tests/test_get_edge_count.c index 2e51750..94f4979 100644 --- a/tests/test_get_edge_count.c +++ b/tests/test_get_edge_count.c @@ -21,23 +21,23 @@ Author Marco M. Mosca, email: marcomichele.mosca@gmail.com void test_get_edge_count() { - graph_t* graph; - if ( ( graph = create_graph(5, labels) ) == NULL ) { + graph_t* graph; + if ( ( graph = create_graph(5, labels) ) == NULL ) { exit(EXIT_FAILURE); - } - for(char** e=edges; *e!=NULL; e++){ + } + for(char** e=edges; *e!=NULL; e++){ if ( add_edge(graph,*e) == -1 ) { fprintf(stderr, "Adding edge failed: %s", *e); perror(""); exit(EXIT_FAILURE); } - } + } assert(get_edge_count(graph) == 6); - free_graph(&graph); + free_graph(&graph); } int main() { - test_get_edge_count(); - return 0; + test_get_edge_count(); + return 0; }