Skip to content

Commit

Permalink
Fix possible constant overflow
Browse files Browse the repository at this point in the history
Found by Coverity Scan

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Sep 8, 2024
1 parent d6e9ab6 commit 0b7bb20
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mrdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ static unsigned short in_cksum(unsigned short *addr, int len)
{
unsigned short answer = 0;
unsigned short *w = addr;
unsigned int sum = 0;
int nleft = len;
int sum = 0;

/*
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
Expand All @@ -108,7 +108,7 @@ static unsigned short in_cksum(unsigned short *addr, int len)
/* add back carry outs from top 16 bits to low 16 bits */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
answer = ~sum; /* truncate to 16 bits */
answer = ~sum & 0xffff; /* truncate to 16 bits */

return answer;
}
Expand Down

0 comments on commit 0b7bb20

Please sign in to comment.