Constified numerous function parameters.

As was pointed out by the cppcheck[0] static code analysis utility we
can mark numerous function parameters as 'const'. This acts as a hint to
the compiler about our intentions and the compiler will tell us when we
deviate from them.

[0]: https://cppcheck.sourceforge.io/
This commit is contained in:
Andrew Clayton
2022-06-16 02:00:52 +01:00
committed by Alejandro Colomar
parent 637a2006a6
commit 4418f99cd4
13 changed files with 43 additions and 41 deletions

View File

@@ -102,7 +102,7 @@ typedef struct {
static nxt_int_t nxt_conf_path_next_token(nxt_conf_path_parse_t *parse,
nxt_str_t *token);
static u_char *nxt_conf_json_skip_space(u_char *start, u_char *end);
static u_char *nxt_conf_json_skip_space(u_char *start, const u_char *end);
static u_char *nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value,
u_char *start, u_char *end, nxt_conf_json_error_t *error);
static u_char *nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value,
@@ -266,7 +266,7 @@ nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count)
void
nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name,
nxt_conf_value_t *value, uint32_t index)
const nxt_conf_value_t *value, uint32_t index)
{
nxt_conf_object_member_t *member;
@@ -367,7 +367,7 @@ nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count)
void
nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index,
nxt_conf_value_t *value)
const nxt_conf_value_t *value)
{
array->u.array->elements[index] = *value;
}
@@ -1271,7 +1271,7 @@ nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end,
static u_char *
nxt_conf_json_skip_space(u_char *start, u_char *end)
nxt_conf_json_skip_space(u_char *start, const u_char *end)
{
u_char *p, ch;
@@ -2605,7 +2605,7 @@ nxt_conf_json_escape(u_char *dst, u_char *src, size_t size)
void
nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line,
nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line,
nxt_uint_t *column)
{
u_char *p;

View File

@@ -109,7 +109,7 @@ size_t nxt_conf_json_length(nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty);
u_char *nxt_conf_json_print(u_char *p, nxt_conf_value_t *value,
nxt_conf_json_pretty_t *pretty);
void nxt_conf_json_position(u_char *start, u_char *pos, nxt_uint_t *line,
void nxt_conf_json_position(u_char *start, const u_char *pos, nxt_uint_t *line,
nxt_uint_t *column);
nxt_int_t nxt_conf_validate(nxt_conf_validation_t *vldt);
@@ -125,7 +125,7 @@ NXT_EXPORT uint8_t nxt_conf_get_boolean(nxt_conf_value_t *value);
NXT_EXPORT nxt_uint_t nxt_conf_object_members_count(nxt_conf_value_t *value);
nxt_conf_value_t *nxt_conf_create_object(nxt_mp_t *mp, nxt_uint_t count);
void nxt_conf_set_member(nxt_conf_value_t *object, nxt_str_t *name,
nxt_conf_value_t *value, uint32_t index);
const nxt_conf_value_t *value, uint32_t index);
void nxt_conf_set_member_string(nxt_conf_value_t *object, nxt_str_t *name,
nxt_str_t *value, uint32_t index);
nxt_int_t nxt_conf_set_member_string_dup(nxt_conf_value_t *object, nxt_mp_t *mp,
@@ -137,7 +137,7 @@ void nxt_conf_set_member_null(nxt_conf_value_t *object, nxt_str_t *name,
nxt_conf_value_t *nxt_conf_create_array(nxt_mp_t *mp, nxt_uint_t count);
void nxt_conf_set_element(nxt_conf_value_t *array, nxt_uint_t index,
nxt_conf_value_t *value);
const nxt_conf_value_t *value);
nxt_int_t nxt_conf_set_element_string_dup(nxt_conf_value_t *array, nxt_mp_t *mp,
nxt_uint_t index, nxt_str_t *value);
NXT_EXPORT nxt_uint_t nxt_conf_array_elements_count(nxt_conf_value_t *value);

View File

@@ -376,8 +376,9 @@ nxt_int_t nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_http_action_t *action, nxt_http_action_conf_t *acf);
nxt_int_t nxt_http_static_mtypes_init(nxt_mp_t *mp, nxt_lvlhsh_t *hash);
nxt_int_t nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash,
nxt_str_t *exten, nxt_str_t *type);
nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten);
const nxt_str_t *exten, nxt_str_t *type);
nxt_str_t *nxt_http_static_mtype_get(nxt_lvlhsh_t *hash,
const nxt_str_t *exten);
nxt_http_action_t *nxt_http_application_handler(nxt_task_t *task,
nxt_http_request_t *r, nxt_http_action_t *action);

