tChange GET/GBIT32 macros to explicitly cast final result to u32int. Otherwise, the type of the expression will be int, and if written to a uvlong (or just a ulong on most 64-bit systems), it will be sign-extended. - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 9a5678a8a95c46913c15a5fc19f73c113e8ed036
 (DIR) parent 3a19470202c5c0f6e9375e5d57535c3d508f2edf
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sat,  4 Nov 2006 20:41:42 +0000
       
       Change GET/GBIT32 macros to explicitly cast final result to u32int.
       Otherwise, the type of the expression will be int, and if written to
       a uvlong (or just a ulong on most 64-bit systems), it will be
       sign-extended.
       
       This was going on in drawfcall with Mouse.msec, which is declared
       as a ulong.
       
       This fix assumes that the protocols only send unsigned numbers,
       which is true.
       
       Diffstat:
         M include/drawfcall.h                 |       2 +-
         M include/fcall.h                     |       2 +-
       
       2 files changed, 2 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/include/drawfcall.h b/include/drawfcall.h
       t@@ -53,7 +53,7 @@ AUTOLIB(draw)
                (p)[3] = (x)&0xFF
        
        #define GET(p, x) \
       -        ((x) = (((p)[0] << 24) | ((p)[1] << 16) | ((p)[2] << 8) | ((p)[3])))
       +        ((x) = (u32int)(((p)[0] << 24) | ((p)[1] << 16) | ((p)[2] << 8) | ((p)[3])))
        
        #define PUT2(p, x) \
                (p)[0] = ((x) >> 8)&0xFF, \
 (DIR) diff --git a/include/fcall.h b/include/fcall.h
       t@@ -50,7 +50,7 @@ struct        Fcall
        
        #define        GBIT8(p)        ((p)[0])
        #define        GBIT16(p)        ((p)[0]|((p)[1]<<8))
       -#define        GBIT32(p)        ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
       +#define        GBIT32(p)        ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
        #define        GBIT64(p)        ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
                                        ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))