Commit be63ee81 authored by BenceJanosSzabo's avatar BenceJanosSzabo
Browse files

XER: fixed nfinite recursion in generated code (Bug 521803)



Change-Id: Ic7440e44ba1f20d0995eb4d13256d81ab06c5245
Signed-off-by: default avatarBenceJanosSzabo <bence.janos.szabo@ericsson.com>
parent f69687a5
......@@ -1342,10 +1342,14 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
/* An untagged union can start with the start tag of any alternative */
for (i = 0; i < sdef->nElements; i++) {
src=mputprintf(src,
" if (%s::can_start(name, uri, %s_xer_, flavor, flavor2)) return TRUE;\n"
, sdef->elements[i].type, sdef->elements[i].typegen
);
// An untagged union cannot start with itself. It would create an infinite
// recursion.
if (strcmp(sdef->elements[i].type, sdef->name) != 0) {
src=mputprintf(src,
" if (%s::can_start(name, uri, %s_xer_, flavor, flavor2)) return TRUE;\n"
, sdef->elements[i].type, sdef->elements[i].typegen
);
}
}
src = mputstr(src, " return FALSE;\n}\n\n");
......
......@@ -1461,6 +1461,56 @@ Dynamic test case error: Performing a valueof or send operation on a non-specifi
:exmp.
.*---------------------------------------------------------------------*
:h4. Decoding record with untagged self recursive union field from incorrect XML
.*---------------------------------------------------------------------*
:xmp tab=0.
<TC - Decoding record with untagged self recursive union field from incorrect XML>
<STATIC>
type component Test_CT{};
<TTCN_TC:PURE_EXEC>
type record MyRecord {
UntaggedUnion u
} with {
encode "XML";
}
type union UntaggedUnion {
integer i,
UntaggedUnion u
} with {
encode "XML";
variant "untagged";
}
external function ef_xer_dec(in octetstring par) return MyRecord
with { extension "prototype(convert) decode (XER:XER_EXTENDED) errorbehavior(ALL:ERROR)" }
testcase tc_dec_self_recursive_untagged_field() runs on Test_CT {
var universal charstring bad_xml := "<MyRecord>\n\t<bad>44</bad>\n</MyRecord>\n\n";
var MyRecord v_res := ef_xer_dec(unichar2oct(bad_xml));
setverdict(pass);
}
control {
execute(tc_dec_self_recursive_untagged_field());
}
<RESULT>
While XER-decoding type '@Temp.MyRecord': Component 'u': 'bad' does not match any alternative
<END_TC>
:exmp.
.*---------------------------------------------------------------------*
:h1.REFERENCES
.*---------------------------------------------------------------------*
......
......@@ -786,6 +786,36 @@ testcase decode_ut_union2() runs on UTA
CHECK_DECODE(exer_dec_untunion2, s_untunion2, UntaggedUnion2, c_untunion2);
}
// ------- untagged union with a recursive field
type record MyRecord {
UntaggedUnion3 u
}
type union UntaggedUnion3 {
integer i,
UntaggedUnion3 u
} with {
variant "untagged";
}
DECLARE_EXER_ENCODERS(MyRecord, untunion3);
const MyRecord c_untunion3 := { u := { i := 44 } };
const universal charstring s_untunion3 := "<MyRecord>\n\t<i>44</i>\n</MyRecord>\n\n";
testcase encode_ut_union3() runs on UTA
{
CHECK_METHOD(exer_enc_untunion3, c_untunion3, s_untunion3);
}
testcase decode_ut_union3() runs on UTA
{
CHECK_DECODE(exer_dec_untunion3, s_untunion3, MyRecord, c_untunion3);
}
/* * * * * * * * * * * Run it! * * * * * * * * * * */
control {
......@@ -831,6 +861,9 @@ control {
execute(encode_ut_union2());
execute(decode_ut_union2());
execute(encode_ut_union3());
execute(decode_ut_union3());
execute(encode_ut_union_recof());
execute(decode_ut_union_recof());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment