diff --git a/compiler2/union.c b/compiler2/union.c index 66e03ed7df9aaae84ed93f76a20879483d4acd90..a578f32e8486ce3ea86f8da9c309e2fc27ada8e6 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 5ba09a28b5f5313c828dfcb60c208a308f3dcaa4..f71078785a7101c6af9ecc6d8b90f7dd501f21c6 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()); } }