correct push
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 13 Feb 2023 11:20:45 +0000 (12:20 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 13 Feb 2023 11:20:45 +0000 (12:20 +0100)
stack.c

diff --git a/stack.c b/stack.c
index 829f8aa6483f9357861680931a49a54d0a045799..a355fa5e3281b2fc34d1c3460c43701d776c99a2 100644 (file)
--- a/stack.c
+++ b/stack.c
@@ -1,3 +1,4 @@
+#include <math.h>
 #include <stdio.h>
 
 #include "debug.h"
@@ -30,7 +31,14 @@ double pop ()
 
 double push (double val)
 {
-    return push_tab (stack, -1, val);
+    double ret = NAN;
+    if (stack) {
+        ret = push_tab (stack, -1, val);
+    } else {
+        stack = resize_tab (stack, 1);
+        ret = set_tab (stack, 1, val);
+    }
+    return ret;
 }
 
 double put (int n, double val)