Skip to content

Default string containing unicode characters are not handled properly #855

@TonyWelte

Description

@TonyWelte

For the WString something is wrong in the generated __description.c file. Relevant part:

// Define type names, field names, and default values
static char test_msgs__msg__WStrings__FIELD_NAME__wstring_value[] = "wstring_value";
static char test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default1[] = "wstring_value_default1";
static char test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default1[] = "Hello world!";
static char test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default2[] = "wstring_value_default2";
static char test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default2[] = "Hell\\xc3\\xb6 w\\xc3\\xb6rld!";
static char test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default3[] = "wstring_value_default3";
static char test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default3[] = "\\xe3\\x83\\x8f\\xe3\\x83\\xad\\xe3\\x83\\xbc\\xe3\\x83\\xaf\\xe3\\x83\\xbc\\xe3\\x83\\xab\\xe3\\x83\\x89";
static char test_msgs__msg__WStrings__FIELD_NAME__array_of_wstrings[] = "array_of_wstrings";
static char test_msgs__msg__WStrings__FIELD_NAME__bounded_sequence_of_wstrings[] = "bounded_sequence_of_wstrings";
static char test_msgs__msg__WStrings__FIELD_NAME__unbounded_sequence_of_wstrings[] = "unbounded_sequence_of_wstrings";

static rosidl_runtime_c__type_description__Field test_msgs__msg__WStrings__FIELDS[] = {
  {
    {test_msgs__msg__WStrings__FIELD_NAME__wstring_value, 13, 13},
    {
      rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_WSTRING,
      0,
      0,
      {NULL, 0, 0},
    },
    {NULL, 0, 0},
  },
  {
    {test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default1, 22, 22},
    {
      rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_WSTRING,
      0,
      0,
      {NULL, 0, 0},
    },
    {test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default1, 12, 12},
  },
  {
    {test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default2, 22, 22},
    {
      rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_WSTRING,
      0,
      0,
      {NULL, 0, 0},
    },
    {test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default2, 12, 12},
  },
  {
    {test_msgs__msg__WStrings__FIELD_NAME__wstring_value_default3, 22, 22},
    {
      rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_WSTRING,
      0,
      0,
      {NULL, 0, 0},
    },
    {test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default3, 7, 7},
  },

both test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default2 and test_msgs__msg__WStrings__DEFAULT_VALUE__wstring_value_default3 are registered in the FIELDS with a size and capacity much smaller that the actual size of their array. This is due to len() not returning the number of bytes but the number of codepoints.

Also should the \ in \x really be escaped in the constant definition ? If it's escaped \\xc3\\xb6 is just the string "\xc3\xb6" and not "ö".

I can create a PR with a fix but I'd like to confirm my suspicions

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions