Skip to content

Commit 54c41d7

Browse files
committed
[#24584] Fix TypeObjectRegistry null pass to a callee + regression tests
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent c2cc2c6 commit 54c41d7

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,7 @@ ReturnCode_t TypeObjectRegistry::set_annotation_parameter_value(
26172617
TypeValueConverter::sto(value) : 0));
26182618
break;
26192619
case TK_CHAR8:
2620-
param_value = TypeObjectUtils::build_annotation_parameter_value(!value.empty() ? value : 0);
2620+
param_value = TypeObjectUtils::build_annotation_parameter_value(!value.empty() ? value[0] : '\0');
26212621
break;
26222622
case TK_ENUM:
26232623
{

test/unittest/dds/xtypes/type_representation/TypeObjectRegistryTests.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,25 @@
2121

2222
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
2323
#include <fastdds/dds/xtypes/common.hpp>
24+
#include <fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
2425
#include <fastdds/dds/xtypes/type_representation/TypeObject.hpp>
2526
#include <fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
2627

28+
#include <fastdds/xtypes/type_representation/TypeObjectRegistry.hpp>
29+
2730
namespace eprosima {
2831
namespace fastdds {
2932
namespace dds {
3033
namespace xtypes {
3134

35+
class TestTypeObjectRegistry : public TypeObjectRegistry
36+
{
37+
38+
public:
39+
40+
using TypeObjectRegistry::set_annotation_parameter_value;
41+
};
42+
3243
// Test TypeObjectRegistry::register_type_object
3344
TEST(TypeObjectRegistryTests, register_type_object)
3445
{
@@ -330,6 +341,42 @@ TEST(TypeObjectRegistryTests, get_type_information)
330341
EXPECT_EQ(RETCODE_OK, registry.get_type_information(type_ids, type_info, false));
331342
}
332343

344+
// (MacOS) Regression test for clang/libc++ builds: empty char8 annotation
345+
// parameters must not route through the string overload
346+
// and must produce a null character default value instead
347+
TEST(TypeObjectRegistryTests, set_annotation_parameter_value_empty_char8)
348+
{
349+
TestTypeObjectRegistry registry;
350+
AnnotationParameterValue param_value;
351+
// Build the primitive char8 type explicitly so the conversion logic is exercised on the
352+
// single-character annotation path instead of the string one
353+
auto char8_type = DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8);
354+
355+
ASSERT_NE(nullptr, char8_type);
356+
// An empty value for a char8 annotation must still succeed and yield the default
357+
// null character rather than being treated as a string payload
358+
EXPECT_EQ(RETCODE_OK, registry.set_annotation_parameter_value(char8_type, "", param_value));
359+
EXPECT_EQ(TK_CHAR8, param_value._d());
360+
EXPECT_EQ('\0', param_value.char_value());
361+
}
362+
363+
// (MacOS) Regression test for clang/libc++ builds: non empty char8 annotation
364+
TEST(TypeObjectRegistryTests, set_annotation_parameter_value_non_empty_char8_uses_first_character)
365+
{
366+
TestTypeObjectRegistry registry;
367+
AnnotationParameterValue param_value;
368+
// Use the same primitive char8 path to verify how
369+
// text input is narrowed into a single annotation character
370+
auto char8_type = DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8);
371+
372+
ASSERT_NE(nullptr, char8_type);
373+
// For char8 annotations only the first character is significant,
374+
// even if the provided text contains more bytes
375+
EXPECT_EQ(RETCODE_OK, registry.set_annotation_parameter_value(char8_type, "FastDDS", param_value));
376+
EXPECT_EQ(TK_CHAR8, param_value._d());
377+
EXPECT_EQ('F', param_value.char_value());
378+
}
379+
333380
} // xtypes
334381
} // dds
335382
} // fastdds
@@ -342,3 +389,4 @@ int main(
342389
testing::InitGoogleTest(&argc, argv);
343390
return RUN_ALL_TESTS();
344391
}
392+

0 commit comments

Comments
 (0)