aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/endian.h
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2010-05-20 06:16:13 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2010-05-20 06:16:13 +0000
commitf7ea97bde337b7fa5d5326b2e7ec5002343a3589 (patch)
treedf7adae4921c5526b4a58cb00c784f9573d4bc44 /sys/sys/endian.h
parent97fea87b496a14be621e8e5941dd7837711c18e7 (diff)
downloadsrc-f7ea97bde337b7fa5d5326b2e7ec5002343a3589.tar.gz
src-f7ea97bde337b7fa5d5326b2e7ec5002343a3589.zip
Fix some way-past-brucification complaints from FlexeLint.
Notes
Notes: svn path=/head/; revision=208331
Diffstat (limited to 'sys/sys/endian.h')
-rw-r--r--sys/sys/endian.h41
1 files changed, 23 insertions, 18 deletions
diff --git a/sys/sys/endian.h b/sys/sys/endian.h
index 35a43804b92c..d50110cabc5d 100644
--- a/sys/sys/endian.h
+++ b/sys/sys/endian.h
@@ -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_ */