More ticket #1037:
- bug in aligning pointer if sizeof(long) is less than sizeof(void*). Thanks John Ridges for pointing this out
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3082 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/pool.c b/pjlib/src/pj/pool.c
index 22df21c..800b86c 100644
--- a/pjlib/src/pj/pool.c
+++ b/pjlib/src/pj/pool.c
@@ -31,7 +31,8 @@
# include <pj/pool_i.h>
#endif
-#define LOG(expr) PJ_LOG(6,expr)
+#define LOG(expr) PJ_LOG(6,expr)
+#define ALIGN_PTR(PTR,ALIGNMENT) (PTR + (-(long)(PTR) & (ALIGNMENT-1)))
PJ_DEF_DATA(int) PJ_NO_MEMORY_EXCEPTION;
@@ -71,9 +72,7 @@
block->end = ((unsigned char*)block) + size;
/* Set the start pointer, aligning it as needed */
- block->cur = (unsigned char*)
- (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
- ~(PJ_POOL_ALIGNMENT - 1));
+ block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
/* Insert in the front of the list. */
pj_list_insert_after(&pool->block_list, block);
@@ -216,9 +215,7 @@
block->end = buffer + initial_size;
/* Set the start pointer, aligning it as needed */
- block->cur = (unsigned char*)
- (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
- ~(PJ_POOL_ALIGNMENT - 1));
+ block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
pj_list_insert_after(&pool->block_list, block);
@@ -262,9 +259,7 @@
block = pool->block_list.next;
/* Set the start pointer, aligning it as needed */
- block->cur = (unsigned char*)
- (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) &
- ~(PJ_POOL_ALIGNMENT - 1));
+ block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT);
pool->capacity = block->end - (unsigned char*)pool;
}