Project

General

Profile

Feature #1339 ยป 0035-packets_json.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 05/02/2025 12:22 AM

View differences:

common/networking/packets_json.c
/**********************************************************************//**
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_json(struct connection *pc,
enum packet_type *ptype)
......
json_t *pint;
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 enough for a length field yet */
return NULL;
return nullptr;
}
dio_input_init(&din, pc->buffer->data, pc->buffer->ndata);
......
whole_packet_len = len_read;
if ((unsigned)whole_packet_len > pc->buffer->ndata) {
return NULL; /* Not all data has been read */
return nullptr; /* Not all data has been read */
}
/*
......
"will be closed now.");
connection_close(pc, _("decoding error"));
return NULL;
return nullptr;
}
/*
......
whole_packet_len - 3, 0, &error);
/* Set the connection mode */
pc->json_mode = (pc->json_packet != NULL);
pc->json_mode = (pc->json_packet != nullptr);
}
if (pc->json_mode) {
......
pc->buffer->ndata);
if (!pc->json_packet) {
return NULL;
return nullptr;
}
pint = json_object_get(pc->json_packet, "pid");
if (!pint) {
log_error("ERROR: Unable to get packet type.");
return NULL;
return nullptr;
}
utype.type = json_integer_value(pint);
......
}
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) len=%d from %s",
......
data = receive_handler(pc);
if (!data) {
connection_close(pc, _("incompatible packet contents"));
return NULL;
return nullptr;
} else {
return data;
}
common/networking/packets_json.h
#define SEND_PACKET_START(packet_type) \
unsigned char buffer[MAX_LEN_PACKET * 5]; \
struct plocation *pid_addr; \
char *json_buffer = NULL; \
char *json_buffer = nullptr; \
struct json_data_out dout; \
dio_output_init(&(dout.raw), buffer, sizeof(buffer)); \
if (pc->json_mode) { \
......
dio_put_uint8_json(&dout, pid_addr, packet_type); \
FC_FREE(pid_addr); \
} else { \
dout.json = NULL; \
dout.json = nullptr; \
dio_put_type_raw(&dout.raw, pc->packet_header.length, 0); \
dio_put_type_raw(&dout.raw, pc->packet_header.type, packet_type); \
}
......
} else { \
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;
/* Utilities to move string vectors in and out of packets. */
#define PACKET_STRVEC_INSERT(dest, src) \
    (1-1/1)