[comp.windows.x] Bug in Xlib/XKeyBind.c

dupuy@amsterdam.columbia.edu (Alexander Dupuy) (05/03/87)

There is a small bug in X/Xlib/XKeyBind.c relating to unbinding mappings.
I noticed it when my Sun 3.2 C compiler generated a warning.

cc -pg -O -I../include  -c XKeyBind.c
"XKeyBind.c", line 289: warning: constant 1024 is out of range of unsigned char comparison 
"XKeyBind.c", line 289: warning: value coerced to 0 for bug compatibility
"XKeyBind.c", line 289: warning: do not expect this coercion in release 4.0
mv XKeyBind.o profiled/XKeyBind.o
cc -O -I../include  -c XKeyBind.c
"XKeyBind.c", line 289: warning: constant 1024 is out of range of unsigned char comparison 
"XKeyBind.c", line 289: warning: value coerced to 0 for bug compatibility
"XKeyBind.c", line 289: warning: do not expect this coercion in release 4.0

When a runtime keybinding is undone, the metabits field is set to EMPTY_ENTRY,
which in XKeyBind.c is #defined as LeftMask (aka 0x0400).  Unfortunately, the
metabits field in the sntry struct is defined as unsigned char.  The fix is to
change EMPTY_ENTRY to 0x80, a value which can not be generated by the
FullKeyState() macro.

I'm surprised nobody else who compiled X on a Sun running 3.[234..] has found
this bug before (or maybe I just missed the posting).

@alex

here are the diffs for lazy people:

*** /u/src/X/Xlib/XKeyBind.c	Sat Apr  4 15:36:07 1987
--- XKeyBind.c	Sat May  2 23:10:39 1987
***************
*** 11,17 ****
  #include <stdio.h>
  #include <strings.h>
  
! #define EMPTY_ENTRY LeftMask 
     /* if the "metabits" field of a runtime table entry contains this,
      it's an empty entry */
  
--- 11,19 ----
  #include <stdio.h>
  #include <strings.h>
  
!    /* ad - this was LeftMask, but that's too big to fit in an unsigned char,
!     so I changed it to 0x80, which can't be generated by {,Full}KeyState() */
! #define EMPTY_ENTRY 0x80 
     /* if the "metabits" field of a runtime table entry contains this,
      it's an empty entry */
  
---
arpanet: dupuy@columbia.edu
uucp:	...!seismo!columbia!dupuy