Skip to content

Commit

Permalink
Exclude checksum itself from checksum calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxianer99 committed Mar 8, 2022
1 parent e9c81e9 commit 8ed0397
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 24c16.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ int update_checksum(t_eeprom_data* data)

p_data = (char*)data;

for (size_t i=0; i<sizeof(*data); i++)
for (size_t i=0; i < (sizeof(*data) - sizeof(data->checksum)); i++)
{
checksum += *p_data;
p_data++;
}

//fprintf(stderr, "Checksum: %x\n", checksum);
data->checksum = checksum;

return (0);
}

Expand Down Expand Up @@ -56,7 +57,7 @@ char verify_checksum(t_eeprom_data* data)

p_data = (char*)data;

for (size_t i=0; i<sizeof(*data); i++)
for (size_t i=0; i < (sizeof(*data) - sizeof(data->checksum)); i++)
{
checksum += *p_data;
p_data++;
Expand Down

0 comments on commit 8ed0397

Please sign in to comment.