Skip to content

Commit

Permalink
Eliminate an always-true pointer check
Browse files Browse the repository at this point in the history
'packet' is already guaranteed to be not NULL because prior in the
function we check: if (packet == NULL) {  goto notifyError; }.

So we replace these checks with an assertion, because it's what
we expect given the current state of the code.
  • Loading branch information
kcgen committed Jul 28, 2022
1 parent 608b68e commit d3fa74f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions include/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifndef ENET_INCLUDE_H
#define ENET_INCLUDE_H

#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -4328,10 +4329,9 @@ extern "C" {
memset(incomingCommand->fragments, 0, (fragmentCount + 31) / 32 * sizeof(enet_uint32));
}

if (packet != NULL) {
++packet->referenceCount;
peer->totalWaitingData += packet->dataLength;
}
assert(packet != NULL);
++packet->referenceCount;
peer->totalWaitingData += packet->dataLength;

enet_list_insert(enet_list_next(currentCommand), incomingCommand);

Expand All @@ -4353,7 +4353,8 @@ extern "C" {
goto notifyError;
}

if (packet != NULL && packet->referenceCount == 0) {
assert(packet != NULL);
if (packet->referenceCount == 0) {
callbacks.packet_destroy(packet);
}

Expand Down

0 comments on commit d3fa74f

Please sign in to comment.