summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-03-15 05:41:50 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-03-26 07:33:41 -0400
commit19bc88850e714a46ec68c779f4914bb5a0c71bd0 (patch)
tree4e5dca2a7d2617f469d85ffed60b7e93733ce8ae
parentfe4310cc61a44d51f451bfdad16b1db7f6769fd4 (diff)
downloadlighttpd-git-19bc88850e714a46ec68c779f4914bb5a0c71bd0.tar.gz
[multiple] add attrs from gcc -Wsuggest-attribute=
-rw-r--r--src/algo_hmac.c2
-rw-r--r--src/buffer.h4
-rw-r--r--src/configfile.c3
-rw-r--r--src/connections.c1
-rw-r--r--src/fdevent.h3
-rw-r--r--src/fdevent_poll.c1
-rw-r--r--src/first.h22
-rw-r--r--src/gw_backend.c1
-rw-r--r--src/gw_backend.h1
-rw-r--r--src/http_auth.c1
-rw-r--r--src/http_auth.h5
-rw-r--r--src/http_kv.h10
-rw-r--r--src/http_vhostdb.h1
-rw-r--r--src/keyvalue.h1
-rw-r--r--src/log.c2
-rw-r--r--src/mod_authn_pam.c3
-rw-r--r--src/mod_extforward.c3
-rw-r--r--src/mod_ssi.c1
-rw-r--r--src/mod_ssi_expr.c2
-rw-r--r--src/mod_uploadprogress.c5
-rw-r--r--src/network_write.h1
-rw-r--r--src/plugin_config.h2
-rw-r--r--src/request.c2
-rw-r--r--src/stat_cache.h2
-rw-r--r--src/vector.h3
25 files changed, 77 insertions, 5 deletions
diff --git a/src/algo_hmac.c b/src/algo_hmac.c
index 54262e4a..87552c2a 100644
--- a/src/algo_hmac.c
+++ b/src/algo_hmac.c
@@ -31,6 +31,7 @@
#endif
#endif
+#ifndef USE_NETTLE_CRYPTO
#if defined(USE_OPENSSL_CRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
#define HMAC EVP_HMAC
static unsigned char *
@@ -56,6 +57,7 @@ EVP_HMAC (const EVP_MD *evp_md, const void *key,
return (1 == rc) ? md : NULL;
}
#endif
+#endif
int
diff --git a/src/buffer.h b/src/buffer.h
index f0e94b16..7743b989 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -173,7 +173,10 @@ void buffer_append_string_encoded(buffer * restrict b, const char * restrict s,
void buffer_append_string_c_escaped(buffer * restrict b, const char * restrict s, size_t s_len);
void buffer_urldecode_path(buffer *b);
+
+__attribute_pure__
int buffer_is_valid_UTF8(const buffer *b);
+
void buffer_path_simplify(buffer *dest, buffer *src);
void buffer_to_lower(buffer *b);
@@ -181,6 +184,7 @@ void buffer_to_upper(buffer *b);
/** deprecated */
+__attribute_const__
char hex2int(unsigned char c);
__attribute_pure__
diff --git a/src/configfile.c b/src/configfile.c
index 171deb01..e36cc488 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -309,7 +309,8 @@ static void config_check_module_duplicates (server *srv) {
srv->srvconf.modules = modules;
}
-static const char * config_has_opt_and_value (server * const srv, const char * const opt, const uint32_t olen, const char * const v, const uint32_t vlen) {
+__attribute_pure__
+static const char * config_has_opt_and_value (const server * const srv, const char * const opt, const uint32_t olen, const char * const v, const uint32_t vlen) {
for (uint32_t i = 0; i < srv->config_context->used; ++i) {
const data_config * const config =
(data_config const *)srv->config_context->data[i];
diff --git a/src/connections.c b/src/connections.c
index ec45fad8..ea40f7dc 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -1695,6 +1695,7 @@ connection_handle_read_post_cq_compact (chunkqueue * const cq)
}
+__attribute_pure__
static int
connection_handle_read_post_chunked_crlf (chunkqueue * const cq)
{
diff --git a/src/fdevent.h b/src/fdevent.h
index ca5c1af6..ac2ecc76 100644
--- a/src/fdevent.h
+++ b/src/fdevent.h
@@ -50,6 +50,7 @@ __attribute_cold__
int fdevent_config(const char **event_handler_name, struct log_error_st *errh);
__attribute_cold__
+__attribute_const__
const char * fdevent_show_event_handlers(void);
__attribute_cold__
@@ -88,7 +89,9 @@ int fdevent_rename(const char *oldpath, const char *newpath);
struct sockaddr;
int fdevent_accept_listenfd(int listenfd, struct sockaddr *addr, size_t *addrlen);
+__attribute_pure__
char ** fdevent_environ(void);
+
int fdevent_open_devnull(void);
int fdevent_open_dirname(char *path, int symlinks);
int fdevent_set_stdin_stdout_stderr(int fdin, int fdout, int fderr);
diff --git a/src/fdevent_poll.c b/src/fdevent_poll.c
index 25803b7d..4860a662 100644
--- a/src/fdevent_poll.c
+++ b/src/fdevent_poll.c
@@ -77,6 +77,7 @@ static int fdevent_poll_event_set(fdevents *ev, fdnode *fdn, int events) {
return 0;
}
+__attribute_pure__
static int fdevent_poll_next_ndx(const fdevents *ev, int ndx) {
for (uint32_t i = (uint32_t)(ndx+1); i < ev->used; ++i) {
if (ev->pollfds[i].revents) return i;
diff --git a/src/first.h b/src/first.h
index dd095f8a..d3431a21 100644
--- a/src/first.h
+++ b/src/first.h
@@ -140,6 +140,15 @@
#endif
#endif
+#ifndef __attribute_const__
+#if __has_attribute(const) \
+ || __GNUC_PREREQ(2,5)
+#define __attribute_const__ __attribute__((__const__))
+#else
+#define __attribute_const__
+#endif
+#endif
+
#ifndef __attribute_pure__
#if __has_attribute(pure) \
|| __GNUC_PREREQ(2,96)
@@ -158,5 +167,18 @@
#endif
#endif
+#ifndef __attribute_malloc__
+#if __has_attribute(malloc) \
+ || __GNUC_PREREQ(2,96)
+#define __attribute_malloc__ __attribute__((__malloc__))
+#elif defined(_MSC_VER)
+#undef restrict
+#define __attribute_malloc__ __declspec(restrict)
+#define restrict __restrict
+#else
+#define __attribute_malloc__
+#endif
+#endif
+
#endif
diff --git a/src/gw_backend.c b/src/gw_backend.c
index dbe27193..1de5b98f 100644
--- a/src/gw_backend.c
+++ b/src/gw_backend.c
@@ -702,6 +702,7 @@ static void gw_proc_kill(gw_host *host, gw_proc *proc) {
--host->num_procs;
}
+__attribute_pure__
static gw_host * unixsocket_is_dup(gw_plugin_data *p, const buffer *unixsocket) {
if (NULL == p->cvlist) return NULL;
/* (init i to 0 if global context; to 1 to skip empty global context) */
diff --git a/src/gw_backend.h b/src/gw_backend.h
index aed81265..ed8b0653 100644
--- a/src/gw_backend.h
+++ b/src/gw_backend.h
@@ -330,6 +330,7 @@ typedef struct gw_handler_ctx {
__attribute_cold__
+__attribute_malloc__
void * gw_init(void);
__attribute_cold__
diff --git a/src/http_auth.c b/src/http_auth.c
index 4bc4f70c..c0ccc9ce 100644
--- a/src/http_auth.c
+++ b/src/http_auth.c
@@ -134,6 +134,7 @@ void http_auth_require_free (http_auth_require_t * const require)
/* (case-sensitive version of array.c:array_get_index(),
* and common case expects small num of allowed tokens,
* so it is reasonably performant to simply walk the array) */
+__attribute_pure__
static int http_auth_array_contains (const array * const a, const char * const k, const size_t klen)
{
for (size_t i = 0, used = a->used; i < used; ++i) {
diff --git a/src/http_auth.h b/src/http_auth.h
index db388c63..13b82a18 100644
--- a/src/http_auth.h
+++ b/src/http_auth.h
@@ -21,6 +21,7 @@ typedef enum http_auth_digest_type {
#define HTTP_AUTH_DIGEST_SHA256_BINLEN 32 /* SHA256_DIGEST_LENGTH */
#define HTTP_AUTH_DIGEST_SHA512_256_BINLEN 32 /* SHA512_256_DIGEST_LENGTH */
+__attribute_const__
unsigned int http_auth_digest_len (int algo);
struct http_auth_scheme_t;
@@ -39,11 +40,13 @@ typedef struct http_auth_require_t {
} http_auth_require_t;
__attribute_cold__
+__attribute_malloc__
http_auth_require_t * http_auth_require_init (void);
__attribute_cold__
void http_auth_require_free (http_auth_require_t *require);
+__attribute_pure__
int http_auth_match_rules (const http_auth_require_t *require, const char *user, const char *group, const char *host);
typedef struct http_auth_info_t {
@@ -72,12 +75,14 @@ typedef struct http_auth_scheme_t {
} http_auth_scheme_t;
__attribute_cold__
+__attribute_pure__
const http_auth_scheme_t * http_auth_scheme_get (const buffer *name);
__attribute_cold__
void http_auth_scheme_set (const http_auth_scheme_t *scheme);
__attribute_cold__
+__attribute_pure__
const http_auth_backend_t * http_auth_backend_get (const buffer *name);
__attribute_cold__
diff --git a/src/http_kv.h b/src/http_kv.h
index a3845677..1d123d02 100644
--- a/src/http_kv.h
+++ b/src/http_kv.h
@@ -59,11 +59,21 @@ typedef enum {
typedef enum { HTTP_VERSION_UNSET = -1, HTTP_VERSION_1_0, HTTP_VERSION_1_1, HTTP_VERSION_2 } http_version_t;
+__attribute_pure__
const char *get_http_status_name(int i);
+
+__attribute_pure__
const char *get_http_version_name(int i);
+
+__attribute_pure__
const char *get_http_method_name(http_method_t i);
+
+__attribute_pure__
int get_http_version_key(const char *s, size_t slen);
+
+__attribute_pure__
http_method_t get_http_method_key(const char *s, size_t slen);
+
void http_status_append(buffer *b, int status);
void http_method_append(buffer *b, http_method_t method);
void http_version_append(buffer *b, http_version_t version);
diff --git a/src/http_vhostdb.h b/src/http_vhostdb.h
index 32924ea4..b5b08565 100644
--- a/src/http_vhostdb.h
+++ b/src/http_vhostdb.h
@@ -15,6 +15,7 @@ typedef struct http_vhostdb_backend_t {
} http_vhostdb_backend_t;
__attribute_cold__
+__attribute_pure__
const http_vhostdb_backend_t * http_vhostdb_backend_get (const buffer *name);
__attribute_cold__
diff --git a/src/keyvalue.h b/src/keyvalue.h
index 277bddd3..aaa32d77 100644
--- a/src/keyvalue.h
+++ b/src/keyvalue.h
@@ -24,6 +24,7 @@ typedef struct {
} pcre_keyvalue_buffer;
__attribute_cold__
+__attribute_malloc__
pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void);
__attribute_cold__
diff --git a/src/log.c b/src/log.c
index 98d5555e..d27ececf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -133,6 +133,7 @@ log_buffer_append_encoded (buffer * const b,
}
+__attribute_format__((__printf__, 2, 0))
static void
log_buffer_vprintf (buffer * const b,
const char * const fmt, va_list ap)
@@ -171,6 +172,7 @@ log_buffer_vprintf (buffer * const b,
}
+__attribute_format__((__printf__, 4, 0))
static void
log_error_va_list_impl (log_error_st * const errh,
const char * const filename,
diff --git a/src/mod_authn_pam.c b/src/mod_authn_pam.c
index a803d1f5..63099cd6 100644
--- a/src/mod_authn_pam.c
+++ b/src/mod_authn_pam.c
@@ -102,7 +102,8 @@ SETDEFAULTS_FUNC(mod_authn_pam_set_defaults) {
if (cpv->v.a->used) {
const data_string *ds = (const data_string *)
array_get_element_klen(cpv->v.a,CONST_STR_LEN("service"));
- cpv->v.v = (NULL != ds) ? ds->value.ptr : "http";
+ *(const void **)&cpv->v.v =
+ (NULL != ds) ? ds->value.ptr : "http";
cpv->vtype = T_CONFIG_LOCAL;
}
break;
diff --git a/src/mod_extforward.c b/src/mod_extforward.c
index 4f41b4ce..65d5fbaf 100644
--- a/src/mod_extforward.c
+++ b/src/mod_extforward.c
@@ -652,6 +652,7 @@ static handler_t mod_extforward_X_Forwarded_For(request_st * const r, plugin_dat
return HANDLER_GO_ON;
}
+__attribute_pure__
static int find_end_quoted_string (const char * const s, int i) {
do {
++i;
@@ -659,6 +660,7 @@ static int find_end_quoted_string (const char * const s, int i) {
return i;
}
+__attribute_pure__
static int find_next_semicolon_or_comma_or_eq (const char * const s, int i) {
for (; s[i] != '=' && s[i] != ';' && s[i] != ',' && s[i] != '\0'; ++i) {
if (s[i] == '"') {
@@ -669,6 +671,7 @@ static int find_next_semicolon_or_comma_or_eq (const char * const s, int i) {
return i;
}
+__attribute_pure__
static int find_next_semicolon_or_comma (const char * const s, int i) {
for (; s[i] != ';' && s[i] != ',' && s[i] != '\0'; ++i) {
if (s[i] == '"') {
diff --git a/src/mod_ssi.c b/src/mod_ssi.c
index eb04d1b5..ec4f3b78 100644
--- a/src/mod_ssi.c
+++ b/src/mod_ssi.c
@@ -924,6 +924,7 @@ static int process_ssi_stmt(request_st * const r, handler_ctx * const p, const c
}
+__attribute_pure__
static int mod_ssi_parse_ssi_stmt_value(const unsigned char * const s, const int len) {
int n;
const int c = (s[0] == '"' ? '"' : s[0] == '\'' ? '\'' : 0);
diff --git a/src/mod_ssi_expr.c b/src/mod_ssi_expr.c
index ac27ab00..7bc3622e 100644
--- a/src/mod_ssi_expr.c
+++ b/src/mod_ssi_expr.c
@@ -22,6 +22,7 @@ typedef struct {
int in_cond;
} ssi_tokenizer_t;
+__attribute_malloc__
ssi_val_t *ssi_val_init(void) {
ssi_val_t *s;
@@ -36,6 +37,7 @@ void ssi_val_free(ssi_val_t *s) {
free(s);
}
+__attribute_pure__
int ssi_val_tobool(ssi_val_t *B) {
if (B->type == SSI_TYPE_STRING) {
return !buffer_string_is_empty(B->str);
diff --git a/src/mod_uploadprogress.c b/src/mod_uploadprogress.c
index c6e3ac7a..0916cdc2 100644
--- a/src/mod_uploadprogress.c
+++ b/src/mod_uploadprogress.c
@@ -83,9 +83,10 @@ static int request_map_insert(request_map *rm, request_st * const r, const char
return 0;
}
-static request_st * request_map_get_request(request_map *rm, const char *r_id, size_t idlen) {
+__attribute_pure__
+static request_st * request_map_get_request(const request_map * const rm, const char * const r_id, const size_t idlen) {
for (uint32_t i = 0; i < rm->used; ++i) {
- request_map_entry *rme = rm->ptr[i];
+ const request_map_entry * const rme = rm->ptr[i];
if (buffer_is_equal_string(rme->r_id, r_id, idlen)) {
return rme->r; /* found request */
diff --git a/src/network_write.h b/src/network_write.h
index 16114c00..6279292b 100644
--- a/src/network_write.h
+++ b/src/network_write.h
@@ -7,6 +7,7 @@ __attribute_cold__
int network_write_init(server *srv);
__attribute_cold__
+__attribute_const__
const char * network_write_show_handlers(void);
#endif
diff --git a/src/plugin_config.h b/src/plugin_config.h
index db7f9801..d9369701 100644
--- a/src/plugin_config.h
+++ b/src/plugin_config.h
@@ -129,9 +129,11 @@ typedef struct {
} config_plugin_keys_t;
__attribute_cold__
+__attribute_pure__
int config_plugin_value_tobool(const data_unset *du, int default_value);
__attribute_cold__
+__attribute_pure__
int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
__attribute_cold__
diff --git a/src/request.c b/src/request.c
index 62f2f0cb..b0a8a5a8 100644
--- a/src/request.c
+++ b/src/request.c
@@ -347,7 +347,7 @@ int http_request_host_policy (buffer * const b, const unsigned int http_parseopt
&& 0 != http_request_host_normalize(b, scheme_port)));
}
-__attribute_pure__ /*(could be even more strict and use __attribute_const__)*/
+__attribute_const__
static int request_uri_is_valid_char(const unsigned char c) {
return (c > 32 && c != 127 && c != 255);
}
diff --git a/src/stat_cache.h b/src/stat_cache.h
index 06c1142e..62e42c69 100644
--- a/src/stat_cache.h
+++ b/src/stat_cache.h
@@ -41,7 +41,9 @@ void stat_cache_entry_refchg(void *data, int mod);
__attribute_cold__
void stat_cache_xattrname (const char *name);
+__attribute_pure__
const buffer * stat_cache_mimetype_by_ext(const array *mimetypes, const char *name, uint32_t nlen);
+
#if defined(HAVE_XATTR) || defined(HAVE_EXTATTR)
const buffer * stat_cache_mimetype_by_xattr(const char *name);
const buffer * stat_cache_content_type_get_by_xattr(stat_cache_entry *sce, const array *mimetypes, int use_xattr);
diff --git a/src/vector.h b/src/vector.h
index d3587936..8c40cd5a 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -10,7 +10,10 @@ static inline size_t vector_align_size(size_t s) {
}
void vector_free(void *data);
+
+__attribute_malloc__
void *vector_malloc(size_t sz);
+
void *vector_realloc(void *data, size_t elem_size, size_t size, size_t used);
#define DEFINE_TYPED_VECTOR(name, entry, release) \