Skip to content

Commit

Permalink
Remove the unecessary lower-bound channel limit checks
Browse files Browse the repository at this point in the history
This commit removes the channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT
checks because they're always false (and aren't needed to ensure the
channel limit is within-bounds).

Here's why:

1. channelLimit is unsigned, so it's always zero or greater.

2. The 'if' branch already handles the case where channelLimit is zero,
   which is an alias for the maximum limit (per the API description).

3. Therefore, the else branch is only called when channelLimit is between
   1 and ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, inclusively.  These
   bounds are perfectly valid, so the else condition is always false and
   isn't needed.
  • Loading branch information
kcgen committed Jul 28, 2022
1 parent 0bbff4d commit 2af0663
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions include/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4437,8 +4437,6 @@ extern "C" {

if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
} else if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
}

host->randomSeed = (enet_uint32) (size_t) host;
Expand Down Expand Up @@ -4690,10 +4688,7 @@ extern "C" {
void enet_host_channel_limit(ENetHost *host, size_t channelLimit) {
if (!channelLimit || channelLimit > ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT;
} else if (channelLimit < ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT) {
channelLimit = ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT;
}

host->channelLimit = channelLimit;
}

Expand Down

0 comments on commit 2af0663

Please sign in to comment.