diff options
author | irungentoo <irungentoo@gmail.com> | 2015-08-02 21:16:08 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-08-02 21:16:08 -0400 |
commit | 87b11024cd38f6d7543d2f29e8492ad404e5977a (patch) | |
tree | 0f189332924e31ebae2492edb84149d711a3d67b | |
parent | 7e964d4370b44025ece4fbae66b690f5d3758651 (diff) |
Save fixes.
-rw-r--r-- | toxcore/Messenger.c | 10 | ||||
-rw-r--r-- | 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) | |||
2570 | uint32_t *data32, size32 = sizeof(uint32_t); | 2570 | uint32_t *data32, size32 = sizeof(uint32_t); |
2571 | 2571 | ||
2572 | data32 = (uint32_t *)data; | 2572 | data32 = (uint32_t *)data; |
2573 | data32[0] = 0; | 2573 | memset(data, 0, size32); |
2574 | data32[1] = MESSENGER_STATE_COOKIE_GLOBAL; | 2574 | data += size32; |
2575 | data += size32 * 2; | 2575 | host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL); |
2576 | data += size32; | ||
2576 | 2577 | ||
2577 | #ifdef DEBUG | 2578 | #ifdef DEBUG |
2578 | assert(sizeof(get_nospam(&(m->fr))) == sizeof(uint32_t)); | 2579 | 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) | |||
2748 | if (length < cookie_len) | 2749 | if (length < cookie_len) |
2749 | return -1; | 2750 | return -1; |
2750 | 2751 | ||
2751 | memcpy(data32, data, sizeof(data32)); | 2752 | memcpy(data32, data, sizeof(uint32_t)); |
2753 | lendian_to_host32(data32 + 1, data + sizeof(uint32_t)); | ||
2752 | 2754 | ||
2753 | if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) | 2755 | if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) |
2754 | return load_state(messenger_load_state_callback, m, data + cookie_len, | 2756 | 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); | |||
47 | #define host_tolendian16(x) lendian_to_host16(x) | 47 | #define host_tolendian16(x) lendian_to_host16(x) |
48 | 48 | ||
49 | void host_to_lendian32(uint8_t *dest, uint32_t num); | 49 | void host_to_lendian32(uint8_t *dest, uint32_t num); |
50 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); | ||
50 | 51 | ||
51 | /* state load/save */ | 52 | /* state load/save */ |
52 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); | 53 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); |