File tree Expand file tree Collapse file tree
src/cpp/fastdds/xtypes/serializers/json Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -584,8 +584,16 @@ ReturnCode_t json_serialize_enum_member(
584584
585585 // Get value depending on the enclosing type
586586 assert (enum_type->get_kind () == TK_ENUM );
587- TypeKind enclosing_kind = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index ().at (
588- 0 )->get_descriptor ().type ())->get_kind (); // Unfortunately DynamicDataImpl::get_enclosing_typekind is private
587+ auto enclosing_type_impl = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index ().at (
588+ 0 )->get_descriptor ().type ()); // Unfortunately DynamicDataImpl::get_enclosing_typekind is private
589+ if (nullptr == enclosing_type_impl)
590+ {
591+ EPROSIMA_LOG_ERROR (XTYPES_UTILS ,
592+ " Error encountered while serializing TK_ENUM member to JSON: null enclosing type." );
593+ return RETCODE_BAD_PARAMETER ;
594+ }
595+ TypeKind enclosing_kind = enclosing_type_impl->get_kind ();
596+
589597 nlohmann::json j_value;
590598 if (TK_INT8 == enclosing_kind)
591599 {
Original file line number Diff line number Diff line change @@ -679,8 +679,15 @@ ReturnCode_t json_deserialize_enum_member(
679679
680680 // Get enclosing type kind to parse the value accordingly, and later user the appropriate setter
681681 assert (enum_type->get_kind () == TK_ENUM );
682- TypeKind enclosing_kind = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index ().at (
683- 0 )->get_descriptor ().type ())->get_kind (); // Unfortunately DynamicDataImpl::get_enclosing_typekind is private
682+ auto enclosing_type_impl = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index ().at (
683+ 0 )->get_descriptor ().type ()); // Unfortunately DynamicDataImpl::get_enclosing_typekind is private
684+ if (nullptr == enclosing_type_impl)
685+ {
686+ EPROSIMA_LOG_ERROR (XTYPES_UTILS ,
687+ " Error encountered while deserializing TK_ENUM member from JSON: null enclosing type." );
688+ return RETCODE_BAD_PARAMETER ;
689+ }
690+ TypeKind enclosing_kind = enclosing_type_impl->get_kind ();
684691
685692 if (DynamicDataJsonFormat::OMG == format)
686693 {
@@ -776,9 +783,7 @@ ReturnCode_t json_deserialize_enum_member(
776783 // Find value corresponding to name
777784
778785 DynamicTypeMembersByName all_members;
779- if (RETCODE_OK !=
780- (ret =
781- traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type)->get_all_members_by_name (all_members)))
786+ if (RETCODE_OK != (ret = enum_type->get_all_members_by_name (all_members)))
782787 {
783788 EPROSIMA_LOG_ERROR (XTYPES_UTILS ,
784789 " Error encountered while deserializing TK_ENUM member from JSON: get_all_members_by_name failed." );
You can’t perform that action at this time.
0 commit comments