Commit 073a2453 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

JSON dec: fixed union field recognition fault (bug 522660)



Change-Id: I7dbc389c8be16fe49bded538b4aacd8a23aa9193
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 657c5be3
......@@ -2326,7 +2326,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
, unbound_value);
for (i = 0; i < sdef->nElements; ++i) {
src = mputprintf(src,
"if (0 == strncmp(fld_name, \"%s\", name_len)) {\n"
"if (%d == name_len && 0 == strncmp(fld_name, \"%s\", name_len)) {\n"
" int ret_val = %s%s().JSON_decode(%s_descr_, p_tok, p_silent);\n"
" if (0 > ret_val) {\n"
" if (JSON_ERROR_INVALID_TOKEN) {\n"
......@@ -2337,6 +2337,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
" dec_len += (size_t)ret_val;\n"
" }\n"
" } else "
, (int)strlen(sdef->elements[i].jsonAlias ? sdef->elements[i].jsonAlias : sdef->elements[i].dispname)
, sdef->elements[i].jsonAlias ? sdef->elements[i].jsonAlias : sdef->elements[i].dispname
, at_field, sdef->elements[i].name, sdef->elements[i].typedescrname
, (unsigned long) strlen(sdef->elements[i].dispname), sdef->elements[i].dispname);
......
......@@ -824,6 +824,23 @@ testcase tc_multi_level_recordof() runs on MTC {
f_bool2verdict(match(f_dec_multi_list(os), x));
}
testcase tc_bug_522660() runs on MTC {
var universal charstring enc1 := "{\"f12\":10}";
var universal charstring enc2 := "{\"f1\":10}";
var Uni522660 x1, x2;
var integer res1 := decvalue_unichar(enc1, x1);
var integer res2 := decvalue_unichar(enc2, x2);
if (res1 != 0 or x1 != { f12 := 10 }) {
setverdict(fail, "Test #1 failed. Result: ", res1, ". Decoded value: ", x1);
}
else if (res2 != 0 or x2 != { f1 := 10 }) {
setverdict(fail, "Test #2 failed. Result: ", res2, ". Decoded value: ", x2);
}
else {
setverdict(pass);
}
}
//=========================================================================
// Control
//=========================================================================
......@@ -913,6 +930,8 @@ control {
execute(tc_embedded_anytype());
execute(tc_multi_level_record());
execute(tc_multi_level_recordof());
execute(tc_bug_522660());
}
......
......@@ -300,6 +300,11 @@ with {
variant (days[-]) "JSON: as number";
}
type union Uni522660 {
integer f12,
integer f1
}
} with {
encode "JSON";
extension "anytype integer, charstring, R, RoI, Thing";
......
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