fix alignment issues in alloc_pool.c
This closes
@@ -348,7 +348,8 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool)
DEQ_INSERT_TAIL(qtype->allocated, item);
sys_mutex_unlock(desc->lock);
item->header = PATTERN_FRONT;
- *((uint32_t*) ((char*) &item[1] + desc->total_size))= PATTERN_BACK;
+ const uint32_t pb = PATTERN_BACK;
+ memcpy((char*) &item[1] + desc->total_size, &pb, sizeof(pb));
QD_MEMORY_FILL(&item[1], QD_MEMORY_INIT, desc->total_size);
#endif
return &item[1];
@@ -414,7 +415,8 @@ void *qd_alloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool)
DEQ_INSERT_TAIL(qtype->allocated, item);
sys_mutex_unlock(desc->lock);
item->header = PATTERN_FRONT;
- *((uint32_t*) ((char*) &item[1] + desc->total_size))= PATTERN_BACK;
+ const uint32_t pb = PATTERN_BACK;
+ memcpy((char*) &item[1] + desc->total_size, &pb, sizeof(pb));
QD_MEMORY_FILL(&item[1], QD_MEMORY_INIT, desc->total_size);
#endif
return &item[1];
@@ -434,7 +436,9 @@ void qd_dealloc(qd_alloc_type_desc_t *desc, qd_alloc_pool_t **tpool, char *p)
assert (desc->header == PATTERN_FRONT);
assert (desc->trailer == PATTERN_BACK);
assert (item->header == PATTERN_FRONT);
- assert (*((uint32_t*) (p + desc->total_size)) == PATTERN_BACK);
+ const uint32_t pb = PATTERN_BACK;
+ (void)pb; // prevent unused warning
+ assert (memcmp(p + desc->total_size, &pb, sizeof(pb)) == 0);
assert (item->desc == desc); // Check for double-free
qd_alloc_type_t *qtype = (qd_alloc_type_t*) desc->debug;
sys_mutex_lock(desc->lock);
