Commit 5ae2adab authored by Kai Vogelgesang's avatar Kai Vogelgesang Committed by rna

Fix some issues that fsanitize=undefined found

parent 67ac7e7d
Pipeline #2992 passed with stages
in 1 minute and 24 seconds
...@@ -160,8 +160,10 @@ bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) ...@@ -160,8 +160,10 @@ bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr)
#define PrrtPacketField_encode(payload, buf_ptr, field_t, field, conversion) \ #define PrrtPacketField_encode(payload, buf_ptr, field_t, field, conversion) \
do { \ do { \
field_t *ptr = (field_t *) (buf_ptr); \ field_t PrrtPacketField_encode_value = conversion((payload)->field); \
*ptr = conversion((payload)->field); \ /* memcpy to avoid misaligned access.
* The compiler will optimize this into appropriate mov instructions */ \
memcpy(buf_ptr, &PrrtPacketField_encode_value, sizeof(field_t)); \
(buf_ptr) += sizeof(field_t); \ (buf_ptr) += sizeof(field_t); \
} while (false) } while (false)
...@@ -254,8 +256,11 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ ...@@ -254,8 +256,11 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ
#define PrrtPacketField_decode(payload, buf_ptr, field_t, field, conversion) \ #define PrrtPacketField_decode(payload, buf_ptr, field_t, field, conversion) \
do { \ do { \
field_t *PrrtPacketField_decode_ptr = (field_t *) (buf_ptr); \ field_t PrrtPacketField_decode_value; \
(payload)->field = conversion(*PrrtPacketField_decode_ptr); \ /* memcpy to avoid misaligned access.
* The compiler will optimize this into appropriate mov instructions */ \
memcpy(&PrrtPacketField_decode_value, buf_ptr, sizeof(field_t)); \
(payload)->field = conversion(PrrtPacketField_decode_value); \
(buf_ptr) += sizeof(field_t); \ (buf_ptr) += sizeof(field_t); \
} while (false) } while (false)
......
...@@ -26,14 +26,14 @@ BITMAP_EXPOSED_FUNCTION bool Bitmap_get(Bitmap *bitmap, uint32_t position) ...@@ -26,14 +26,14 @@ BITMAP_EXPOSED_FUNCTION bool Bitmap_get(Bitmap *bitmap, uint32_t position)
{ {
uint32_t byte_offset = position / 32; uint32_t byte_offset = position / 32;
uint32_t bit_offset = position % 32; uint32_t bit_offset = position % 32;
return (bool) ((bitmap->data[byte_offset] & (1 << bit_offset)) != 0); return (bool) ((bitmap->data[byte_offset] & (1u << bit_offset)) != 0);
} }
BITMAP_EXPOSED_FUNCTION bool Bitmap_set_0(Bitmap *bitmap, uint32_t position) BITMAP_EXPOSED_FUNCTION bool Bitmap_set_0(Bitmap *bitmap, uint32_t position)
{ {
uint32_t byte_offset = position / 32; uint32_t byte_offset = position / 32;
uint32_t bit_offset = position % 32; uint32_t bit_offset = position % 32;
bitmap->data[byte_offset] &= ~(1 << bit_offset); bitmap->data[byte_offset] &= ~(1u << bit_offset);
return true; return true;
} }
...@@ -41,7 +41,7 @@ BITMAP_EXPOSED_FUNCTION bool Bitmap_set_1(Bitmap *bitmap, uint32_t position) ...@@ -41,7 +41,7 @@ BITMAP_EXPOSED_FUNCTION bool Bitmap_set_1(Bitmap *bitmap, uint32_t position)
{ {
uint32_t byte_offset = position / 32; uint32_t byte_offset = position / 32;
uint32_t bit_offset = position % 32; uint32_t bit_offset = position % 32;
bitmap->data[byte_offset] |= (1 << bit_offset); bitmap->data[byte_offset] |= (1u << bit_offset);
return true; return true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment