Commits

Philip Jenvey committed 2bef841

fix frombytes on empty strings
(transplanted from b1a4f4d62d781879b56bf63cd0da4628ee0518ac)

  • Participants
  • Parent commits cfd0791

Comments (0)

Files changed (2)

File 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])

File 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