NetBSD Problem Report #121

Date: Fri, 11 Feb 1994 15:05:02 -0800
From: thomas@mathematik.uni-Bremen.de
Reply-To: thomas@mathematik.uni-Bremen.de
To: gnats-admin
Cc: gnats-admin, netbsd-bugs
Subject: port-i386/121: endian.h uses X in byte swap macros

>Number:         121
>Category:       port-i386
>Synopsis:       endian.h uses X in byte swap macros
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 11 15:05:01 +0000 1994
>Closed-Date:    Thu Feb 24 01:30:44 +0000 1994
>Last-Modified:  Sat Sep 15 07:49:35 +0000 2012
>Originator:     Thomas Eberhardt
>Release:        
>Organization:
CeVis, University of Bremen, Germany
>Environment:

Machine: i386
>Description:
	endian.h uses X in his byte swap macros.  This causes problems
	if applications #define X as, for example, 0.
>How-To-Repeat:
	#define X 0
	and use ntohl etc. macros => BOOM
>Fix:

Replace X with __x:

*** sys/arch/i386/include/endian.h-	Mon Dec 20 12:22:08 1993
--- sys/arch/i386/include/endian.h	Fri Feb 11 22:09:24 1994
***************
*** 71,119 ****

  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("bswap %1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })
  #else
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register unsigned short X = (x); \
     asm ("xchgb %h1, %b1" \
! 	: "=q" (X) \
! 	: "0" (X)); \
!    X; })

  #else	/* __GNUC__ >= 2 */

  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long X = (x); \
     asm ("bswap %1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })
  #else
  #define __byte_swap_long(x) \
! ({ register u_long X = (x); \
     asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register u_short X = (x); \
     asm ("rorw $8, %w1" \
! 	: "=r" (X) \
! 	: "0" (X)); \
!    X; })

  #endif	/* __GNUC__ >= 2 */

--- 71,119 ----

  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("bswap %1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #else
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register unsigned short __x = (x); \
     asm ("xchgb %h1, %b1" \
! 	: "=q" (__x) \
! 	: "0" (__x)); \
!    __x; })

  #else	/* __GNUC__ >= 2 */

  #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
  #define __byte_swap_long(x) \
! ({ register unsigned long __x = (x); \
     asm ("bswap %1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #else
  #define __byte_swap_long(x) \
! ({ register u_long __x = (x); \
     asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })
  #endif	/* KERNEL && ... */
  #define __byte_swap_word(x) \
! ({ register u_short __x = (x); \
     asm ("rorw $8, %w1" \
! 	: "=r" (__x) \
! 	: "0" (__x)); \
!    __x; })

  #endif	/* __GNUC__ >= 2 */

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: cgd 
State-Changed-When: Wed Feb 23 17:30:44 PST 1994 
State-Changed-Why:  
fixed; patch applied 

>Unformatted:



 SUP 8.26 (4.3 BSD) for file NetBSD-current/supfile at Feb 11 22:25:24
 Last update occurred at Fri Feb 11 11:28:46 1994 for collection current
 Last update occurred at Thu Feb 10 12:29:24 1994 for collection current
 Last update occurred at Thu Feb 10 12:29:24 1994 for collection current

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.