Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 May 2010 06:16:13 +0000 (UTC)
From:      Poul-Henning Kamp <phk@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r208331 - head/sys/sys
Message-ID:  <201005200616.o4K6GDN8010282@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: phk
Date: Thu May 20 06:16:13 2010
New Revision: 208331
URL: http://svn.freebsd.org/changeset/base/208331

Log:
  Fix some way-past-brucification complaints from FlexeLint.

Modified:
  head/sys/sys/endian.h

Modified: head/sys/sys/endian.h
==============================================================================
--- head/sys/sys/endian.h	Thu May 20 06:05:40 2010	(r208330)
+++ head/sys/sys/endian.h	Thu May 20 06:16:13 2010	(r208331)
@@ -33,6 +33,11 @@
 #include <sys/_types.h>
 #include <machine/endian.h>
 
+#ifndef _UINT8_T_DECLARED
+typedef	__uint8_t	uint8_t;
+#define	_UINT8_T_DECLARED
+#endif
+ 
 #ifndef _UINT16_T_DECLARED
 typedef	__uint16_t	uint16_t;
 #define	_UINT16_T_DECLARED
@@ -94,7 +99,7 @@ typedef	__uint64_t	uint64_t;
 static __inline uint16_t
 be16dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
 	return ((p[0] << 8) | p[1]);
 }
@@ -102,15 +107,15 @@ be16dec(const void *pp)
 static __inline uint32_t
 be32dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
-	return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+	return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
 }
 
 static __inline uint64_t
 be64dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
 	return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
 }
@@ -118,7 +123,7 @@ be64dec(const void *pp)
 static __inline uint16_t
 le16dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
 	return ((p[1] << 8) | p[0]);
 }
@@ -126,15 +131,15 @@ le16dec(const void *pp)
 static __inline uint32_t
 le32dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
-	return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+	return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
 }
 
 static __inline uint64_t
 le64dec(const void *pp)
 {
-	unsigned char const *p = (unsigned char const *)pp;
+	uint8_t const *p = (uint8_t const *)pp;
 
 	return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p));
 }
@@ -142,7 +147,7 @@ le64dec(const void *pp)
 static __inline void
 be16enc(void *pp, uint16_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
 	p[0] = (u >> 8) & 0xff;
 	p[1] = u & 0xff;
@@ -151,7 +156,7 @@ be16enc(void *pp, uint16_t u)
 static __inline void
 be32enc(void *pp, uint32_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
 	p[0] = (u >> 24) & 0xff;
 	p[1] = (u >> 16) & 0xff;
@@ -162,16 +167,16 @@ be32enc(void *pp, uint32_t u)
 static __inline void
 be64enc(void *pp, uint64_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
-	be32enc(p, u >> 32);
-	be32enc(p + 4, u & 0xffffffff);
+	be32enc(p, (uint32_t)(u >> 32));
+	be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
 }
 
 static __inline void
 le16enc(void *pp, uint16_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
 	p[0] = u & 0xff;
 	p[1] = (u >> 8) & 0xff;
@@ -180,7 +185,7 @@ le16enc(void *pp, uint16_t u)
 static __inline void
 le32enc(void *pp, uint32_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
 	p[0] = u & 0xff;
 	p[1] = (u >> 8) & 0xff;
@@ -191,10 +196,10 @@ le32enc(void *pp, uint32_t u)
 static __inline void
 le64enc(void *pp, uint64_t u)
 {
-	unsigned char *p = (unsigned char *)pp;
+	uint8_t *p = (uint8_t *)pp;
 
-	le32enc(p, u & 0xffffffff);
-	le32enc(p + 4, u >> 32);
+	le32enc(p, (uint32_t)(u & 0xffffffffU));
+	le32enc(p + 4, (uint32_t)(u >> 32));
 }
 
 #endif	/* _SYS_ENDIAN_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005200616.o4K6GDN8010282>