Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Clean up friend loading. #1333

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -2966,21 +2966,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