Feature #1305 ยป 0025-packets.-ch-Replace-NULL-with-nullptr.patch
common/networking/packets.c | ||
---|---|---|
#define SPECHASH_IDATA_FREE (packet_handler_hash_data_free_fn_t) free
|
||
#include "spechash.h"
|
||
static struct packet_handler_hash *packet_handlers = NULL;
|
||
static struct packet_handler_hash *packet_handlers = nullptr;
|
||
#ifdef USE_COMPRESSION
|
||
static int stat_size_alone = 0;
|
||
... | ... | |
if (-2 == level) {
|
||
const char *s = getenv("FREECIV_COMPRESSION_LEVEL");
|
||
if (NULL == s || !str_to_int(s, &level) || -1 > level || 9 < level) {
|
||
if (s == nullptr || !str_to_int(s, &level) || -1 > level || 9 < level) {
|
||
level = -1;
|
||
}
|
||
}
|
||
... | ... | |
/**********************************************************************//**
|
||
Read and return a packet from the connection 'pc'. The type of the
|
||
packet is written in 'ptype'. On error, the connection is closed and
|
||
the function returns NULL.
|
||
the function returns nullptr.
|
||
**************************************************************************/
|
||
void *get_packet_from_connection_raw(struct connection *pc,
|
||
enum packet_type *ptype)
|
||
... | ... | |
void *(*receive_handler)(struct connection *);
|
||
if (!pc->used) {
|
||
return NULL; /* connection was closed, stop reading */
|
||
return nullptr; /* Connection was closed, stop reading */
|
||
}
|
||
if (pc->buffer->ndata < data_type_size(pc->packet_header.length)) {
|
||
/* Not got enough for a length field yet */
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
dio_input_init(&din, pc->buffer->data, pc->buffer->ndata);
|
||
... | ... | |
log_compress("COMPRESS: got a jumbo packet of size %d",
|
||
whole_packet_len);
|
||
} else {
|
||
/* to return NULL below */
|
||
/* To return nullptr below */
|
||
whole_packet_len = 6;
|
||
}
|
||
} else if (len_read >= COMPRESSION_BORDER) {
|
||
... | ... | |
#endif /* USE_COMPRESSION */
|
||
if ((unsigned)whole_packet_len > pc->buffer->ndata) {
|
||
return NULL; /* not all data has been read */
|
||
return nullptr; /* Not all data has been read */
|
||
}
|
||
#ifdef USE_COMPRESSION
|
||
... | ... | |
"The connection will be closed now.");
|
||
connection_close(pc, _("illegal packet size"));
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
if (compressed_packet) {
|
||
... | ... | |
log_verbose("Uncompressing of the packet stream failed. "
|
||
"The connection will be closed now.");
|
||
connection_close(pc, _("decoding error"));
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
}
|
||
... | ... | |
log_verbose("The packet stream is corrupt. The connection "
|
||
"will be closed now.");
|
||
connection_close(pc, _("decoding error"));
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
dio_get_type_raw(&din, pc->packet_header.type, &utype.itype);
|
||
utype.type = utype.itype;
|
||
if (utype.type >= PACKET_LAST
|
||
|| (receive_handler = pc->phs.handlers->receive[utype.type]) == NULL) {
|
||
|| (receive_handler = pc->phs.handlers->receive[utype.type]) == nullptr) {
|
||
log_verbose("Received unsupported packet type %d (%s). The connection "
|
||
"will be closed now.",
|
||
utype.type, packet_name(utype.type));
|
||
connection_close(pc, _("unsupported packet type"));
|
||
return NULL;
|
||
return nullptr;
|
||
}
|
||
log_packet("got packet type=(%s)%d len=%d from %s",
|
||
... | ... | |
data = receive_handler(pc);
|
||
if (!data) {
|
||
connection_close(pc, _("incompatible packet contents"));
|
||
return NULL;
|
||
return nullptr;
|
||
} else {
|
||
return data;
|
||
}
|
||
... | ... | |
/* wrong attribute data */
|
||
if (pplayer->attribute_block_buffer.data) {
|
||
free(pplayer->attribute_block_buffer.data);
|
||
pplayer->attribute_block_buffer.data = NULL;
|
||
pplayer->attribute_block_buffer.data = nullptr;
|
||
}
|
||
pplayer->attribute_block_buffer.length = 0;
|
||
log_error("Received wrong attribute chunk");
|
||
... | ... | |
if (chunk->offset == 0) {
|
||
if (pplayer->attribute_block_buffer.data) {
|
||
free(pplayer->attribute_block_buffer.data);
|
||
pplayer->attribute_block_buffer.data = NULL;
|
||
pplayer->attribute_block_buffer.data = nullptr;
|
||
}
|
||
pplayer->attribute_block_buffer.data = fc_malloc(chunk->total_length);
|
||
pplayer->attribute_block_buffer.length = chunk->total_length;
|
||
... | ... | |
if (chunk->offset + chunk->chunk_length == chunk->total_length) {
|
||
/* Received full attribute block */
|
||
if (pplayer->attribute_block.data != NULL) {
|
||
if (pplayer->attribute_block.data != nullptr) {
|
||
free(pplayer->attribute_block.data);
|
||
}
|
||
pplayer->attribute_block.data = pplayer->attribute_block_buffer.data;
|
||
pplayer->attribute_block.length = pplayer->attribute_block_buffer.length;
|
||
pplayer->attribute_block_buffer.data = NULL;
|
||
pplayer->attribute_block_buffer.data = nullptr;
|
||
pplayer->attribute_block_buffer.length = 0;
|
||
}
|
||
}
|
||
... | ... | |
**************************************************************************/
|
||
static void packet_handlers_free(void)
|
||
{
|
||
if (packet_handlers != NULL) {
|
||
if (packet_handlers != nullptr) {
|
||
packet_handler_hash_destroy(packet_handlers);
|
||
packet_handlers = NULL;
|
||
packet_handlers = nullptr;
|
||
}
|
||
}
|
||
... | ... | |
free_tokens(tokens, tokens_num);
|
||
/* Ensure the hash table is created. */
|
||
if (packet_handlers == NULL) {
|
||
if (packet_handlers == nullptr) {
|
||
packet_handlers = packet_handler_hash_new();
|
||
}
|
||
... | ... | |
phandlers);
|
||
}
|
||
fc_assert(phandlers != NULL);
|
||
fc_assert(phandlers != nullptr);
|
||
return phandlers;
|
||
}
|
common/networking/packets.h | ||
---|---|---|
#define web_lsend_packet(packetname, pconn, pack, ...) \
|
||
do { \
|
||
const struct packet_web_ ##packetname *_pptr_ = pack; \
|
||
if (_pptr_ != NULL) { \
|
||
if (_pptr_ != nullptr) { \
|
||
lsend_packet_web_ ##packetname(pconn, _pptr_, ##__VA_ARGS__ ); \
|
||
} \
|
||
} while (FALSE);
|
||
... | ... | |
#define RECEIVE_PACKET_END(result) \
|
||
if (!packet_check(&din, pc)) { \
|
||
FREE_PACKET_STRUCT(&packet_buf); \
|
||
return NULL; \
|
||
return nullptr; \
|
||
} \
|
||
remove_packet_from_buffer(pc->buffer); \
|
||
result = fc_malloc(sizeof(*result)); \
|
||
... | ... | |
#define RECEIVE_PACKET_FIELD_ERROR(field, ...) \
|
||
log_packet("Error on field '" #field "'" __VA_ARGS__); \
|
||
FREE_PACKET_STRUCT(&packet_buf); \
|
||
return NULL
|
||
return nullptr;
|
||
#endif /* FREECIV_JSON_PROTOCOL */
|
||