From b6fe21d5206e0d5195abfb2340e853fa1ae86ddb Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Thu, 24 Aug 2023 09:13:34 +0200 Subject: [PATCH] dynsub: fix bounded strings Signed-off-by: Erik Boasson --- examples/dynsub/print_sample.c | 7 +++++-- examples/dynsub/type_cache.c | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/dynsub/print_sample.c b/examples/dynsub/print_sample.c index 64b007c380..2507f756d8 100644 --- a/examples/dynsub/print_sample.c +++ b/examples/dynsub/print_sample.c @@ -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; } diff --git a/examples/dynsub/type_cache.c b/examples/dynsub/type_cache.c index 76246b074a..da845709d0 100644 --- a/examples/dynsub/type_cache.c +++ b/examples/dynsub/type_cache.c @@ -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: