diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2010-01-17 16:50:29 -0500 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2010-01-17 16:50:29 -0500 |
commit | 90c944c9cc1fde845caa29b98c2864eb32660403 (patch) | |
tree | 69801abe26fe4fe829a6e236bd0e4c9ca3f203c1 /support/misc | |
parent | e94001c0bb9ee7847a2ef7a3b436acd74acb9fd6 (diff) | |
download | nfs-utils-90c944c9cc1fde845caa29b98c2864eb32660403.tar.gz |
tcpwrapper: Fix signage problems in the tcp_wrappers hash function
Eliminate the following compiler warnings:
tcpwrapper.c:78: warning: no previous prototype for strtoint
tcpwrapper.c: In function strtoint
tcpwrapper.c:81: warning: conversion to int size_t may change the
sign of the result
tcpwrapper.c:85: warning: conversion to unsigned int from int may
change the sign of the result
tcpwrapper.c: In function hashint:
tcpwrapper.c:91: warning: conversion to int from unsigned int may
change the sign of the result
The hash value is probably computed consistently even with
unexpected sign inversions.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/misc')
-rw-r--r-- | support/misc/tcpwrapper.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/support/misc/tcpwrapper.c b/support/misc/tcpwrapper.c index b981d58..6f65c13 100644 --- a/support/misc/tcpwrapper.c +++ b/support/misc/tcpwrapper.c @@ -75,29 +75,35 @@ hash_head haccess_tbl[HASH_TABLE_SIZE]; static haccess_t *haccess_lookup(struct sockaddr_in *addr, u_long); static void haccess_add(struct sockaddr_in *addr, u_long, int); -inline unsigned int strtoint(char *str) +static unsigned long +strtoint(const char *str) { - unsigned int n = 0; - int len = strlen(str); - int i; + unsigned long i, n = 0; + size_t len = strlen(str); - for (i=0; i < len; i++) - n+=((int)str[i])*i; + for (i = 0; i < len; i++) + n += (unsigned char)str[i] * i; return n; } -static inline int hashint(unsigned int num) + +static unsigned int +hashint(const unsigned long num) +{ + return (unsigned int)(num % HASH_TABLE_SIZE); +} + +static unsigned int +HASH(const char *addr, const unsigned long program) { - return num % HASH_TABLE_SIZE; + return hashint(strtoint(addr) + program); } -#define HASH(_addr, _prog) \ - hashint((strtoint((_addr))+(_prog))) void haccess_add(struct sockaddr_in *addr, u_long prog, int access) { hash_head *head; - haccess_t *hptr; - int hash; + haccess_t *hptr; + unsigned int hash; hptr = (haccess_t *)malloc(sizeof(haccess_t)); if (hptr == NULL) @@ -117,8 +123,8 @@ void haccess_add(struct sockaddr_in *addr, u_long prog, int access) haccess_t *haccess_lookup(struct sockaddr_in *addr, u_long prog) { hash_head *head; - haccess_t *hptr; - int hash; + haccess_t *hptr; + unsigned int hash; hash = HASH(inet_ntoa(addr->sin_addr), prog); head = &(haccess_tbl[hash]); |