packet_utils: Remove checksum() side-effect
checksum() was modifying argument when it is bytearray. Make sure checksum() doesn't modify its argument. Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
57f9f8f27d
commit
0fc3d72ba2
@ -26,10 +26,10 @@ def carry_around_add(a, b):
|
||||
|
||||
|
||||
def checksum(data):
|
||||
data = six.binary_type(data) # input can be bytearray.
|
||||
if len(data) % 2:
|
||||
data += b'\x00'
|
||||
|
||||
data = six.binary_type(data) # input can be bytearray.
|
||||
s = sum(array.array('H', data))
|
||||
s = (s & 0xffff) + (s >> 16)
|
||||
s += (s >> 16)
|
||||
|
Loading…
Reference in New Issue
Block a user