hash.h warnings
Andrew Thompson
thompsa at freebsd.org
Tue Apr 3 02:50:13 UTC 2007
On Sun, Mar 25, 2007 at 03:18:42AM -0700, Garrett Cooper wrote:
> On Mar 25, 2007, at 1:38 AM, Andrew Thompson wrote:
>
> >Hi,
> >
> >
> >There was a discussion late last year about how to fix the warnings in
> >sys/sys/hash.h.
> >
> >http://lists.freebsd.org/pipermail/freebsd-net/2006-October/
> >012098.html
> >
> >@/sys/hash.h: In function `hash32_stre':
> >@/sys/hash.h:97: warning: cast discards qualifiers from pointer
> >target type
> >@/sys/hash.h: In function `hash32_strne':
> >@/sys/hash.h:116: warning: cast discards qualifiers from pointer
> >target type
>
> After looking at the source it appears that part of the problem stems
> from the fact that p is an unsigned char pointer, where ep is a
> signed char double pointer. So you're losing some precision in the
> process (hence where the error's coming from I believe).
>
> So, if you modified buf (the pointer that p is pointing to) or ep to
> be compatible with one another, you probably wouldn't get this warning..
I have come up with this patch, can anyone tell me if its correct. There
are no consumers of hash32_stre or hash32_strne in the src tree or
openbgpd/openospfd which hash.h was imported for.
Andrew
-------------- next part --------------
Index: sys/sys/hash.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/hash.h,v
retrieving revision 1.2
diff -u -p -r1.2 hash.h
--- sys/sys/hash.h 12 Mar 2006 15:34:33 -0000 1.2
+++ sys/sys/hash.h 3 Apr 2007 02:31:04 -0000
@@ -86,7 +86,7 @@ hash32_strn(const void *buf, size_t len,
* namei() hashing of path name parts.
*/
static __inline uint32_t
-hash32_stre(const void *buf, int end, char **ep, uint32_t hash)
+hash32_stre(const void *buf, int end, const char **ep, uint32_t hash)
{
const unsigned char *p = buf;
@@ -94,7 +94,7 @@ hash32_stre(const void *buf, int end, ch
hash = HASHSTEP(hash, *p++);
if (ep)
- *ep = (char *)p;
+ *ep = p;
return hash;
}
@@ -105,7 +105,8 @@ hash32_stre(const void *buf, int end, ch
* as a helper for the namei() hashing of path name parts.
*/
static __inline uint32_t
-hash32_strne(const void *buf, size_t len, int end, char **ep, uint32_t hash)
+hash32_strne(const void *buf, size_t len, int end, const char **ep,
+ uint32_t hash)
{
const unsigned char *p = buf;
@@ -113,7 +114,7 @@ hash32_strne(const void *buf, size_t len
hash = HASHSTEP(hash, *p++);
if (ep)
- *ep = (char *)p;
+ *ep = p;
return hash;
}
Index: share/man/man9/hash.9
===================================================================
RCS file: /home/ncvs/src/share/man/man9/hash.9,v
retrieving revision 1.3
diff -u -p -r1.3 hash.9
--- share/man/man9/hash.9 19 Oct 2006 11:03:44 -0000 1.3
+++ share/man/man9/hash.9 3 Apr 2007 02:19:23 -0000
@@ -47,9 +47,9 @@
.Ft uint32_t
.Fn hash32_strn "const void *buf" "size_t len" "uint32_t hash"
.Ft uint32_t
-.Fn hash32_stre "const void *buf" "int end" "char **ep" "uint32_t hash"
+.Fn hash32_stre "const void *buf" "int end" "const char **ep" "uint32_t hash"
.Ft uint32_t
-.Fn hash32_strne "const void *buf" "size_t len" "int end" "char **ep" "uint32_t hash"
+.Fn hash32_strne "const void *buf" "size_t len" "int end" "const char **ep" "uint32_t hash"
.Sh DESCRIPTION
The
.Fn hash32
More information about the freebsd-hackers
mailing list