diff --git a/header/vectors.h b/header/vectors.h index ad1d322220fd1e2cb66a5fe2d4bc1b8fdabd0475..257dc2fd24bca4a96310064d7208157cc1191b18 100644 --- a/header/vectors.h +++ b/header/vectors.h @@ -14,6 +14,7 @@ #include <stdlib.h> #include <stdint.h> #include <stdbool.h> +#include <assert.h> typedef int type; typedef struct vector_* vector; diff --git a/src/test_vectors.c b/src/test_vectors.c index 2605805593751c95dfa9a979d18d69efea3cbe77..3e181f1d528596003ddea6cf9edb054e3af6d2a3 100644 --- a/src/test_vectors.c +++ b/src/test_vectors.c @@ -14,10 +14,10 @@ int main() { vector test = vector_create(); - printf("%d \n", vector_length(test)); + printf("Created Vector lenght : %d \n", vector_length(test)); vector_push(test, 15); - printf("%d \n", vector_length(test)); + printf("Modified Vector lenght : %d \n", vector_length(test)); return 0; } \ No newline at end of file diff --git a/src/vectors.c b/src/vectors.c index c7a85b38a2d3895c860241759dacff031cdc0ce3..14400878c9506196193d8754032864162fa3953f 100644 --- a/src/vectors.c +++ b/src/vectors.c @@ -17,7 +17,11 @@ vector vector_create() { vector vec = malloc(sizeof(*vec)); //!BUG POSSIBLE + assert(vec != NULL); + vec->content = malloc(sizeof(type) * VECTOR_INIT_CAPACITY); + assert(vec->content != NULL); + vec->capacity = VECTOR_INIT_CAPACITY; vec->length = 0; @@ -34,6 +38,8 @@ void vector_push(vector vec, type element) if(vec->length >= vec->capacity) { vec->content = realloc(vec->content, sizeof(type) * vec->capacity * 2); + assert(vec->content != NULL); + vec->capacity = vec->capacity * 2; }