fix a memory leak
[calc.git] / tabular.c
index 0252a8e8ec1bf82aad5e3f6a723db40644fe35de..83c17898248b07dd3495be769bbcdc7b35eddd2c 100644 (file)
--- a/tabular.c
+++ b/tabular.c
@@ -43,6 +43,9 @@ tab_t *resize_tab (tab_t *tab, int nb)
 
 tab_t *copy_tab (tab_t *tab)
 {
+    if (tab == NULL) {
+        return NULL;
+    }
     tab_t *new = alloc_tab (tab->size);
     memcpy (new->data, tab->data, tab->size * sizeof (double));
     return new;
@@ -154,8 +157,8 @@ double pop_tab (tab_t *tab, int id)
 void order_tab (tab_t *tab)
 {
     int i, j;
-    if ((!tab) || (tab->size < 3)) {
-        VERBOSE (WARNING, fprintf (stdout, "error not enough element in stack (%d)\n", tab->size));
+    if ((!tab) || (tab->size < 2)) {
+        VERBOSE (WARNING, fprintf (stdout, "error not enough element in stack (%d)\n", (tab) ? tab->size : 0));
         return;
     }