Skip to content

Commit 4610027

Browse files
author
tempate
committed
Tests fixes - unbounded sequence & array length
Signed-off-by: tempate <danieldiaz@eprosima.com>
1 parent c71014c commit 4610027

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/cpp/fastdds/xtypes/dyn_type_tree.ipp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ ReturnCode_t dyn_type_to_tree(
6464

6565
for (const auto& member : members_by_name)
6666
{
67-
ret = dyn_type_to_tree(member.second, member.first, node);
67+
utilities::collections::TreeNode<TreeNodeType> child;
68+
ret = dyn_type_to_tree(member.second, member.first, child);
6869

6970
if (ret != RETCODE_OK)
7071
{
7172
return ret;
7273
}
7374

74-
// Add each member with its name as a new node in a branch (recursion)
75-
parent.add_branch(node);
75+
// Add each member with its name as a new child in a branch (recursion)
76+
parent.add_branch(child);
7677
}
7778

7879
node = parent;
@@ -92,7 +93,7 @@ ReturnCode_t dyn_type_to_tree(
9293
}
9394

9495
std::string internal_str;
95-
ret = dyn_type_to_str(internal_type, internal_str);
96+
ret = dyn_type_to_str(type, internal_str);
9697

9798
if (ret != RETCODE_OK)
9899
{
@@ -303,7 +304,7 @@ ReturnCode_t array_kind_to_str(
303304
for (const auto& bound : bounds)
304305
{
305306
array_str += "[";
306-
array_str += bound;
307+
array_str += std::to_string(bound);
307308
array_str += "]";
308309
}
309310

@@ -349,13 +350,11 @@ ReturnCode_t sequence_kind_to_str(
349350

350351
for (const auto& bound : bounds)
351352
{
352-
if (bound == static_cast<std::uint32_t>(LENGTH_UNLIMITED))
353-
{
354-
sequence_str += ", unbounded";
355-
}
356-
else
353+
const auto UNBOUNDED = static_cast<std::uint32_t>(LENGTH_UNLIMITED);
354+
355+
if (bound != UNBOUNDED)
357356
{
358-
sequence_str += ", " + bound;
357+
sequence_str += ", " + std::to_string(bound);
359358
}
360359
}
361360

@@ -527,7 +526,9 @@ ReturnCode_t dyn_type_tree_to_idl(
527526
break;
528527
}
529528
default:
529+
{
530530
continue;
531+
}
531532
}
532533

533534
if (ret != RETCODE_OK)
@@ -722,9 +723,16 @@ ReturnCode_t node_to_str(
722723

723724
if (node.info.dynamic_type->get_kind() == TK_ARRAY)
724725
{
725-
auto dim_pos = node.info.type_kind_name.find("[");
726-
auto kind_name_str = node.info.type_kind_name.substr(0, dim_pos);
727-
auto dim_str = node.info.type_kind_name.substr(dim_pos, std::string::npos);
726+
const auto dim_pos = node.info.type_kind_name.find("[");
727+
728+
if (dim_pos == std::string::npos)
729+
{
730+
EPROSIMA_LOG_ERROR(DYN_TYPES, "Array type name is not well formed.");
731+
return RETCODE_BAD_PARAMETER;
732+
}
733+
734+
const auto kind_name_str = node.info.type_kind_name.substr(0, dim_pos);
735+
const auto dim_str = node.info.type_kind_name.substr(dim_pos, std::string::npos);
728736

729737
node_str += kind_name_str + " " + node.info.member_name + dim_str;
730738
}

0 commit comments

Comments
 (0)