View File

@@ -8,16 +8,16 @@
static nxt_int_t nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
u_char **pos, const u_char *end);
static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
u_char **pos, const u_char *end);
static nxt_int_t nxt_http_parse_field_name(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
u_char **pos, const u_char *end);
static nxt_int_t nxt_http_parse_field_value(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
static u_char *nxt_http_lookup_field_end(u_char *p, u_char *end);
u_char **pos, const u_char *end);
static u_char *nxt_http_lookup_field_end(u_char *p, const u_char *end);
static nxt_int_t nxt_http_parse_field_end(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
u_char **pos, const u_char *end);
static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp);
@@ -62,7 +62,7 @@ static const uint8_t nxt_http_target_chars[256] nxt_aligned(64) = {
nxt_inline nxt_http_target_traps_e
nxt_http_parse_target(u_char **pos, u_char *end)
nxt_http_parse_target(u_char **pos, const u_char *end)
{
u_char *p;
nxt_uint_t trap;
@@ -158,7 +158,7 @@ nxt_http_parse_fields(nxt_http_request_parse_t *rp, nxt_buf_mem_t *b)
static nxt_int_t
nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
const u_char *end)
{
u_char *p, ch, *after_slash, *args;
nxt_int_t rc;
@@ -479,7 +479,7 @@ space_after_target:
static nxt_int_t
nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
const u_char *end)
{
u_char *p, ch;
@@ -517,7 +517,7 @@ nxt_http_parse_unusual_target(nxt_http_request_parse_t *rp, u_char **pos,
static nxt_int_t
nxt_http_parse_field_name(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
const u_char *end)
{
u_char *p, c;
size_t len;
@@ -624,7 +624,7 @@ name_end:
static nxt_int_t
nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
const u_char *end)
{
u_char *p, *start, ch;
size_t len;
@@ -704,7 +704,7 @@ nxt_http_parse_field_value(nxt_http_request_parse_t *rp, u_char **pos,
static u_char *
nxt_http_lookup_field_end(u_char *p, u_char *end)
nxt_http_lookup_field_end(u_char *p, const u_char *end)
{
while (nxt_fast_path(end - p >= 16)) {
@@ -771,7 +771,7 @@ nxt_http_lookup_field_end(u_char *p, u_char *end)
static nxt_int_t
nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
u_char *end)
const u_char *end)
{
u_char *p;
nxt_http_field_t *field;

View File

@@ -35,7 +35,7 @@ typedef union {
struct nxt_http_request_parse_s {
nxt_int_t (*handler)(nxt_http_request_parse_t *rp,
u_char **pos, u_char *end);
u_char **pos, const u_char *end);
nxt_str_t method;

View File

@@ -30,11 +30,11 @@ static u_char *nxt_http_date_cache_handler(u_char *buf, nxt_realtime_t *now,
static nxt_http_name_value_t *nxt_http_argument(nxt_array_t *array,
u_char *name, size_t name_length, uint32_t hash, u_char *start,
u_char *end);
const u_char *end);
static nxt_int_t nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start,
u_char *end);
const u_char *end);
static nxt_http_name_value_t *nxt_http_cookie(nxt_array_t *array, u_char *name,
size_t name_length, u_char *start, u_char *end);
size_t name_length, u_char *start, const u_char *end);
#define NXT_HTTP_COOKIE_HASH \
@@ -949,7 +949,7 @@ nxt_http_arguments_parse(nxt_http_request_t *r)
static nxt_http_name_value_t *
nxt_http_argument(nxt_array_t *array, u_char *name, size_t name_length,
uint32_t hash, u_char *start, u_char *end)
uint32_t hash, u_char *start, const u_char *end)
{
size_t length;
nxt_http_name_value_t *nv;
@@ -1018,7 +1018,7 @@ nxt_http_cookies_parse(nxt_http_request_t *r)
static nxt_int_t
nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end)
nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, const u_char *end)
{
size_t name_length;
u_char c, *p, *name;
@@ -1067,7 +1067,7 @@ nxt_http_cookie_parse(nxt_array_t *cookies, u_char *start, u_char *end)
static nxt_http_name_value_t *
nxt_http_cookie(nxt_array_t *array, u_char *name, size_t name_length,
u_char *start, u_char *end)
u_char *start, const u_char *end)
{
u_char c, *p;
uint32_t hash;

View File

@@ -1024,7 +1024,7 @@ typedef struct {
nxt_int_t
nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash,
nxt_str_t *exten, nxt_str_t *type)
const nxt_str_t *exten, nxt_str_t *type)
{
nxt_lvlhsh_query_t lhq;
nxt_http_static_mtype_t *mtype;
@@ -1049,7 +1049,7 @@ nxt_http_static_mtypes_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *hash,
nxt_str_t *
nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, nxt_str_t *exten)
nxt_http_static_mtype_get(nxt_lvlhsh_t *hash, const nxt_str_t *exten)
{
nxt_lvlhsh_query_t lhq;
nxt_http_static_mtype_t *mtype;

View File

@@ -155,7 +155,7 @@ static void *nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size,
nxt_bool_t freeable);
static intptr_t nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1,
nxt_rbtree_node_t *node2);
static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p);
static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p);
static const char *nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster,
u_char *p);
@@ -830,7 +830,7 @@ nxt_mp_free(nxt_mp_t *mp, void *p)
static nxt_mp_block_t *
nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p)
nxt_mp_find_block(nxt_rbtree_t *tree, const u_char *p)
{
nxt_mp_block_t *block;
nxt_rbtree_node_t *node, *sentinel;

View File

@@ -100,7 +100,7 @@ nxt_inline void
nxt_port_mmap_set_chunk_free(nxt_free_map_t *m, nxt_chunk_id_t c);
nxt_inline nxt_chunk_id_t
nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, u_char *p)
nxt_port_mmap_chunk_id(nxt_port_mmap_header_t *hdr, const u_char *p)
{
u_char *mm_start;

View File

@@ -19,7 +19,7 @@ static uint8_t nxt_port_enqueue_buf(nxt_task_t *task, nxt_port_msg_t *pm,
void *qbuf, nxt_buf_t *b);
static nxt_int_t nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port,
nxt_port_send_msg_t *msg);
static nxt_port_send_msg_t *nxt_port_msg_alloc(nxt_port_send_msg_t *m);
static nxt_port_send_msg_t *nxt_port_msg_alloc(const nxt_port_send_msg_t *m);
static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data);
static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port);
nxt_inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg);
@@ -332,7 +332,7 @@ nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port,
static nxt_port_send_msg_t *
nxt_port_msg_alloc(nxt_port_send_msg_t *m)
nxt_port_msg_alloc(const nxt_port_send_msg_t *m)
{
nxt_port_send_msg_t *msg;

View File

@@ -338,7 +338,7 @@ nxt_rmemstrn(const u_char *s, const u_char *end, const char *ss, size_t length)
size_t
nxt_str_strip(u_char *start, u_char *end)
nxt_str_strip(const u_char *start, u_char *end)
{
u_char *p;

View File

@@ -96,7 +96,7 @@ NXT_EXPORT u_char *nxt_memcasestrn(const u_char *s, const u_char *end,
const char *ss, size_t length);
NXT_EXPORT u_char *nxt_rmemstrn(const u_char *s, const u_char *end,
const char *ss, size_t length);
NXT_EXPORT size_t nxt_str_strip(u_char *start, u_char *end);
NXT_EXPORT size_t nxt_str_strip(const u_char *start, u_char *end);
typedef struct {

View File

@@ -196,7 +196,8 @@ static int nxt_unit_request_hash_add(nxt_unit_ctx_t *ctx,
static nxt_unit_request_info_t *nxt_unit_request_hash_find(
nxt_unit_ctx_t *ctx, uint32_t stream, int remove);
static char * nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level);
static char * nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid,
int level);
static void *nxt_unit_lvlhsh_alloc(void *data, size_t size);
static void nxt_unit_lvlhsh_free(void *data, void *p);
static int nxt_unit_memcasecmp(const void *p1, const void *p2, size_t length);
@@ -6666,7 +6667,7 @@ static const char * nxt_unit_log_levels[] = {
static char *
nxt_unit_snprint_prefix(char *p, char *end, pid_t pid, int level)
nxt_unit_snprint_prefix(char *p, const char *end, pid_t pid, int level)
{
struct tm tm;
struct timespec ts;