This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
 
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]