From c73e95e60892f8fa8107b6e86276da24bdae7bff Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Tue, 13 Oct 2020 18:29:01 +0200 Subject: [PATCH] Logs of unsuccessful union matchings are now properly cleaned up (bug 567844) Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> Change-Id: I723f69311554c3010add93c4833e5f6f85cf7747 --- compiler2/union.c | 2 ++ .../templateUnion/TtemplateUnion.ttcn | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/compiler2/union.c b/compiler2/union.c index 66e03ed7d..a578f32e8 100644 --- a/compiler2/union.c +++ b/compiler2/union.c @@ -3216,12 +3216,14 @@ void defUnionTemplate(const struct_def *sdef, output_struct *output) "}\n" "if (template_selection == SPECIFIC_VALUE && " "single_value.union_selection == match_value.get_selection()) {\n" + "size_t previous_size = TTCN_Logger::get_logmatch_buffer_len();\n" "switch (single_value.union_selection) {\n", name, name); for (i = 0; i < sdef->nElements; i++) { src = mputprintf(src, "case %s_%s:\n" "if(TTCN_Logger::VERBOSITY_COMPACT == TTCN_Logger::get_matching_verbosity()){\n" "TTCN_Logger::log_logmatch_info(\".%s\");\n" "single_value.field_%s->log_match(match_value.%s%s(), legacy);\n" + "TTCN_Logger::set_logmatch_buffer_len(previous_size);\n" "} else {\n" "TTCN_Logger::log_event_str(\"{ %s := \");\n" "single_value.field_%s->log_match(match_value.%s%s(), legacy);\n" diff --git a/regression_test/templateUnion/TtemplateUnion.ttcn b/regression_test/templateUnion/TtemplateUnion.ttcn index 5ba09a28b..f71078785 100644 --- a/regression_test/templateUnion/TtemplateUnion.ttcn +++ b/regression_test/templateUnion/TtemplateUnion.ttcn @@ -200,6 +200,27 @@ testcase tc_record_withWildCard3E() runs on templateUnion_mycomp { if(ispresent(vtl_rec2.u.i)){setverdict(fail)}else {setverdict(pass)}; } +testcase tc_logmatch_cleanup() runs on templateUnion_mycomp { + // bug 567844 + // When logging the result of an unsuccessful matching operation with a union template, + // the matching info is not properly cleaned up, and can cause future logged matchings + // of the same type to also display leftover data. + var charstring log2_exp := " matched"; + for (var integer i := 0; i < 5; i := i + 1) { + var templateUnion_myunion x := { f1 := i }; + var charstring log1 := log2str(match(x, templateUnion_myunion: { f1 := 10 })); + var charstring log1_exp := ".f1 := " & int2str(i) & " with 10 unmatched"; + if (log1 != log1_exp) { + setverdict(fail, "log1: ", log1, ", expected: ", log1_exp); + } + var charstring log2 := log2str(match(x, templateUnion_myunion: { f1 := ? })); + if (log2 != log2_exp) { + setverdict(fail, "log2: ", log2, ", expected: ", log2_exp); + } + } + setverdict(pass); +} + control { execute(templateUnionSpec()); execute(templateUnionList()); @@ -209,5 +230,6 @@ control { execute(templateUnionAnyorNone()); // execute(templateUnionIfpresent()); execute(tc_record_withWildCard3E()); + execute(tc_logmatch_cleanup()); } } -- GitLab