TP 11 exo1: simplify the logic in the array creation and resizing
[TD_C.git] / TP_13 / exo1 / lib / array.c
index f7e324f662e21e73bb86c8bcc1850d9ae36b1b72..d2e6182808f6dea9fa87ff335d02771d6782c58f 100644 (file)
@@ -4,15 +4,13 @@
 
 int* create_tab(int tab[], unsigned tab_size) {
     tab = malloc(sizeof(int) * tab_size);
-    if (tab == NULL) {
-        return NULL;
-    } else {
+    if (tab != NULL) {
         /* initialize to zero the integer array */
         for (unsigned i = 0; i < tab_size; i++) {
             tab[i] = 0;
         }
-        return tab;
     }
+    return tab;
 }
 
 void free_tab(int tab[]) {
@@ -38,11 +36,7 @@ int* concat_tab(int tab1[], unsigned tab_size1, int tab2[], unsigned tab_size2,
 
 int* resize_tab(int tab[], unsigned new_tab_size) {
     tab = realloc(tab, sizeof(int) * new_tab_size);
-    if (tab == NULL) {
-        return NULL;
-    } else {
-        return tab;
-    }
+    return tab;
 }
 
 /* number of occurences of an element in an unsorted array  */