Skip to content

Commit

Permalink
Manually aligned SAVED_FRIEND struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Lindén committed Nov 15, 2016
1 parent b3351d3 commit 425249b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -2634,21 +2634,23 @@ void do_messenger(Messenger *m, void *userdata)
#define SAVED_FRIEND_REQUEST_SIZE 1024
#define NUM_SAVED_PATH_NODES 8

#pragma pack(push, 8)
struct SAVED_FRIEND {
uint8_t status;
uint8_t real_pk[crypto_box_PUBLICKEYBYTES];
uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do.
uint8_t info[SAVED_FRIEND_REQUEST_SIZE];
// ^ The data sent during the friend requests we do.
uint8_t : 1; // padding
uint16_t info_size; // Length of the info.
uint8_t name[MAX_NAME_LENGTH];
uint8_t : 1; // padding
uint16_t name_length;
uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmessage_length;
uint8_t userstatus;
uint8_t : 5; // padding
uint32_t friendrequest_nospam;
uint64_t last_seen_time;
};
#pragma pack(pop)
} __attribute__ ((aligned (8)));

static uint32_t saved_friendslist_size(const Messenger *m)
{
Expand All @@ -2663,6 +2665,7 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
for (i = 0; i < m->numfriends; i++) {
if (m->friendlist[i].status > 0) {
struct SAVED_FRIEND temp;
printf("sizeof SAVED_FRIEND: %lu\n", sizeof(struct SAVED_FRIEND));
memset(&temp, 0, sizeof(struct SAVED_FRIEND));
temp.status = m->friendlist[i].status;
memcpy(temp.real_pk, m->friendlist[i].real_pk, crypto_box_PUBLICKEYBYTES);
Expand Down

0 comments on commit 425249b

Please sign in to comment.