diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 17:22:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-12 20:21:42 +0000 |
commit | beeb9b4335d9ca6f947a52528453753a51f194f3 (patch) | |
tree | 242cad42e2e90ebf5ed04283fd79f42f4e3afa60 /toxcore/Messenger.c | |
parent | cbda01021c561bd061cb03a1c1bab58199ac2307 (diff) |
Style fixes in TCP code; remove MIN and PAIR from util.h.
* Moved PAIR to toxav, where it's used (but really this should die).
* Replace most MIN calls with typed `min_*` calls. Didn't replace the
ones where the desired semantics are unclear. Moved the MIN macro to
the one place where it's still used.
* Avoid assignments in `while` loops. Instead, factored out the loop body
into a separate `bool`-returning function.
* Use named types for callbacks (`_cb` types).
* Avoid assignments in `if` conditions.
* Removed `MAKE_REALLOC` and expanded its two calls. We can't have
templates in C, and this fake templating is ugly and hard to analyse
and debug (it expands on a single line).
* Moved epoll system include to the .c file, out of the .h file.
* Avoid assignments in expressions (`a = b = c;`).
* Avoid multiple declarators per struct member declaration.
* Fix naming inconsistencies.
* Replace `net_to_host` macro with function.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index a5d15a34..416b937c 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -717,7 +717,9 @@ int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, | |||
717 | return -1; | 717 | return -1; |
718 | } | 718 | } |
719 | 719 | ||
720 | int msglen = MIN(maxlen, m->friendlist[friendnumber].statusmessage_length); | 720 | // TODO(iphydf): This should be uint16_t and min_u16. If maxlen exceeds |
721 | // uint16_t's range, it won't affect the result. | ||
722 | uint32_t msglen = min_u32(maxlen, m->friendlist[friendnumber].statusmessage_length); | ||
721 | 723 | ||
722 | memcpy(buf, m->friendlist[friendnumber].statusmessage, msglen); | 724 | memcpy(buf, m->friendlist[friendnumber].statusmessage, msglen); |
723 | memset(buf + msglen, 0, maxlen - msglen); | 725 | memset(buf + msglen, 0, maxlen - msglen); |
@@ -2855,9 +2857,10 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data) | |||
2855 | memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE); | 2857 | memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE); |
2856 | 2858 | ||
2857 | if (temp.status < 3) { | 2859 | if (temp.status < 3) { |
2860 | // TODO(iphydf): Use uint16_t and min_u16 here. | ||
2858 | const size_t friendrequest_length = | 2861 | const size_t friendrequest_length = |
2859 | MIN(m->friendlist[i].info_size, | 2862 | min_u32(m->friendlist[i].info_size, |
2860 | MIN(SAVED_FRIEND_REQUEST_SIZE, MAX_FRIEND_REQUEST_DATA_SIZE)); | 2863 | min_u32(SAVED_FRIEND_REQUEST_SIZE, MAX_FRIEND_REQUEST_DATA_SIZE)); |
2861 | memcpy(temp.info, m->friendlist[i].info, friendrequest_length); | 2864 | memcpy(temp.info, m->friendlist[i].info, friendrequest_length); |
2862 | 2865 | ||
2863 | temp.info_size = net_htons(m->friendlist[i].info_size); | 2866 | temp.info_size = net_htons(m->friendlist[i].info_size); |