This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
hal_endian.h error in swap macro
- From: Brian Murphy <brm at tt dot dk>
- To: ecos-patches at sources dot redhat dot com
- Date: Thu, 15 May 2003 13:20:56 +0200
- Subject: hal_endian.h error in swap macro
The attached patch fixes a problem with the hal swap macro CYG_SWAP16 which
neither masks the input values nor typecasts to a 16 bit type on return.
I have also
made the same change to the 32 bit swap macro.
Why are the other set of endianness macros (with the network code) not
written
in terms of the hal macros? It would save some confusion I think.
/Brian
Index: packages/hal/common/current/include/hal_endian.h
===================================================================
RCS file: /usr/cvs/sw/ecos/packages/hal/common/current/include/hal_endian.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 hal_endian.h
--- packages/hal/common/current/include/hal_endian.h 26 Jul 2002 13:44:00 -0000 1.1.1.1
+++ packages/hal/common/current/include/hal_endian.h 15 May 2003 11:08:33 -0000
@@ -63,16 +63,17 @@
#ifndef CYG_SWAP16
# define CYG_SWAP16(_x_) \
- ({ cyg_uint16 _x = (_x_); ((_x << 8) | (_x >> 8)); })
+ ({ cyg_uint16 _x = (_x_); (cyg_uint16)(((_x & 0x00FFU) << 8) | \
+ ((_x & 0xFF00U) >> 8)); })
#endif
#ifndef CYG_SWAP32
-# define CYG_SWAP32(_x_) \
- ({ cyg_uint32 _x = (_x_); \
- ((_x << 24) | \
- ((0x0000FF00UL & _x) << 8) | \
- ((0x00FF0000UL & _x) >> 8) | \
- (_x >> 24)); })
+# define CYG_SWAP32(_x_) \
+ ({ cyg_uint32 _x = (_x_); \
+ (cyg_uint32)( ((0x000000FFUL & _x) << 24) | \
+ ((0x0000FF00UL & _x) << 8) | \
+ ((0x00FF0000UL & _x) >> 8) | \
+ ((0xFF000000UL & _x) >> 24) ); })
#endif