[rtems commit] sys/endian.h: Fix 16-bit int problems

Sebastian Huber sebh at rtems.org
Mon Dec 15 07:30:48 UTC 2014


Module:    rtems
Branch:    master
Commit:    b2ee119f7aeaa96f7305dbda55f7cc14d4d840c5
Changeset: http://git.rtems.org/rtems/commit/?id=b2ee119f7aeaa96f7305dbda55f7cc14d4d840c5

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Dec 15 08:01:59 2014 +0100

sys/endian.h: Fix 16-bit int problems

---

 cpukit/include/sys/endian.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cpukit/include/sys/endian.h b/cpukit/include/sys/endian.h
index abd6f01..b78d8c7 100644
--- a/cpukit/include/sys/endian.h
+++ b/cpukit/include/sys/endian.h
@@ -91,7 +91,7 @@ be16dec(const void *pp)
 {
 	uint8_t const *p = (uint8_t const *)pp;
 
-	return ((p[0] << 8) | p[1]);
+	return (((unsigned)p[0] << 8) | p[1]);
 }
 
 static __inline uint32_t
@@ -99,7 +99,8 @@ be32dec(const void *pp)
 {
 	uint8_t const *p = (uint8_t const *)pp;
 
-	return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+	return (((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) |
+    ((uint32_t)p[2] << 8) | p[3]);
 }
 
 static __inline uint64_t
@@ -115,7 +116,7 @@ le16dec(const void *pp)
 {
 	uint8_t const *p = (uint8_t const *)pp;
 
-	return ((p[1] << 8) | p[0]);
+	return (((unsigned)p[1] << 8) | p[0]);
 }
 
 static __inline uint32_t
@@ -123,7 +124,8 @@ le32dec(const void *pp)
 {
 	uint8_t const *p = (uint8_t const *)pp;
 
-	return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
+	return (((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) |
+    ((uint32_t)p[1] << 8) | p[0]);
 }
 
 static __inline uint64_t




More information about the vc mailing list