summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-05-28 11:49:46 +0000
committerBenny Prijono <bennylp@teluu.com>2007-05-28 11:49:46 +0000
commit7c28b42ad3fd73d9d7f07b0ebfd3b7f501d71a9f (patch)
tree7a03c60792cca873cba6f1b5255e932fec4bc861 /pjlib
parent26be3e55bedc2f31559151d2608aa338badfbbed (diff)
Fixed ticket #304: Memory alignment error for hash entry buffer causing crash on ARM (thanks ChenHuan)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1307 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/hash.h18
-rw-r--r--pjlib/src/pj/hash.c10
2 files changed, 16 insertions, 12 deletions
diff --git a/pjlib/include/pj/hash.h b/pjlib/include/pj/hash.h
index ed1805d7..f033ab75 100644
--- a/pjlib/include/pj/hash.h
+++ b/pjlib/include/pj/hash.h
@@ -47,7 +47,12 @@ PJ_BEGIN_DECL
/**
* This indicates the size of of each hash entry.
*/
-#define PJ_HASH_ENTRY_SIZE (3*sizeof(void*) + 2*sizeof(pj_uint32_t))
+#define PJ_HASH_ENTRY_BUF_SIZE (3*sizeof(void*) + 2*sizeof(pj_uint32_t))
+
+/**
+ * Type declaration for entry buffer, used by #pj_hash_set_np()
+ */
+typedef void *pj_hash_entry_buf[(PJ_HASH_ENTRY_BUF_SIZE+sizeof(void*)-1)/(sizeof(void*))];
/**
* This is the function that is used by the hash table to calculate hash value
@@ -148,18 +153,15 @@ PJ_DECL(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
* this value to search the entry's index, otherwise it will
* compute the key. This value can be obtained when calling
* #pj_hash_get().
- * @param entry_buf Pointer to buffer which will be used for the new entry,
- * when one needs to be created. The buffer must be at least
- * PJ_HASH_ENTRY_SIZE long, and the first PJ_HASH_ENTRY_SIZE
- * bytes of the buffer will be used by the hash table.
- * Application may use the remaining portion of the buffer
- * for its own purpose.
+ * @param entry_buf Buffer which will be used for the new entry, when one needs
+ * to be created.
* @param value value to be associated, or NULL to delete the entry with
* the specified key.
*/
PJ_DECL(void) pj_hash_set_np(pj_hash_table_t *ht,
const void *key, unsigned keylen,
- pj_uint32_t hval, void *entry_buf, void *value);
+ pj_uint32_t hval, pj_hash_entry_buf entry_buf,
+ void *value);
/**
* Get the total number of entries in the hash table.
diff --git a/pjlib/src/pj/hash.c b/pjlib/src/pj/hash.c
index 5b3454d9..2e13f450 100644
--- a/pjlib/src/pj/hash.c
+++ b/pjlib/src/pj/hash.c
@@ -100,8 +100,8 @@ PJ_DEF(pj_hash_table_t*) pj_hash_create(pj_pool_t *pool, unsigned size)
pj_hash_table_t *h;
unsigned table_size;
- /* Check that PJ_HASH_ENTRY_SIZE is correct. */
- PJ_ASSERT_RETURN(sizeof(pj_hash_entry)==PJ_HASH_ENTRY_SIZE, NULL);
+ /* Check that PJ_HASH_ENTRY_BUF_SIZE is correct. */
+ PJ_ASSERT_RETURN(sizeof(pj_hash_entry)<=PJ_HASH_ENTRY_BUF_SIZE, NULL);
h = PJ_POOL_ALLOC_T(pool, pj_hash_table_t);
h->count = 0;
@@ -237,11 +237,13 @@ PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht,
PJ_DEF(void) pj_hash_set_np( pj_hash_table_t *ht,
const void *key, unsigned keylen,
- pj_uint32_t hval, void *entry_buf, void *value)
+ pj_uint32_t hval, pj_hash_entry_buf entry_buf,
+ void *value)
{
pj_hash_entry **p_entry;
- p_entry = find_entry( NULL, ht, key, keylen, value, &hval, entry_buf );
+ p_entry = find_entry( NULL, ht, key, keylen, value, &hval,
+ (void*)entry_buf );
if (*p_entry) {
if (value == NULL) {
/* delete entry */