Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -1342,10 +1342,14 @@ void defUnionClass(struct_def const *sdef, output_struct *output) ...@@ -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 */ /* An untagged union can start with the start tag of any alternative */
for (i = 0; i < sdef->nElements; i++) { for (i = 0; i < sdef->nElements; i++) {
src=mputprintf(src, // An untagged union cannot start with itself. It would create an infinite
" if (%s::can_start(name, uri, %s_xer_, flavor, flavor2)) return TRUE;\n" // recursion.
, sdef->elements[i].type, sdef->elements[i].typegen 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"); 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 ...@@ -1461,6 +1461,56 @@ Dynamic test case error: Performing a valueof or send operation on a non-specifi
:exmp. :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 :h1.REFERENCES
.*---------------------------------------------------------------------* .*---------------------------------------------------------------------*
......
...@@ -786,6 +786,36 @@ testcase decode_ut_union2() runs on UTA ...@@ -786,6 +786,36 @@ testcase decode_ut_union2() runs on UTA
CHECK_DECODE(exer_dec_untunion2, s_untunion2, UntaggedUnion2, c_untunion2); 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! * * * * * * * * * * */ /* * * * * * * * * * * Run it! * * * * * * * * * * */
control { control {
...@@ -831,6 +861,9 @@ control { ...@@ -831,6 +861,9 @@ control {
execute(encode_ut_union2()); execute(encode_ut_union2());
execute(decode_ut_union2()); execute(decode_ut_union2());
execute(encode_ut_union3());
execute(decode_ut_union3());
execute(encode_ut_union_recof()); execute(encode_ut_union_recof());
execute(decode_ut_union_recof()); execute(decode_ut_union_recof());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment