[Bug 1955] New: Fix CPU_swap_u16
bugzilla-daemon at rtems.org
bugzilla-daemon at rtems.org
Tue Nov 8 21:42:40 UTC 2011
https://www.rtems.org/bugzilla/show_bug.cgi?id=1955
Summary: Fix CPU_swap_u16
Product: RTEMS
Version: HEAD
Platform: lm32
OS/Version: RTEMS
Status: NEW
Severity: normal
Priority: P3
Component: cpukit
AssignedTo: joel.sherrill at oarcorp.com
ReportedBy: seb at tmplab.org
(from Werner Almesberger)
CPU_swap_u16 is a macro, with all the problems that entails,
such as:
- multiple evaluation of the argument,
- tricky type semantics, and last but not least
- the need to protect arguments
The lack of the latter is a bug, though I don't think it had any
real-life impact on M1 behaviour this far.
Converting this to an inline function solves all these issues.
- Werner
Index: cpukit/score/cpu/lm32/rtems/score/cpu.h
===================================================================
RCS file: /usr1/CVS/rtems/cpukit/score/cpu/lm32/rtems/score/cpu.h,v
retrieving revision 1.14
diff -u -r1.14 cpu.h
--- cpukit/score/cpu/lm32/rtems/score/cpu.h 27 Sep 2011 09:17:02 -0000
1.14
+++ cpukit/score/cpu/lm32/rtems/score/cpu.h 8 Nov 2011 18:27:45 -0000
@@ -1258,8 +1258,10 @@
* @param[in] value is the value to be swapped
* @return the value after being endian swapped
*/
-#define CPU_swap_u16( value ) \
- (((value&0xff) << 8) | ((value >> 8)&0xff))
+static inline uint16_t CPU_swap_u16(uint16_t v)
+{
+ return v << 8 | v >> 8;
+}
#ifdef __cplusplus
}
--
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.
More information about the bugs
mailing list