From 7fa0c89c96bdaf45bf202d770aa56dc7c68959b9 Mon Sep 17 00:00:00 2001 From: hqwrong Date: Mon, 2 Apr 2018 21:21:28 +0800 Subject: [PATCH] add comment to func cryptpacket_received --- toxcore/net_crypto.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 65c81d92..2e8299f1 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2755,6 +2755,13 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t * * return -1 on failure. * return 0 on success. + * + * Note: The condition `buffer_end - buffer_start < packet_number - buffer_start` is + * a trick which handles situations `buffer_end >= buffer_start` and + * `buffer_end < buffer_start`(when buffer_end overflowed) both correctly + * + * It CANNOT be simplified to `packet_number < buffer_start`, as it will fail + * when `buffer_end < buffer_start`. */ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet_number) {