Clear padding in outgoing messages
Padding used to not be cleared in this code base, but that has the downside of valgrind reporting nuisance warnings (which could be fixed using valgrind's programmatic interface) but also of potentially leaking information. The cost of clearing the padding appears to be insignificant compared to the cost of doing the real work, and so it is probably best to just clear it. Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
cdfeb0aacc
commit
7bffaedde8
4 changed files with 17 additions and 17 deletions
|
@ -102,17 +102,13 @@ static void *serdata_default_append (struct ddsi_serdata_default **d, size_t n)
|
|||
|
||||
static void *serdata_default_append_aligned (struct ddsi_serdata_default **d, size_t n, size_t a)
|
||||
{
|
||||
#if CLEAR_PADDING
|
||||
size_t pos0 = st->pos;
|
||||
#endif
|
||||
size_t pos0 = (*d)->pos;
|
||||
char *p;
|
||||
assert (ispowerof2_size (a));
|
||||
(*d)->pos = (uint32_t) alignup_size ((*d)->pos, a);
|
||||
p = serdata_default_append (d, n);
|
||||
#if CLEAR_PADDING
|
||||
if (p && (*d)->pos > pos0)
|
||||
memset ((*d)->data + pos0, 0, (*d)->pos - pos0);
|
||||
#endif
|
||||
while (pos0 < (*d)->pos)
|
||||
(*d)->data[pos0++] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -512,6 +508,7 @@ static struct ddsi_serdata *serdata_default_from_sample_rawcdr (const struct dds
|
|||
return NULL;
|
||||
assert (sample->keysize <= 16);
|
||||
serdata_default_append_blob (&d, 1, sample->size, sample->blob);
|
||||
serdata_default_append_aligned (&d, 0, 4);
|
||||
d->keyhash.m_set = 1;
|
||||
d->keyhash.m_iskey = 1;
|
||||
if (sample->keysize == 0)
|
||||
|
|
|
@ -289,6 +289,7 @@ int spdp_write (struct participant *pp)
|
|||
/* Add PrismTech specific version information */
|
||||
{
|
||||
ps.present |= PP_PRISMTECH_PARTICIPANT_VERSION_INFO;
|
||||
memset (&ps.prismtech_participant_version_info, 0, sizeof (ps.prismtech_participant_version_info));
|
||||
ps.prismtech_participant_version_info.version = 0;
|
||||
ps.prismtech_participant_version_info.flags =
|
||||
NN_PRISMTECH_FL_DDSI2_PARTICIPANT_FLAG |
|
||||
|
|
|
@ -158,8 +158,13 @@ static const void *deser_generic_src (const void * __restrict src, size_t *srcof
|
|||
|
||||
static void *ser_generic_align4 (char * __restrict p, size_t * __restrict off)
|
||||
{
|
||||
*off = align4size (*off);
|
||||
return p + *off;
|
||||
const size_t off1 = align4size (*off);
|
||||
size_t pad = off1 - *off;
|
||||
char *dst = p + *off;
|
||||
*off = off1;
|
||||
while (pad--)
|
||||
*dst++ = 0;
|
||||
return dst;
|
||||
}
|
||||
|
||||
static dds_return_t deser_uint32 (uint32_t *dst, const struct dd * __restrict dd, size_t * __restrict off)
|
||||
|
|
|
@ -809,13 +809,10 @@ void *nn_xmsg_addpar (struct nn_xmsg *m, nn_parameterid_t pid, size_t len)
|
|||
phdr->parameterid = pid;
|
||||
phdr->length = (uint16_t) len4;
|
||||
p = (char *) (phdr + 1);
|
||||
if (len4 > len)
|
||||
{
|
||||
/* zero out padding bytes added to satisfy parameter alignment --
|
||||
alternative: zero out, but this way valgrind/purify can tell us
|
||||
where we forgot to initialize something */
|
||||
memset (p + len, 0, len4 - len);
|
||||
}
|
||||
/* zero out padding bytes added to satisfy parameter alignment: this way
|
||||
valgrind can tell us where we forgot to initialize something */
|
||||
while (len < len4)
|
||||
p[len++] = 0;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue