diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-05-28 11:49:46 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-05-28 11:49:46 +0000 |
commit | 7c28b42ad3fd73d9d7f07b0ebfd3b7f501d71a9f (patch) | |
tree | 7a03c60792cca873cba6f1b5255e932fec4bc861 | |
parent | 26be3e55bedc2f31559151d2608aa338badfbbed (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
-rw-r--r-- | pjlib-util/src/pjlib-util/resolver.c | 6 | ||||
-rw-r--r-- | pjlib/include/pj/hash.h | 18 | ||||
-rw-r--r-- | pjlib/src/pj/hash.c | 10 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_ua_layer.c | 2 |
4 files changed, 20 insertions, 16 deletions
diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c index a2a12fec..080249a5 100644 --- a/pjlib-util/src/pjlib-util/resolver.c +++ b/pjlib-util/src/pjlib-util/resolver.c @@ -125,8 +125,8 @@ struct pj_dns_async_query unsigned transmit_cnt; /**< Number of transmissions. */ struct res_key key; /**< Key to index this query. */ - char hbufid[PJ_HASH_ENTRY_SIZE]; /**< Hash buffer 1 */ - char hbufkey[PJ_HASH_ENTRY_SIZE]; /**< Hash buffer 2 */ + pj_hash_entry_buf hbufid; /**< Hash buffer 1 */ + pj_hash_entry_buf hbufkey; /**< Hash buffer 2 */ pj_timer_entry timer_entry; /**< Timer to manage timeouts */ unsigned options; /**< Query options. */ void *user_data; /**< Application data. */ @@ -144,7 +144,7 @@ struct cached_res struct res_key key; /**< Resource key. */ char buf[RES_BUF_SZ];/**< Resource buffer. */ - char hbuf[PJ_HASH_ENTRY_SIZE]; /**< Hash buffer */ + pj_hash_entry_buf hbuf; /**< Hash buffer */ pj_time_val expiry_time; /**< Expiration time. */ pj_dns_parsed_packet *pkt; /**< The response packet. */ }; 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 */ diff --git a/pjsip/src/pjsip/sip_ua_layer.c b/pjsip/src/pjsip/sip_ua_layer.c index be89e2b6..cff58133 100644 --- a/pjsip/src/pjsip/sip_ua_layer.c +++ b/pjsip/src/pjsip/sip_ua_layer.c @@ -62,7 +62,7 @@ struct dlg_set PJ_DECL_LIST_MEMBER(struct dlg_set); /* This is the buffer to store this entry in the hash table. */ - char ht_entry[PJ_HASH_ENTRY_SIZE]; + pj_hash_entry_buf ht_entry; /* List of dialog in this dialog set. */ struct dlg_set_head dlg_list; |