Skip to content

Commit

Permalink
ports: Remove side effects from CC_ASSERT calls
Browse files Browse the repository at this point in the history
Since p-net may be compiled without asserts
(e.g. release builds for STM32Cube), it could be
the case that expressions with side effects were
not evaluated; this would cause incorrect behaviour.

While the rt-kernel port does not use CC_ASSERT,
it has also been changed in the same manner for
consistency.
  • Loading branch information
Philip Vedin committed Feb 22, 2024
1 parent 6e9ede5 commit 2f0e146
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ports/STM32Cube/pnal.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ pnal_buf_t * pnal_buf_alloc (uint16_t length)

void pnal_buf_free (pnal_buf_t * p)
{
CC_ASSERT (pbuf_free (p) == 1);
uint8_t deallocated = pbuf_free (p);
(void)deallocated;
CC_ASSERT (deallocated == 1);
}

uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment)
Expand Down
4 changes: 3 additions & 1 deletion src/ports/iMX8M/pnal.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ pnal_buf_t * pnal_buf_alloc (uint16_t length)

void pnal_buf_free (pnal_buf_t * p)
{
CC_ASSERT (pbuf_free (p) == 1);
uint8_t deallocated = pbuf_free (p);
(void)deallocated;
CC_ASSERT (deallocated == 1);
}

uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment)
Expand Down
4 changes: 3 additions & 1 deletion src/ports/rt-kernel/pnal.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ pnal_buf_t * pnal_buf_alloc (uint16_t length)

void pnal_buf_free (pnal_buf_t * p)
{
ASSERT (pbuf_free (p) == 1);
uint8_t deallocated = pbuf_free (p);
(void)deallocated;
ASSERT (deallocated == 1);
}

uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment)
Expand Down

0 comments on commit 2f0e146

Please sign in to comment.