Assertions to help clang static analyzer
Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
b9660e46c9
commit
0b6ea79469
2 changed files with 5 additions and 0 deletions
|
@ -110,6 +110,7 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
|
||||||
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
|
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
|
||||||
/* return resets buf[0] (so that it picks up the loan the next time) and zeros the data */
|
/* return resets buf[0] (so that it picks up the loan the next time) and zeros the data */
|
||||||
CU_ASSERT_FATAL (ptrs[0] == NULL);
|
CU_ASSERT_FATAL (ptrs[0] == NULL);
|
||||||
|
assert (ptr0copy != NULL); /* clang static analyzer */
|
||||||
CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, sizeof (s)) == 0);
|
CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, sizeof (s)) == 0);
|
||||||
|
|
||||||
/* read 3, return: should work fine, causes realloc */
|
/* read 3, return: should work fine, causes realloc */
|
||||||
|
@ -121,6 +122,7 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
|
||||||
result = dds_return_loan (reader, ptrs, n);
|
result = dds_return_loan (reader, ptrs, n);
|
||||||
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
|
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
|
||||||
CU_ASSERT_FATAL (ptrs[0] == NULL);
|
CU_ASSERT_FATAL (ptrs[0] == NULL);
|
||||||
|
assert (ptr0copy != NULL); /* clang static analyzer */
|
||||||
CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, 3 * sizeof (s)) == 0);
|
CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, 3 * sizeof (s)) == 0);
|
||||||
|
|
||||||
/* read 1 using loan, expecting to get the same address (no realloc needed), defer return.
|
/* read 1 using loan, expecting to get the same address (no realloc needed), defer return.
|
||||||
|
@ -145,6 +147,7 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
|
||||||
{
|
{
|
||||||
const struct RoundTripModule_DataType *a = ptrs[0];
|
const struct RoundTripModule_DataType *a = ptrs[0];
|
||||||
const struct RoundTripModule_DataType *b = ptrs2[0];
|
const struct RoundTripModule_DataType *b = ptrs2[0];
|
||||||
|
assert (a != NULL && b != NULL); /* clang static analyzer */
|
||||||
CU_ASSERT_FATAL (a->payload._length == b->payload._length);
|
CU_ASSERT_FATAL (a->payload._length == b->payload._length);
|
||||||
CU_ASSERT_FATAL (a->payload._buffer != b->payload._buffer);
|
CU_ASSERT_FATAL (a->payload._buffer != b->payload._buffer);
|
||||||
CU_ASSERT_FATAL (a->payload._buffer[0] == b->payload._buffer[0]);
|
CU_ASSERT_FATAL (a->payload._buffer[0] == b->payload._buffer[0]);
|
||||||
|
@ -164,6 +167,7 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
|
||||||
|
|
||||||
//This should be a use-after-free
|
//This should be a use-after-free
|
||||||
//CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, sizeof (s)) == 0);
|
//CU_ASSERT_FATAL (memcmp (ptr0copy, zeros, sizeof (s)) == 0);
|
||||||
|
(void) ptr0copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
CU_Test (ddsc_loan, take_cleanup, .init = create_entities, .fini = delete_entities)
|
CU_Test (ddsc_loan, take_cleanup, .init = create_entities, .fini = delete_entities)
|
||||||
|
|
|
@ -213,6 +213,7 @@ static struct ddsi_serdata *serdata_pserop_from_sample (const struct ddsi_sertop
|
||||||
const size_t size4 = (size + 3) & ~(size_t)3;
|
const size_t size4 = (size + 3) & ~(size_t)3;
|
||||||
struct ddsi_serdata_pserop *d = serdata_pserop_new (tp, kind, size4, &header);
|
struct ddsi_serdata_pserop *d = serdata_pserop_new (tp, kind, size4, &header);
|
||||||
assert (tp->ops_key == NULL || (size >= 16 && tp->memsize >= 16));
|
assert (tp->ops_key == NULL || (size >= 16 && tp->memsize >= 16));
|
||||||
|
assert (d->data != NULL); // clang static analyzer
|
||||||
memcpy (d->data, data, size);
|
memcpy (d->data, data, size);
|
||||||
memset (d->data + size, 0, size4 - size);
|
memset (d->data + size, 0, size4 - size);
|
||||||
d->pos = (uint32_t) size;
|
d->pos = (uint32_t) size;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue