Changed the way statusmessage is allocated

This commit is contained in:
Maxim Biro 2013-08-09 16:34:53 -04:00
parent c6d06ae6ee
commit 9dd691d106

View File

@ -47,8 +47,9 @@ uint8_t self_public_key[crypto_box_PUBLICKEYBYTES];
static uint8_t self_name[MAX_NAME_LENGTH]; static uint8_t self_name[MAX_NAME_LENGTH];
static uint16_t self_name_length; static uint16_t self_name_length;
static uint8_t *self_statusmessage; static uint8_t self_statusmessage[MAX_STATUSMESSAGE_LENGTH];
static uint16_t self_statusmessage_len; static uint16_t self_statusmessage_length;
static USERSTATUS self_userstatus; static USERSTATUS self_userstatus;
static Friend *friendlist; static Friend *friendlist;
@ -315,11 +316,8 @@ int m_set_statusmessage(uint8_t *status, uint16_t length)
{ {
if (length > MAX_STATUSMESSAGE_LENGTH) if (length > MAX_STATUSMESSAGE_LENGTH)
return -1; return -1;
uint8_t *newstatus = calloc(length, 1); memcpy(self_statusmessage, status, length);
memcpy(newstatus, status, length); self_statusmessage_length = length;
free(self_statusmessage);
self_statusmessage = newstatus;
self_statusmessage_len = length;
uint32_t i; uint32_t i;
for (i = 0; i < numfriends; ++i) for (i = 0; i < numfriends; ++i)
@ -565,7 +563,7 @@ static void doFriends(void)
friendlist[i].name_sent = 1; friendlist[i].name_sent = 1;
} }
if (friendlist[i].statusmessage_sent == 0) { if (friendlist[i].statusmessage_sent == 0) {
if (send_statusmessage(i, self_statusmessage, self_statusmessage_len)) if (send_statusmessage(i, self_statusmessage, self_statusmessage_length))
friendlist[i].statusmessage_sent = 1; friendlist[i].statusmessage_sent = 1;
} }
if (friendlist[i].userstatus_sent == 0) { if (friendlist[i].userstatus_sent == 0) {