You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2021/02/12 21:23:10 UTC
[qpid-dispatch] branch master updated: DISPATCH-1948: fix alignment
issues in alloc_pool.c
This is an automated email from the ASF dual-hosted git repository.
kgiusti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
The following commit(s) were added to refs/heads/master by this push:
new 63f1b21 DISPATCH-1948: fix alignment issues in alloc_pool.c
63f1b21 is described below
commit 63f1b21d10d93b34be787aa2c1accd4d2aaa3a5a
Author: Kenneth Giusti <kg...@apache.org>
AuthorDate: Tue Feb 2 16:52:51 2021 -0500
DISPATCH-1948: fix alignment issues in alloc_pool.c
This closes #1015
---
src/alloc_pool.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/alloc_pool.c b/src/alloc_pool.c
index 0feb20e..284630e 100644
--- a/src/alloc_pool.c
+++ b/src/alloc_pool.c
@@ -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);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org