Skip to content
Snippets Groups Projects
Commit 17b14223 authored by abivarma.kandiah's avatar abivarma.kandiah
Browse files

Add asserts in functions

parent 0ed98ea3
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
typedef int type; typedef int type;
typedef struct vector_* vector; typedef struct vector_* vector;
......
...@@ -14,10 +14,10 @@ int main() ...@@ -14,10 +14,10 @@ int main()
{ {
vector test = vector_create(); vector test = vector_create();
printf("%d \n", vector_length(test)); printf("Created Vector lenght : %d \n", vector_length(test));
vector_push(test, 15); vector_push(test, 15);
printf("%d \n", vector_length(test)); printf("Modified Vector lenght : %d \n", vector_length(test));
return 0; return 0;
} }
\ No newline at end of file
...@@ -17,7 +17,11 @@ vector vector_create() ...@@ -17,7 +17,11 @@ vector vector_create()
{ {
vector vec = malloc(sizeof(*vec)); //!BUG POSSIBLE vector vec = malloc(sizeof(*vec)); //!BUG POSSIBLE
assert(vec != NULL);
vec->content = malloc(sizeof(type) * VECTOR_INIT_CAPACITY); vec->content = malloc(sizeof(type) * VECTOR_INIT_CAPACITY);
assert(vec->content != NULL);
vec->capacity = VECTOR_INIT_CAPACITY; vec->capacity = VECTOR_INIT_CAPACITY;
vec->length = 0; vec->length = 0;
...@@ -34,6 +38,8 @@ void vector_push(vector vec, type element) ...@@ -34,6 +38,8 @@ void vector_push(vector vec, type element)
if(vec->length >= vec->capacity) if(vec->length >= vec->capacity)
{ {
vec->content = realloc(vec->content, sizeof(type) * vec->capacity * 2); vec->content = realloc(vec->content, sizeof(type) * vec->capacity * 2);
assert(vec->content != NULL);
vec->capacity = vec->capacity * 2; vec->capacity = vec->capacity * 2;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment