Commits

Philip Jenvey committed b1a4f4d

fix frombytes on empty strings

Comments (0)

Files changed (2)

pypy/rlib/rbigint.py

     def frombytes(s, byteorder, signed):
         if byteorder not in ('big', 'little'):
             raise InvalidEndiannessError()
+        if not s:
+            return NULLRBIGINT
 
         if byteorder != BYTEORDER:
             msb = ord(s[0])

pypy/rlib/test/test_rbigint.py

         assert res == -42.0
 
     def test_frombytes(self):
+        bigint = rbigint.frombytes('', byteorder='big', signed=True)
+        assert bigint.tolong() == 0
         s = "\xFF\x12\x34\x56"
         bigint = rbigint.frombytes(s, byteorder="big", signed=False)
         assert bigint.tolong() == 0xFF123456