]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
If the length of a hash name is zero, compute it with strlen.
authorTed Lemon <source@isc.org>
Mon, 5 Apr 1999 19:02:42 +0000 (19:02 +0000)
committerTed Lemon <source@isc.org>
Mon, 5 Apr 1999 19:02:42 +0000 (19:02 +0000)
common/hash.c

index 7a303503d358c848ff801ea0a085367061e44601..8fa51e69d9e0add0d837b5708034399a48eeb4b7 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: hash.c,v 1.12 1999/03/16 05:50:34 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: hash.c,v 1.13 1999/04/05 19:02:42 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -81,6 +81,9 @@ void add_hash (table, name, len, pointer)
        if (!table)
                return;
 
+       if (!len)
+               len = strlen (name);
+
        hashno = do_hash (name, len, table -> hash_count);
        bp = new_hash_bucket ("add_hash");
 
@@ -106,6 +109,9 @@ void delete_hash_entry (table, name, len)
        if (!table)
                return;
 
+       if (!len)
+               len = strlen (name);
+
        hashno = do_hash (name, len, table -> hash_count);
 
        /* Go through the list looking for an entry that matches;
@@ -137,19 +143,15 @@ unsigned char *hash_lookup (table, name, len)
 
        if (!table)
                return (unsigned char *)0;
+       if (!len)
+               len = strlen (name);
+
        hashno = do_hash (name, len, table -> hash_count);
 
-       if (len) {
-               for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
-                       if (len == bp -> len
-                           && !memcmp (bp -> name, name, len))
-                               return bp -> value;
-               }
-       } else {
-               for (bp = table -> buckets [hashno]; bp; bp = bp -> next)
-                       if (!strcmp ((char *)bp -> name,
-                                    (char *)name))
-                               return bp -> value;
+       for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
+               if (len == bp -> len
+                   && !memcmp (bp -> name, name, len))
+                       return bp -> value;
        }
        return (unsigned char *)0;
 }