From 17b14223977633c6f2581191e7aa1392b6f1d3cb Mon Sep 17 00:00:00 2001
From: Abivarman <abivarman.kandiah@etu.hesge.ch>
Date: Wed, 23 Feb 2022 13:27:49 +0100
Subject: [PATCH] Add asserts in functions

---
 header/vectors.h   | 1 +
 src/test_vectors.c | 4 ++--
 src/vectors.c      | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/header/vectors.h b/header/vectors.h
index ad1d322..257dc2f 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 2605805..3e181f1 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 c7a85b3..1440087 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;
 	}
 
-- 
GitLab