From: Grant Edwards <grante@visi.com>
To: ecos-patches@ecos.sourceware.org
Subject: Fix for hal_endian.h SWAP16() macro
Date: Mon, 24 Sep 2007 16:57:00 -0000 [thread overview]
Message-ID: <20070924165701.GA453@grante.dsl.visi.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
The SWAP16() macro is broken.
unsigned u = SWAP16(0x1234);
u will be 0x123412 instead of 0x3412.
Here's a fix.
I believe that the SWAP32() macro will also break in a similar
way on systems where "int" is larger than 32 bits, but I have
no way to test that conjecture.
--
Grant Edwards
grante@visi.com
[-- Attachment #2: hal_endian.h--SWAP16.patch --]
[-- Type: text/plain, Size: 1156 bytes --]
? hal_endian.h--SWAP16.patch
Index: hal_endian.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/common/current/include/hal_endian.h,v
retrieving revision 1.3
diff -U10 -r1.3 hal_endian.h
--- hal_endian.h 23 May 2002 23:02:47 -0000 1.3
+++ hal_endian.h 24 Sep 2007 16:48:40 -0000
@@ -56,21 +56,21 @@
#include <pkgconf/hal.h> // CYGBLD_HAL_ENDIAN_H
#include <cyg/infra/cyg_type.h> // endian setting
// Allow HALs to override the generic implementation of swap macros
#ifdef CYGBLD_HAL_ENDIAN_H
# include CYGBLD_HAL_ENDIAN_H
#endif
#ifndef CYG_SWAP16
# define CYG_SWAP16(_x_) \
- ({ cyg_uint16 _x = (_x_); ((_x << 8) | (_x >> 8)); })
+ ({ cyg_uint16 _x = (_x_); (cyg_uint16)((_x << 8) | (_x >> 8)); })
#endif
#ifndef CYG_SWAP32
# define CYG_SWAP32(_x_) \
({ cyg_uint32 _x = (_x_); \
((_x << 24) | \
((0x0000FF00UL & _x) << 8) | \
((0x00FF0000UL & _x) >> 8) | \
(_x >> 24)); })
#endif
next reply other threads:[~2007-09-24 16:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-24 16:57 Grant Edwards [this message]
2007-09-27 15:09 ` Grant Edwards
2007-09-27 15:32 ` Jonathan Larmour
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070924165701.GA453@grante.dsl.visi.com \
--to=grante@visi.com \
--cc=ecos-patches@ecos.sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).