public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: chris.mason@oracle.com, linux-nfs@vger.kernel.org
Subject: [PATCH 4/6] tcpwrapper: Fix signage problems in the tcp_wrappers hash function
Date: Fri, 15 Jan 2010 12:50:06 -0500	[thread overview]
Message-ID: <20100115175006.30104.12728.stgit@localhost.localdomain> (raw)
In-Reply-To: <20100115174426.30104.3492.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>

Eliminate the following compiler warnings:

tcpwrapper.c:78: warning: no previous prototype for =E2=80=98strtoint=E2=
=80=99
tcpwrapper.c: In function =E2=80=98strtoint=E2=80=99:
tcpwrapper.c:81: warning: conversion to =E2=80=98int=E2=80=99 from =E2=80=
=98size_t=E2=80=99 may change the sign of the result
tcpwrapper.c:85: warning: conversion to =E2=80=98unsigned int=E2=80=99 =
from =E2=80=98int=E2=80=99 may change the sign of the result
tcpwrapper.c: In function =E2=80=98hashint=E2=80=99:
tcpwrapper.c:91: warning: conversion to =E2=80=98int=E2=80=99 from =E2=80=
=98unsigned int=E2=80=99 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>
---

 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);
=20
-inline unsigned int strtoint(char *str)
+static unsigned long
+strtoint(const char *str)
 {
-	unsigned int n =3D 0;
-	int len =3D strlen(str);
-	int i;
+	unsigned long i, n =3D 0;
+	size_t len =3D strlen(str);
=20
-	for (i=3D0; i < len; i++)
-		n+=3D((int)str[i])*i;
+	for (i =3D 0; i < len; i++)
+		n +=3D (unsigned char)str[i] * i;
=20
 	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)))
=20
 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;
=20
 	hptr =3D (haccess_t *)malloc(sizeof(haccess_t));
 	if (hptr =3D=3D NULL)
@@ -117,8 +123,8 @@ void haccess_add(struct sockaddr_in *addr, u_long p=
rog, 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;
=20
 	hash =3D HASH(inet_ntoa(addr->sin_addr), prog);
 	head =3D &(haccess_tbl[hash]);


  parent reply	other threads:[~2010-01-15 17:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-15 17:49 [PATCH 0/6] IPv6 support for nfs-utils tcpwrapper shim Chuck Lever
     [not found] ` <20100115174426.30104.3492.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-01-15 17:49   ` [PATCH 1/6] tcpwrappers: Use xlog() instead of perror(3) and syslog(2) Chuck Lever
2010-01-15 17:49   ` [PATCH 2/6] tcp_wrappers: Use getifaddrs(3) if it is available Chuck Lever
2010-01-15 17:49   ` [PATCH 3/6] tcp_wrapper: Clean up logit() Chuck Lever
2010-01-15 17:50   ` Chuck Lever [this message]
2010-01-15 17:50   ` [PATCH 5/6] tcpwrapper: Eliminated shadowed declaration warnings Chuck Lever
2010-01-15 17:50   ` [PATCH 6/6] tcpwrapper: Add support for IPv6 Chuck Lever
2010-01-15 18:04   ` [PATCH 0/6] IPv6 support for nfs-utils tcpwrapper shim Steve Dickson
     [not found]     ` <4B50AE34.3020009-AfCzQyP5zfLQT0dZR+AlfA@public.gmane.org>
2010-01-15 18:27       ` Chuck Lever
2010-01-15 18:37         ` Steve Dickson
     [not found]           ` <4B50B5F0.6020202-AfCzQyP5zfLQT0dZR+AlfA@public.gmane.org>
2010-01-15 18:59             ` Chuck Lever
2010-01-15 19:32               ` Steve Dickson
  -- strict thread matches above, loose matches on Subject: below --
2010-01-15 21:31 [PATCH 0/6] IPv6 support for nfs-utils tcpwrapper shim (take 2) Chuck Lever
     [not found] ` <20100115212102.18214.19398.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-01-15 21:31   ` [PATCH 4/6] tcpwrapper: Fix signage problems in the tcp_wrappers hash function Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100115175006.30104.12728.stgit@localhost.localdomain \
    --to=chuck.lever@oracle.com \
    --cc=chris.mason@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox