Skip to content

Commit

Permalink
Merge pull request #37 from dosbox-staging/dosbox-staging/cleanup-1
Browse files Browse the repository at this point in the history
Cleanup static analysis issues
  • Loading branch information
inlife committed Jul 29, 2022
2 parents 0bbff4d + a1a909b commit fcbc330
Showing 1 changed file with 30 additions and 47 deletions.
77 changes: 30 additions & 47 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 @@ -2217,18 +2218,17 @@ extern "C" {
if (peer->state != ENET_PEER_STATE_CONNECTED && peer->state != ENET_PEER_STATE_DISCONNECT_LATER) {
return -1;
}

if (peer->incomingBandwidth != 0) {
--host->bandwidthLimitedPeers;
}

peer->incomingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.incomingBandwidth);
peer->outgoingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.outgoingBandwidth);

if (peer->incomingBandwidth != 0) {
++host->bandwidthLimitedPeers;
}

peer->outgoingBandwidth = ENET_NET_TO_HOST_32(command->bandwidthLimit.outgoingBandwidth);

if (peer->incomingBandwidth == 0 && host->outgoingBandwidth == 0) {
peer->windowSize = ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE;
} else if (peer->incomingBandwidth == 0 || host->outgoingBandwidth == 0) {
Expand Down Expand Up @@ -2641,7 +2641,8 @@ extern "C" {
goto commandError;
}

if (peer != NULL && (command->header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0) {
assert(peer);
if ((command->header.command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0) {
enet_uint16 sentTime;

if (!(flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME)) {
Expand Down Expand Up @@ -3133,12 +3134,12 @@ extern "C" {
currentPeer->packetsLost = 0;
}

host->buffers->data = headerData;
host->buffers[0].data = headerData;
if (host->headerFlags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) {
header->sentTime = ENET_HOST_TO_NET_16(host->serviceTime & 0xFFFF);
host->buffers->dataLength = sizeof(ENetProtocolHeader);
host->buffers[0].dataLength = sizeof(ENetProtocolHeader);
} else {
host->buffers->dataLength = (size_t) &((ENetProtocolHeader *) 0)->sentTime;
host->buffers[0].dataLength = (size_t) &((ENetProtocolHeader *) 0)->sentTime;
}

shouldCompress = 0;
Expand All @@ -3159,9 +3160,9 @@ extern "C" {
}
header->peerID = ENET_HOST_TO_NET_16(currentPeer->outgoingPeerID | host->headerFlags);
if (host->checksum != NULL) {
enet_uint32 *checksum = (enet_uint32 *) &headerData[host->buffers->dataLength];
enet_uint32 *checksum = (enet_uint32 *) &headerData[host->buffers[0].dataLength];
*checksum = currentPeer->outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID ? currentPeer->connectID : 0;
host->buffers->dataLength += sizeof(enet_uint32);
host->buffers[0].dataLength += sizeof(enet_uint32);
*checksum = host->checksum(host->buffers, host->bufferCount);
}

Expand All @@ -3176,6 +3177,9 @@ extern "C" {
enet_protocol_remove_sent_unreliable_commands(currentPeer);

if (sentLength < 0) {
// The local 'headerData' array (to which 'data' is assigned) goes out
// of scope on return from this function, so ensure we no longer point to it.
host->buffers[0].data = NULL;
return -1;
}

Expand All @@ -3184,6 +3188,10 @@ extern "C" {
host->totalSentPackets++;
}

// The local 'headerData' array (to which 'data' is assigned) goes out
// of scope on return from this function, so ensure we no longer point to it.
host->buffers[0].data = NULL;

return 0;
} /* enet_protocol_send_outgoing_commands */

Expand Down Expand Up @@ -4329,10 +4337,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 @@ -4354,7 +4361,8 @@ extern "C" {
goto notifyError;
}

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

Expand Down Expand Up @@ -4437,11 +4445,9 @@ 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;
host->randomSeed = (enet_uint32) ((uintptr_t) host % UINT32_MAX);
host->randomSeed += enet_host_random_seed();
host->randomSeed = (host->randomSeed << 16) | (host->randomSeed >> 16);
host->channelLimit = channelLimit;
Expand Down Expand Up @@ -4690,10 +4696,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 Expand Up @@ -5043,10 +5046,7 @@ extern "C" {
}

if (getaddrinfo(name, NULL, &hints, &resultList) != 0) {
if (resultList != NULL) {
freeaddrinfo(resultList);
}

freeaddrinfo(resultList);
return -1;
}

Expand All @@ -5055,29 +5055,18 @@ extern "C" {
if (result->ai_family == AF_INET || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in))) {
enet_inaddr_map4to6(((struct sockaddr_in*)result->ai_addr)->sin_addr, &out->host);
out->sin6_scope_id = 0;

if (resultList != NULL) {
freeaddrinfo(resultList);
}

freeaddrinfo(resultList);
return 0;

} else if (result->ai_family == AF_INET6 || (result->ai_family == AF_UNSPEC && result->ai_addrlen == sizeof(struct sockaddr_in6))) {
memcpy(&out->host, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, sizeof(struct in6_addr));
out->sin6_scope_id = (enet_uint16) ((struct sockaddr_in6*)result->ai_addr)->sin6_scope_id;

if (resultList != NULL) {
freeaddrinfo(resultList);
}

freeaddrinfo(resultList);
return 0;
}
}
}

if (resultList != NULL) {
freeaddrinfo(resultList);
}

freeaddrinfo(resultList);
return -1;
}

Expand Down Expand Up @@ -5362,7 +5351,6 @@ extern "C" {
((uint32_t *)&address->host.s6_addr)[3] = sin->sin_addr.s_addr;

freeaddrinfo(resultList);

return 0;
}
else if(result->ai_family == AF_INET6) {
Expand All @@ -5372,16 +5360,11 @@ extern "C" {
address->sin6_scope_id = sin->sin6_scope_id;

freeaddrinfo(resultList);

return 0;
}
}
}


if (resultList != NULL) {
freeaddrinfo(resultList);
}
freeaddrinfo(resultList);

return enet_address_set_host_ip(address, name);
} /* enet_address_set_host_old */
Expand Down Expand Up @@ -5453,7 +5436,7 @@ extern "C" {
}

ENetSocket enet_socket_create(ENetSocketType type) {
return socket(PF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
return socket(PF_INET6, (int)type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
}

int enet_socket_set_option(ENetSocket socket, ENetSocketOption option, int value) {
Expand Down

0 comments on commit fcbc330

Please sign in to comment.