summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2000-10-16 12:32:42 +0000
committergstein <gstein@13f79535-47bb-0310-9956-ffa450edef68>2000-10-16 12:32:42 +0000
commit09d08a8a25334a059dd38488797319edda83c077 (patch)
treee269b6c1c94e414fce6368ab084cf7b82cb83442
parent2cf3669543f97367e06efb74fb9a12c7c1b5172a (diff)
downloadlibapr-09d08a8a25334a059dd38488797319edda83c077.tar.gz
Make sure that passing (s, APR_HASH_KEY_STRING) and (s, strlen(s)) are
equivalent. The +1 would lead to subtle errors when people forgot t include the null-term in the hash value. (and it is possible that the caller is extracting a substring for the key and does not *have* a null term when doing a lookup) git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60590 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_hash.h6
-rw-r--r--tables/apr_hash.c2
2 files changed, 5 insertions, 3 deletions
diff --git a/include/apr_hash.h b/include/apr_hash.h
index b1b7afeab..dde1f10c9 100644
--- a/include/apr_hash.h
+++ b/include/apr_hash.h
@@ -74,8 +74,10 @@ extern "C" {
* passed to indicate a string-valued key, and have apr_hash compute the
* length automatically.
*
- * Note: apr_hash will use strlen(key)+1 for the length. This allows
- * apr_hash_this() to return a null-terminated string as the key.
+ * Note: apr_hash will use strlen(key) for the length. The null-terminator
+ * is not included in the hash value (why throw a constant in?).
+ * Since the hash table merely references the provided key (rather
+ * than copying it), apr_hash_this() will return the null-term'd key.
*/
#define APR_HASH_KEY_STRING (-1)
diff --git a/tables/apr_hash.c b/tables/apr_hash.c
index f6b6fad31..b0385fb18 100644
--- a/tables/apr_hash.c
+++ b/tables/apr_hash.c
@@ -216,7 +216,7 @@ static apr_hash_entry_t **find_entry(apr_hash_t *ht,
int i;
if (klen == APR_HASH_KEY_STRING)
- klen = strlen(key) + 1;
+ klen = strlen(key);
/*
* This is Daniel J. Bernstein's popular `times 33' hash function