From f12a7fb70153815db528e9ff48088479b3313da3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jan 2017 17:48:52 +0100 Subject: [PATCH] improve comments --- src/cadet/cadet.h | 12 +++++++++--- src/cadet/cadet_common.c | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h index 049f3a85a..f3f6fb6b4 100644 --- a/src/cadet/cadet.h +++ b/src/cadet/cadet.h @@ -67,10 +67,16 @@ extern "C" #define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 0x80000000 #define GNUNET_CADET_LOCAL_CHANNEL_ID_SERV 0xB0000000 -#define HIGH_PID 0xFFFF0000 -#define LOW_PID 0x0000FFFF +#define HIGH_PID 0xFF000000 +#define LOW_PID 0x00FFFFFF -#define PID_OVERFLOW(pid, max) (pid > HIGH_PID && max < LOW_PID) +/** + * Test if the two PIDs (of type `uint32_t`) are in the range where we + * have to worry about overflows. This is the case when @a pid is + * large and @a max is small, useful when comparing @a pid smaller + * than @a max. + */ +#define PID_OVERFLOW(pid, max) (((pid) > HIGH_PID) && ((max) < LOW_PID)) /******************************************************************************/ /************************** MESSAGES ******************************/ diff --git a/src/cadet/cadet_common.c b/src/cadet/cadet_common.c index a9d9a35be..20ee7e5c9 100644 --- a/src/cadet/cadet_common.c +++ b/src/cadet/cadet_common.c @@ -51,11 +51,20 @@ GC_f2s (int fwd) } } + +/** + * Test if @a bigger is larger than @a smaller. + * Considers the case that @a bigger just overflowed + * and is thus tiny while @a smaller is still below + * `UINT32_MAX`. + */ int -GC_is_pid_bigger (uint32_t bigger, uint32_t smaller) +GC_is_pid_bigger (uint32_t bigger, + uint32_t smaller) { - return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) || - (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller))); + return (PID_OVERFLOW (smaller, bigger) || + ( (bigger > smaller) && + (! PID_OVERFLOW (bigger, smaller))) ); } -- 2.25.1