[lib] hash compare function arguments ought to be const qualified

2008-08-14 Stephen Hemminger <stephen.hemminger@vyatta.com>

	* lib/hash.h: (struct hash) Hash comparator callback really
	  ought to treat storage behind arguments as constant - a compare
	  function with side-effects would be evil.
	* */*.c: Adjust comparator functions similarly, thus fixing at least
	  a few compiler warnings about const qualifier being dropped.

Signed-off-by: Paul Jakma <paul@quagga.net>
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 752099d..6f13974 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -131,15 +131,13 @@
 }
 
 static int
-cluster_hash_cmp (void *p1, void *p2)
+cluster_hash_cmp (const void *p1, const void *p2)
 {
-  struct cluster_list * cluster1 = (struct cluster_list *) p1;
-  struct cluster_list * cluster2 = (struct cluster_list *) p2;
+  const struct cluster_list * cluster1 = p1;
+  const struct cluster_list * cluster2 = p2;
 
-  if (cluster1->length == cluster2->length &&
-      memcmp (cluster1->list, cluster2->list, cluster1->length) == 0)
-    return 1;
-  return 0;
+  return (cluster1->length == cluster2->length &&
+	  memcmp (cluster1->list, cluster2->list, cluster1->length) == 0);
 }
 
 static void
@@ -267,15 +265,13 @@
 }
 
 static int
-transit_hash_cmp (void *p1, void *p2)
+transit_hash_cmp (const void *p1, const void *p2)
 {
-  struct transit * transit1 = (struct transit *) p1;
-  struct transit * transit2 = (struct transit *) p2;
+  const struct transit * transit1 = p1;
+  const struct transit * transit2 = p2;
 
-  if (transit1->length == transit2->length &&
-      memcmp (transit1->val, transit2->val, transit1->length) == 0)
-    return 1;
-  return 0;
+  return (transit1->length == transit2->length &&
+	  memcmp (transit1->val, transit2->val, transit1->length) == 0);
 }
 
 static void
@@ -393,10 +389,10 @@
 }
 
 int
-attrhash_cmp (void *p1, void *p2)
+attrhash_cmp (const void *p1, const void *p2)
 {
-  struct attr * attr1 = (struct attr *) p1;
-  struct attr * attr2 = (struct attr *) p2;
+  const struct attr * attr1 = p1;
+  const struct attr * attr2 = p2;
 
   if (attr1->flag == attr2->flag
       && attr1->origin == attr2->origin
@@ -408,8 +404,8 @@
       && attr1->pathlimit.ttl == attr2->pathlimit.ttl
       && attr1->pathlimit.as == attr2->pathlimit.as)
     {
-      struct attr_extra *ae1 = attr1->extra;
-      struct attr_extra *ae2 = attr2->extra;
+      const struct attr_extra *ae1 = attr1->extra;
+      const struct attr_extra *ae2 = attr2->extra;
       
       if (ae1 && ae2
           && ae1->aggregator_as == ae2->aggregator_as
@@ -435,7 +431,7 @@
 }
 
 static void
-attrhash_init ()
+attrhash_init (void)
 {
   attrhash = hash_create (attrhash_key_make, attrhash_cmp);
 }