Remove lh_new's default hash and comparator.
This is a memory error for anything other than LHASH_OF(char), which does not exist. No code outside the library creates (or even queries) an LHASH, so we can change this module freely. Change-Id: Ifbc7a1c69a859e07650fcfaa067bdfc68d83fbbc Reviewed-on: https://boringssl-review.googlesource.com/12978 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
c42a771d7d
commit
55696cecde
@ -74,9 +74,7 @@ static const size_t kMaxAverageChainLength = 2;
|
|||||||
static const size_t kMinAverageChainLength = 1;
|
static const size_t kMinAverageChainLength = 1;
|
||||||
|
|
||||||
_LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) {
|
_LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) {
|
||||||
_LHASH *ret;
|
_LHASH *ret = OPENSSL_malloc(sizeof(_LHASH));
|
||||||
|
|
||||||
ret = OPENSSL_malloc(sizeof(_LHASH));
|
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -91,14 +89,7 @@ _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) {
|
|||||||
OPENSSL_memset(ret->buckets, 0, sizeof(LHASH_ITEM *) * ret->num_buckets);
|
OPENSSL_memset(ret->buckets, 0, sizeof(LHASH_ITEM *) * ret->num_buckets);
|
||||||
|
|
||||||
ret->comp = comp;
|
ret->comp = comp;
|
||||||
if (ret->comp == NULL) {
|
|
||||||
ret->comp = (lhash_cmp_func) strcmp;
|
|
||||||
}
|
|
||||||
ret->hash = hash;
|
ret->hash = hash;
|
||||||
if (ret->hash == NULL) {
|
|
||||||
ret->hash = (lhash_hash_func) lh_strhash;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ static const char *Lookup(
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
CRYPTO_library_init();
|
CRYPTO_library_init();
|
||||||
|
|
||||||
std::unique_ptr<_LHASH, FreeLHASH> lh(lh_new(NULL, NULL));
|
std::unique_ptr<_LHASH, FreeLHASH> lh(
|
||||||
|
lh_new((lhash_hash_func)lh_strhash, (lhash_cmp_func)strcmp));
|
||||||
if (!lh) {
|
if (!lh) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -144,9 +144,7 @@ typedef struct lhash_st {
|
|||||||
lhash_hash_func hash;
|
lhash_hash_func hash;
|
||||||
} _LHASH;
|
} _LHASH;
|
||||||
|
|
||||||
/* lh_new returns a new, empty hash table or NULL on error. If |comp| is NULL,
|
/* lh_new returns a new, empty hash table or NULL on error. */
|
||||||
* |strcmp| will be used. If |hash| is NULL, a generic hash function will be
|
|
||||||
* used. */
|
|
||||||
OPENSSL_EXPORT _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp);
|
OPENSSL_EXPORT _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp);
|
||||||
|
|
||||||
/* lh_free frees the hash table itself but none of the elements. See
|
/* lh_free frees the hash table itself but none of the elements. See
|
||||||
|
Loading…
Reference in New Issue
Block a user