From 0a8a1de32bdcdad2e60958af32ccf324fa81e144 Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Tue, 31 Jan 2023 23:44:39 +0100 Subject: [PATCH] correct a double freeze --- calc.c | 4 ++-- parser.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/calc.c b/calc.c index d5b0246..b0356c8 100644 --- 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' diff --git a/parser.c b/parser.c index 3d8681c..714ea87 100644 --- 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; } } } -- 2.30.2