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 Aug 2, 2019
1 parent 7aab0d9 commit b15a28f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -3050,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 b15a28f

Please sign in to comment.