correct a double freeze
authorMazet Laurent <mazet@softndesign.org>
Tue, 31 Jan 2023 22:44:39 +0000 (23:44 +0100)
committerMazet Laurent <mazet@softndesign.org>
Tue, 31 Jan 2023 22:44:39 +0000 (23:44 +0100)
calc.c
parser.c

diff --git a/calc.c b/calc.c
index d5b02468f9dd2b66bc6f9ca906094d22e0d5841d..b0356c8129f84e650477b1e8202ee965f7d46102 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -377,8 +377,8 @@ int main (int argc, char *argv[])
 // test: echo -e 'sto (3, pi)\nclr\ndisp' | calc.exe | grep -q "storage: 0 0 0 0 0 0 0 0 0 0"
 // test: echo -e 'mem (3)\nclr' | calc.exe -v 3 | grep -q Clear
 // test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\nprog (1, 1, {cos (rcl (1)^2)})\ncall (1, pi/6)\nprog (2, 1, {rcl (1) * 3})\ncall (2, 1, 2)\nls' | calc.exe
-// test: echo -e 'prog (1, 2, {rcl (2) - rcl (1)})\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\nls' | calc.exe -v 3 |grep -q Program
-// test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\nprog (3, 1, cos(rcl (1) * pi / 3))\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\n\ndel (2)\ncall (2, 1, 4)' | calc.exe | grep -c error | xargs test 3 =
+// test: echo -e 'prog (1, 2, {rcl (2) - rcl (1)})\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)' | calc.exe -v 3 |grep -q Program
+// test: echo -e 'prog (2, 2, {rcl (2) - rcl (1)})\nprog (3, 1, cos(rcl (1) * pi / 3))\ncall (1, 2, 3)\nls\nedit (1)\ndel (1)\n\ndel (2)\ncall (2, 1, 4)' | calc.exe | grep -c error | xargs test 4 =
 
 // Gauss sequence
 // test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})};' | calc.exe | grep -q '=> 5050'
index 3d8681cdf3bb7f6d8972459744b15f2b64486928..714ea87168fb069db17fb72c0393bbee9666a304 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -480,7 +480,9 @@ element_t *parser (char *str, char **next, int prio)
     }
 
     /* save string */
-    root->string = string;
+    if (root != NULL) {
+        root->string = string;
+    }
 
     return root;
 }
@@ -780,6 +782,7 @@ void prog (int id, int nbmems, element_t *root)
             }
             if ((programs + n)->string) {
                 free ((programs + n)->string);
+                (programs + n)->string = NULL;
             }
         }
     }