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:
David Benjamin 2016-12-22 03:32:19 -05:00 committed by Adam Langley
parent c42a771d7d
commit 55696cecde
3 changed files with 4 additions and 14 deletions

View File

@ -74,9 +74,7 @@ static const size_t kMaxAverageChainLength = 2;
static const size_t kMinAverageChainLength = 1;
_LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) {
_LHASH *ret;
ret = OPENSSL_malloc(sizeof(_LHASH));
_LHASH *ret = OPENSSL_malloc(sizeof(_LHASH));
if (ret == 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);
ret->comp = comp;
if (ret->comp == NULL) {
ret->comp = (lhash_cmp_func) strcmp;
}
ret->hash = hash;
if (ret->hash == NULL) {
ret->hash = (lhash_hash_func) lh_strhash;
}
return ret;
}

View File

@ -60,7 +60,8 @@ static const char *Lookup(
int main(int argc, char **argv) {
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) {
return 1;
}

View File

@ -144,9 +144,7 @@ typedef struct lhash_st {
lhash_hash_func hash;
} _LHASH;
/* lh_new returns a new, empty hash table or NULL on error. If |comp| is NULL,
* |strcmp| will be used. If |hash| is NULL, a generic hash function will be
* used. */
/* lh_new returns a new, empty hash table or NULL on error. */
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