1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ng_inet_csum: fix double-wrap around of carry

This commit is contained in:
Martine Lenders 2015-07-01 18:19:22 +02:00
parent 6ce23a42f5
commit ad6c02b349

View File

@ -43,11 +43,14 @@ uint16_t ng_inet_csum(uint16_t sum, const uint8_t *buf, uint16_t len)
csum += (*buf << 8); /* add last byte as top half of 16-byte word */
}
csum += csum >> 16;
while (csum >> 16) {
uint16_t carry = csum >> 16;
csum = (csum & 0xffff) + carry;
}
DEBUG("inet_sum: new sum = 0x%04" PRIx32 "\n", csum & 0xffff);
DEBUG("inet_sum: new sum = 0x%04" PRIx32 "\n", csum);
return (csum & 0xffff);
return csum;
}
/** @} */