Skip to content

Commit

Permalink
Fixed bug 1388 - Debian patch(es): endian-ness issues
Browse files Browse the repository at this point in the history
manuel.montezelo@gmail.com 2012-01-20 12:26:38 PST

2) Second bug report: "SDLNet_(Read|Write)(16|32) assume host endianness is
always LE"

http://bugs.debian.org/217221

"When SDL_DATA_ALIGNED is defined, SDLNet_Read16 etc. are defined as
byte-swapping macros. However, since network order is big endian, these
macros should not swap anything on big endian systems. Patch attached."

The accompanying patch "endian.patch" doesn't apply cleanly with 1.2.8 but it
does with 1.2.7.  In any case it's also easy to understand: it removes
conditional execution of code (SDL_BYTEORDER != SDL_BIG_ENDIAN) and keeps only
the (SDL_BYTEORDER == SDL_BIG_ENDIAN) version.
  • Loading branch information
slouken committed Jan 21, 2012
1 parent 5841cee commit b7eb579
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions SDL_net.h
Expand Up @@ -366,31 +366,20 @@ extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void);
#define SDLNet_Write16(value, areap) \
(*SDL_reinterpret_cast(Uint16 *, areap) = SDL_SwapBE16(value))
#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SDLNet_Write16(value, areap) \
do \
{ \
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
area[0] = (value >> 8) & 0xFF; \
area[1] = value & 0xFF; \
} while ( 0 )
#else
#define SDLNet_Write16(value, areap) \
do \
{ \
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
area[1] = (value >> 8) & 0xFF; \
area[0] = value & 0xFF; \
} while ( 0 )
#endif
#endif /* !SDL_DATA_ALIGNED */

/* Write a 32 bit value to network packet buffer */
#if !SDL_DATA_ALIGNED
#define SDLNet_Write32(value, areap) \
*SDL_reinterpret_cast(Uint32 *, areap) = SDL_SwapBE32(value);
#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SDLNet_Write32(value, areap) \
do \
{ \
Expand All @@ -400,47 +389,25 @@ do \
area[2] = (value >> 8) & 0xFF; \
area[3] = value & 0xFF; \
} while ( 0 )
#else
#define SDLNet_Write32(value, areap) \
do \
{ \
Uint8 *area = SDL_reinterpret_cast(Uint8 *, areap); \
area[3] = (value >> 24) & 0xFF; \
area[2] = (value >> 16) & 0xFF; \
area[1] = (value >> 8) & 0xFF; \
area[0] = value & 0xFF; \
} while ( 0 )
#endif
#endif /* !SDL_DATA_ALIGNED */

/* Read a 16 bit value from network packet buffer */
#if !SDL_DATA_ALIGNED
#define SDLNet_Read16(areap) \
(SDL_SwapBE16(*SDL_reinterpret_cast(Uint16 *, areap)))
#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SDLNet_Read16(areap) \
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[1] << 0)
#else
#define SDLNet_Read16(areap) \
(((SDL_reinterpret_cast(Uint8 *, areap))[1] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] << 0)
#endif
#endif /* !SDL_DATA_ALIGNED */

/* Read a 32 bit value from network packet buffer */
#if !SDL_DATA_ALIGNED
#define SDLNet_Read32(areap) \
(SDL_SwapBE32(*SDL_reinterpret_cast(Uint32 *, areap)))
#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SDLNet_Read32(areap) \
(((SDL_reinterpret_cast(Uint8 *, areap))[0] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[1] << 16) | \
((SDL_reinterpret_cast(Uint8 *, areap))[2] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[3] << 0)
#else
#define SDLNet_Read32(areap) \
(((SDL_reinterpret_cast(Uint8 *, areap))[3] << 24) | ((SDL_reinterpret_cast(Uint8 *, areap))[2] << 16) | \
((SDL_reinterpret_cast(Uint8 *, areap))[1] << 8) | (SDL_reinterpret_cast(Uint8 *, areap))[0] << 0)
#endif
#endif /* !SDL_DATA_ALIGNED */

/* Ends C function definitions when using C++ */
Expand Down

0 comments on commit b7eb579

Please sign in to comment.