Skip to content

Commit

Permalink
dynsub: fix bounded strings
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <eb@ilities.com>
  • Loading branch information
eboasson committed Aug 28, 2023
1 parent 72d6d6d commit b6fe21d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions examples/dynsub/print_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ static void print_sample1_ti (const unsigned char *sample, const DDS_XTypes_Type
{
case DDS_XTypes_TI_STRING8_SMALL:
case DDS_XTypes_TI_STRING8_LARGE: {
const char **p = (const char **) align (sample, c, _Alignof (char *), sizeof (char *));
const char *p = align (sample, c, _Alignof (char *), sizeof (char *));
if (c->key || c->valid_data)
{
printf ("%s", sep);
if (label) printf ("\"%s\":", label);
printf ("\"%s\"", *p);
if ((typeid->_d == DDS_XTypes_TI_PLAIN_SEQUENCE_SMALL) ? typeid->_u.string_sdefn.bound : typeid->_u.string_ldefn.bound)
printf ("\"%s\"", p);
else
printf ("\"%s\"", *((const char **) p));
}
break;
}
Expand Down
15 changes: 13 additions & 2 deletions examples/dynsub/type_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,19 @@ static void build_typecache_ti (const DDS_XTypes_TypeIdentifier *typeid, size_t
{
case DDS_XTypes_TI_STRING8_SMALL:
case DDS_XTypes_TI_STRING8_LARGE: {
*align = _Alignof (unsigned char *);
*size = sizeof (unsigned char *);
uint32_t bound;
if (typeid->_d == DDS_XTypes_TI_PLAIN_SEQUENCE_SMALL) {
bound = typeid->_u.string_sdefn.bound;
} else {
bound = typeid->_u.string_ldefn.bound;
}
if (bound == 0) {
*align = _Alignof (unsigned char *);
*size = sizeof (unsigned char *);
} else {
*align = 1;
*size = bound;
}
break;
}
case DDS_XTypes_TI_PLAIN_SEQUENCE_SMALL:
Expand Down

0 comments on commit b6fe21d

Please sign in to comment.