From 87b11024cd38f6d7543d2f29e8492ad404e5977a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 2 Aug 2015 21:16:08 -0400 Subject: [PATCH] Save fixes. --- toxcore/Messenger.c | 10 ++++++---- toxcore/util.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 16e03cbc..6946e809 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2570,9 +2570,10 @@ void messenger_save(const Messenger *m, uint8_t *data) uint32_t *data32, size32 = sizeof(uint32_t); data32 = (uint32_t *)data; - data32[0] = 0; - data32[1] = MESSENGER_STATE_COOKIE_GLOBAL; - data += size32 * 2; + memset(data, 0, size32); + data += size32; + host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL); + data += size32; #ifdef DEBUG assert(sizeof(get_nospam(&(m->fr))) == sizeof(uint32_t)); @@ -2748,7 +2749,8 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length) if (length < cookie_len) return -1; - memcpy(data32, data, sizeof(data32)); + memcpy(data32, data, sizeof(uint32_t)); + lendian_to_host32(data32 + 1, data + sizeof(uint32_t)); if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) return load_state(messenger_load_state_callback, m, data + cookie_len, diff --git a/toxcore/util.h b/toxcore/util.h index 7cd6bb8b..fde9f03c 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -47,6 +47,7 @@ uint16_t lendian_to_host16(uint16_t lendian); #define host_tolendian16(x) lendian_to_host16(x) void host_to_lendian32(uint8_t *dest, uint32_t num); +void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); /* state load/save */ typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);