From 6537a59c98bccda8899a2fff8431071827188264 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 23 Sep 2018 11:42:56 +0200 Subject: [PATCH] tests: fix a memory leak This has been bugging me for while. I was hard to reproduce: it worked only on GNU/Linux, probably because libc++ implements the small string optimization, while libstdc++ did not and actually allocated on the heap for this small string. See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00110.html. * tests/types.at (api.value.type): Do not provide a semantic value to EOF. --- tests/types.at | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/types.at b/tests/types.at index c17e852f..c95d93e4 100644 --- a/tests/types.at +++ b/tests/types.at @@ -132,7 +132,8 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], [], ['1' '2' { printf ("%2.1f\n", $1 + $2); }], ["12"], - [AT_VAL = (res - '0') / 10.0], + [if (res) + AT_VAL = (res - '0') / 10.0], [0.3]) # A typedef which looks like a Bison keyword, but it's using braces. @@ -141,7 +142,8 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], [%code requires { typedef double variant; }], ['1' '2' { printf ("%2.1f\n", $1 + $2); }], ["12"], - [AT_VAL = (res - '0') / 10.0], + [if (res) + AT_VAL = (res - '0') / 10.0], [0.3]) # A user defined struct. @@ -151,8 +153,11 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], ['1' '2' { printf ("%d %2.1f\n", $1.ival + $2.ival, $1.fval + $2.fval); }], ["12"], - [AT_VAL.ival = (res - '0') * 10; - AT_VAL.fval = (res - '0') / 10.f], + [if (res) + { + AT_VAL.ival = (res - '0') * 10; + AT_VAL.fval = (res - '0') / 10.f; + }], [30 0.3]) # A user defined struct that uses pointers. @@ -197,7 +202,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], ["12"], [if (res == '1') AT_VAL.ival = 10; - else + else if (res == '2') AT_VAL.fval = .2f], [10 0.2]) @@ -215,7 +220,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], ["12"], [if (res == '1') AT_VAL.ival = 10; - else + else if (res == '2') AT_VAL.fval = 0.2f], [10 0.2])]) @@ -251,7 +256,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]], ["12"], [if (res == '1') AT_VAL.build(10); - else + else if (res == '2') AT_VAL.build("two");], [10, two])]) ])