summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-08-22 15:51:07 -0400
committerirungentoo <irungentoo@gmail.com>2014-08-22 15:51:07 -0400
commit43723f29707fa531f4db00c938c8b84f734df349 (patch)
tree360bda48521c4c74f0e28a875f6f0f34a4b1e981
parent6408c7de50abf86f6802866fb0977fb3b3e413ae (diff)
Small code cleanup.
-rw-r--r--toxcore/Messenger.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 5dea7b08..fd7527e4 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -388,14 +388,14 @@ uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, const uint8_t *messag
388uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *message, 388uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *message,
389 uint32_t length) 389 uint32_t length)
390{ 390{
391 if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid))) 391 if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid)) || length == 0)
392 return 0; 392 return 0;
393 393
394 uint8_t temp[MAX_CRYPTO_DATA_SIZE]; 394 uint8_t temp[sizeof(theid) + length];
395 theid = htonl(theid); 395 theid = htonl(theid);
396 memcpy(temp, &theid, sizeof(theid)); 396 memcpy(temp, &theid, sizeof(theid));
397 memcpy(temp + sizeof(theid), message, length); 397 memcpy(temp + sizeof(theid), message, length);
398 return write_cryptpacket_id(m, friendnumber, PACKET_ID_MESSAGE, temp, length + sizeof(theid)); 398 return write_cryptpacket_id(m, friendnumber, PACKET_ID_MESSAGE, temp, sizeof(temp));
399} 399}
400 400
401/* Send an action to an online friend. 401/* Send an action to an online friend.
@@ -423,14 +423,14 @@ uint32_t m_sendaction(Messenger *m, int32_t friendnumber, const uint8_t *action,
423uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *action, 423uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *action,
424 uint32_t length) 424 uint32_t length)
425{ 425{
426 if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid))) 426 if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid)) || length == 0)
427 return 0; 427 return 0;
428 428
429 uint8_t temp[MAX_CRYPTO_DATA_SIZE]; 429 uint8_t temp[sizeof(theid) + length];
430 theid = htonl(theid); 430 theid = htonl(theid);
431 memcpy(temp, &theid, sizeof(theid)); 431 memcpy(temp, &theid, sizeof(theid));
432 memcpy(temp + sizeof(theid), action, length); 432 memcpy(temp + sizeof(theid), action, length);
433 return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, temp, length + sizeof(theid)); 433 return write_cryptpacket_id(m, friendnumber, PACKET_ID_ACTION, temp, sizeof(temp));
434} 434}
435 435
436/* Send a name packet to friendnumber. 436/* Send a name packet to friendnumber.