FYI ... also got rid of the stupid +1
----- Forwarded message from gstein@locus.apache.org -----
Reply-To: new-httpd@apache.org
Date: 16 Oct 2000 12:32:43 -0000
From: gstein@locus.apache.org
To: apache-2.0-cvs@apache.org
Subject: cvs commit: apache-2.0/src/lib/apr/tables apr_hash.c
gstein 00/10/16 05:32:43
Modified: src/lib/apr/include apr_hash.h
src/lib/apr/tables apr_hash.c
Log:
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)
Revision Changes Path
1.14 +4 -2 apache-2.0/src/lib/apr/include/apr_hash.h
Index: apr_hash.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_hash.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- apr_hash.h 2000/10/16 06:04:43 1.13
+++ apr_hash.h 2000/10/16 12:32:42 1.14
@@ -74,8 +74,10 @@
* 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)
1.7 +1 -1 apache-2.0/src/lib/apr/tables/apr_hash.c
Index: apr_hash.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/tables/apr_hash.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- apr_hash.c 2000/10/16 06:04:49 1.6
+++ apr_hash.c 2000/10/16 12:32:42 1.7
@@ -216,7 +216,7 @@
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
----- End forwarded message -----
--
Greg Stein, http://www.lyra.org/
Received on Sat Oct 21 14:36:11 2006