Skip to content

Commit

Permalink
cleanup friend loading
Browse files Browse the repository at this point in the history
The assert was removed, because it triggers as soon as the padding bytes
in the struct Saved_Friend are non zero. The Tox specification doesn't
say anything about the value of these bytes, so we should just ignore
them.
  • Loading branch information
sudden6 committed Jan 22, 2020
1 parent 683bc80 commit 90024c3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -3036,9 +3036,7 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)

uint8_t *next_data = friend_save(&temp, cur_data);
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(cur_data, &temp, friend_size()) == 0);
#endif

cur_data = next_data;
++num;
}
Expand All @@ -3052,21 +3050,21 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)

static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
{
if (length % friend_size() != 0) {
const uint32_t l_friend_size = friend_size();

if (length % l_friend_size != 0) {
return STATE_LOAD_STATUS_ERROR; // TODO(endoffile78): error or continue?
}

uint32_t num = length / friend_size();
uint32_t num = length / l_friend_size;
uint32_t i;
const uint8_t *cur_data = data;

for (i = 0; i < num; ++i) {
struct Saved_Friend temp = { 0 };
const uint8_t *next_data = friend_load(&temp, cur_data);
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(&temp, cur_data, friend_size()) == 0);
#endif
assert(next_data - cur_data == l_friend_size);

cur_data = next_data;

if (temp.status >= 3) {
Expand Down

0 comments on commit 90024c3

Please sign in to comment.