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:
IWAMOTO Toshihiro 2015-07-03 11:27:10 +09:00 committed by FUJITA Tomonori
parent 57f9f8f27d
commit 0fc3d72ba2
1 changed files with 1 additions and 1 deletions

View File

@ -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)