Save fixes.

This commit is contained in:
irungentoo 2015-08-02 21:16:08 -04:00
parent 7e964d4370
commit 87b11024cd
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 7 additions and 4 deletions

View File

@ -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,

View File

@ -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);