Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d0fe31

Browse files
committed
Packer.pack_uhyper(): Fixes needed to properly pack unsigned 64 bit
longs where the top bit is set. First, change the masks so that they are `L' longs, otherwise the sign bits will get propagated to the result. Next, do not coerce to int before sending to pack_uint() otherwise Python will generate an OverflowError. Here is a test program that fails without the patch, but now succeeds: import xdrlib addr = (132, 151, 1, 71) uint = 0L for a in addr: uint = (uint << 8) | a ulong64 = uint << 32 p = xdrlib.Packer() p.pack_uhyper(ulong64) buf = p.get_buffer() u = xdrlib.Unpacker(buf) ulong64prime = u.unpack_uhyper() if ulong64 == ulong64prime: print 'okay' else: print 'bogus' print ulong64, ulong64prime
1 parent 8d1ac02 commit 1d0fe31

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/xdrlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def pack_bool(self, x):
5555
else: self.__buf = self.__buf + '\0\0\0\0'
5656

5757
def pack_uhyper(self, x):
58-
self.pack_uint(int(x>>32 & 0xffffffff))
59-
self.pack_uint(int(x & 0xffffffff))
58+
self.pack_uint(x>>32 & 0xffffffffL)
59+
self.pack_uint(x & 0xffffffffL)
6060

6161
pack_hyper = pack_uhyper
6262

0 commit comments

Comments
 (0)