From 67ff31299459d3f925313ccc7357725feb2a57a4 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Wed, 10 Oct 2018 11:22:53 +0000 Subject: [PATCH] mod_http2: bringing some signed/unsigned casting goodness, aligning with github mod-h2 again git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1843424 13f79535-47bb-0310-9956-ffa450edef68 --- modules/http2/h2_alt_svc.c | 4 ++-- modules/http2/h2_bucket_beam.c | 21 +++++++++++++-------- modules/http2/h2_config.c | 9 ++++++--- modules/http2/h2_conn.c | 2 ++ modules/http2/h2_conn_io.c | 27 ++++++++++++++------------- modules/http2/h2_filter.c | 6 ++++-- modules/http2/h2_from_h1.c | 6 +++--- modules/http2/h2_push.c | 15 ++++++++------- modules/http2/h2_push.h | 2 +- modules/http2/h2_version.h | 4 ++-- modules/http2/h2_workers.h | 4 ++-- modules/http2/mod_http2.c | 2 +- 12 files changed, 58 insertions(+), 44 deletions(-) diff --git a/modules/http2/h2_alt_svc.c b/modules/http2/h2_alt_svc.c index 295a16df25..9ce5ad9ed2 100644 --- a/modules/http2/h2_alt_svc.c +++ b/modules/http2/h2_alt_svc.c @@ -46,14 +46,14 @@ h2_alt_svc *h2_alt_svc_parse(const char *s, apr_pool_t *pool) { const char *sep = ap_strchr_c(s, '='); if (sep) { - const char *alpn = apr_pstrmemdup(pool, s, sep - s); + const char *alpn = apr_pstrmemdup(pool, s, (apr_size_t)(sep - s)); const char *host = NULL; int port = 0; s = sep + 1; sep = ap_strchr_c(s, ':'); /* mandatory : */ if (sep) { if (sep != s) { /* optional host */ - host = apr_pstrmemdup(pool, s, sep - s); + host = apr_pstrmemdup(pool, s, (apr_size_t)(sep - s)); } s = sep + 1; if (*s) { /* must be a port number */ diff --git a/modules/http2/h2_bucket_beam.c b/modules/http2/h2_bucket_beam.c index f79cbe3356..a7f5edf5cc 100644 --- a/modules/http2/h2_bucket_beam.c +++ b/modules/http2/h2_bucket_beam.c @@ -198,6 +198,7 @@ static apr_bucket *h2_beam_bucket(h2_bucket_beam *beam, static void mutex_leave(void *ctx, apr_thread_mutex_t *lock) { + (void)ctx; apr_thread_mutex_unlock(lock); } @@ -216,6 +217,7 @@ static apr_status_t enter_yellow(h2_bucket_beam *beam, h2_beam_lock *pbl) static void leave_yellow(h2_bucket_beam *beam, h2_beam_lock *pbl) { + (void)beam; if (pbl->leave) { pbl->leave(pbl->leave_ctx, pbl->mutex); } @@ -228,7 +230,7 @@ static apr_off_t bucket_mem_used(apr_bucket *b) } else { /* should all have determinate length */ - return b->length; + return (apr_off_t)b->length; } } @@ -302,7 +304,7 @@ static void r_purge_sent(h2_bucket_beam *beam) static apr_size_t calc_space_left(h2_bucket_beam *beam) { if (beam->max_buf_size > 0) { - apr_off_t len = calc_buffered(beam); + apr_size_t len = calc_buffered(beam); return (beam->max_buf_size > len? (beam->max_buf_size - len) : 0); } return APR_SIZE_MAX; @@ -777,6 +779,8 @@ static apr_status_t append_bucket(h2_bucket_beam *beam, apr_status_t status; int can_beam = 0, check_len; + (void)block; + (void)pbl; if (beam->aborted) { return APR_ECONNABORTED; } @@ -815,8 +819,8 @@ static apr_status_t append_bucket(h2_bucket_beam *beam, } else { if (b->length == ((apr_size_t)-1)) { - const char *data; - status = apr_bucket_read(b, &data, &len, APR_BLOCK_READ); + const char *data2; + status = apr_bucket_read(b, &data2, &len, APR_BLOCK_READ); if (status != APR_SUCCESS) { return status; } @@ -957,7 +961,7 @@ apr_status_t h2_beam_receive(h2_bucket_beam *beam, /* Called from the receiver thread to take buckets from the beam */ if (enter_yellow(beam, &bl) == APR_SUCCESS) { if (readbytes <= 0) { - readbytes = APR_SIZE_MAX; + readbytes = (apr_off_t)APR_SIZE_MAX; } remain = readbytes; @@ -1027,7 +1031,7 @@ transfer: } ++beam->files_beamed; } - ng = apr_brigade_insert_file(bb, fd, bsender->start, bsender->length, + ng = apr_brigade_insert_file(bb, fd, bsender->start, (apr_off_t)bsender->length, bb->p); #if APR_HAS_MMAP /* disable mmap handling as this leads to segfaults when @@ -1087,9 +1091,9 @@ transfer: brecv != APR_BRIGADE_SENTINEL(bb); brecv = APR_BUCKET_NEXT(brecv)) { remain -= (beam->tx_mem_limits? bucket_mem_used(brecv) - : brecv->length); + : (apr_off_t)brecv->length); if (remain < 0) { - apr_bucket_split(brecv, brecv->length+remain); + apr_bucket_split(brecv, (apr_size_t)((apr_off_t)brecv->length+remain)); beam->recv_buffer = apr_brigade_split_ex(bb, APR_BUCKET_NEXT(brecv), beam->recv_buffer); @@ -1255,6 +1259,7 @@ apr_size_t h2_beam_get_files_beamed(h2_bucket_beam *beam) int h2_beam_no_files(void *ctx, h2_bucket_beam *beam, apr_file_t *file) { + (void)ctx; (void)beam; (void)file; return 0; } diff --git a/modules/http2/h2_config.c b/modules/http2/h2_config.c index 9d9be90749..8bb1d1cc46 100644 --- a/modules/http2/h2_config.c +++ b/modules/http2/h2_config.c @@ -221,7 +221,7 @@ const struct h2_priority *h2_config_get_priority(const h2_config *conf, const char *content_type) { if (content_type && conf->priorities) { - size_t len = strcspn(content_type, "; \t"); + apr_ssize_t len = (apr_ssize_t)strcspn(content_type, "; \t"); h2_priority *prio = apr_hash_get(conf->priorities, content_type, len); return prio? prio : apr_hash_get(conf->priorities, "*", 1); } @@ -400,7 +400,8 @@ static const char *h2_conf_add_push_priority(cmd_parms *cmd, void *_cfg, h2_dependency dependency; h2_priority *priority; int weight; - + + (void)_cfg; if (!*ctype) { return "1st argument must be a mime-type, like 'text/css' or '*'"; } @@ -443,7 +444,7 @@ static const char *h2_conf_add_push_priority(cmd_parms *cmd, void *_cfg, if (!cfg->priorities) { cfg->priorities = apr_hash_make(cmd->pool); } - apr_hash_set(cfg->priorities, ctype, strlen(ctype), priority); + apr_hash_set(cfg->priorities, ctype, (apr_ssize_t)strlen(ctype), priority); return NULL; } @@ -521,6 +522,8 @@ static const char *h2_conf_set_copy_files(cmd_parms *parms, void *arg, const char *value) { h2_config *cfg = (h2_config *)arg; + + (void)parms; if (!strcasecmp(value, "On")) { cfg->copy_files = 1; return NULL; diff --git a/modules/http2/h2_conn.c b/modules/http2/h2_conn.c index 4da90c9a2c..0d6c086e5e 100644 --- a/modules/http2/h2_conn.c +++ b/modules/http2/h2_conn.c @@ -250,6 +250,8 @@ apr_status_t h2_conn_run(struct h2_ctx *ctx, conn_rec *c) apr_status_t h2_conn_pre_close(struct h2_ctx *ctx, conn_rec *c) { h2_session *session = h2_ctx_session_get(ctx); + + (void)c; if (session) { apr_status_t status = h2_session_pre_close(session, async_mpm); return (status == APR_SUCCESS)? DONE : status; diff --git a/modules/http2/h2_conn_io.c b/modules/http2/h2_conn_io.c index eb6ec92313..afeb22606a 100644 --- a/modules/http2/h2_conn_io.c +++ b/modules/http2/h2_conn_io.c @@ -47,16 +47,18 @@ */ #define WRITE_SIZE_MAX (TLS_DATA_MAX - 100) +#define BUF_REMAIN ((apr_size_t)(bmax-off)) static void h2_conn_io_bb_log(conn_rec *c, int stream_id, int level, const char *tag, apr_bucket_brigade *bb) { char buffer[16 * 1024]; const char *line = "(null)"; - apr_size_t bmax = sizeof(buffer)/sizeof(buffer[0]); + int bmax = sizeof(buffer)/sizeof(buffer[0]); int off = 0; apr_bucket *b; + (void)stream_id; if (bb) { memset(buffer, 0, bmax--); for (b = APR_BRIGADE_FIRST(bb); @@ -65,19 +67,19 @@ static void h2_conn_io_bb_log(conn_rec *c, int stream_id, int level, if (APR_BUCKET_IS_METADATA(b)) { if (APR_BUCKET_IS_EOS(b)) { - off += apr_snprintf(buffer+off, bmax-off, "eos "); + off += apr_snprintf(buffer+off, BUF_REMAIN, "eos "); } else if (APR_BUCKET_IS_FLUSH(b)) { - off += apr_snprintf(buffer+off, bmax-off, "flush "); + off += apr_snprintf(buffer+off, BUF_REMAIN, "flush "); } else if (AP_BUCKET_IS_EOR(b)) { - off += apr_snprintf(buffer+off, bmax-off, "eor "); + off += apr_snprintf(buffer+off, BUF_REMAIN, "eor "); } else if (H2_BUCKET_IS_H2EOS(b)) { - off += apr_snprintf(buffer+off, bmax-off, "h2eos "); + off += apr_snprintf(buffer+off, BUF_REMAIN, "h2eos "); } else { - off += apr_snprintf(buffer+off, bmax-off, "meta(unknown) "); + off += apr_snprintf(buffer+off, BUF_REMAIN, "meta(unknown) "); } } else { @@ -109,10 +111,9 @@ static void h2_conn_io_bb_log(conn_rec *c, int stream_id, int level, btype = "pool"; } - off += apr_snprintf(buffer+off, bmax-off, "%s[%ld] ", + off += apr_snprintf(buffer+off, BUF_REMAIN, "%s[%ld] ", btype, - (long)(b->length == ((apr_size_t)-1)? - -1 : b->length)); + (long)(b->length == ((apr_size_t)-1)? -1UL : b->length)); } } line = *buffer? buffer : "(empty)"; @@ -153,7 +154,7 @@ apr_status_t h2_conn_io_init(h2_conn_io *io, conn_rec *c, "h2_conn_io(%ld): init, buffering=%d, warmup_size=%ld, " "cd_secs=%f", io->c->id, io->buffer_output, (long)io->warmup_size, - ((float)io->cooldown_usecs/APR_USEC_PER_SEC)); + ((double)io->cooldown_usecs/APR_USEC_PER_SEC)); } return APR_SUCCESS; @@ -202,8 +203,8 @@ static apr_status_t read_to_scratch(h2_conn_io *io, apr_bucket *b) apr_bucket_file *f = (apr_bucket_file *)b->data; apr_file_t *fd = f->fd; apr_off_t offset = b->start; - apr_size_t len = b->length; + len = b->length; /* file buckets will either mmap (which we do not want) or * read 8000 byte chunks and split themself. However, we do * know *exactly* how many bytes we need where. @@ -288,13 +289,13 @@ int h2_conn_io_needs_flush(h2_conn_io *io) { if (!io->is_flushed) { apr_off_t len = h2_brigade_mem_size(io->output); - if (len > io->flush_threshold) { + if (len > (apr_off_t)io->flush_threshold) { return 1; } /* if we do not exceed flush length due to memory limits, * we want at least flush when we have that amount of data. */ apr_brigade_length(io->output, 0, &len); - return len > (4 * io->flush_threshold); + return len > (apr_off_t)(4 * io->flush_threshold); } return 0; } diff --git a/modules/http2/h2_filter.c b/modules/http2/h2_filter.c index 2ea44156fe..5bda60bf58 100644 --- a/modules/http2/h2_filter.c +++ b/modules/http2/h2_filter.c @@ -54,6 +54,7 @@ static apr_status_t recv_RAW_DATA(conn_rec *c, h2_filter_cin *cin, const char *data; ssize_t n; + (void)c; status = apr_bucket_read(b, &data, &len, block); while (status == APR_SUCCESS && len > 0) { @@ -71,10 +72,10 @@ static apr_status_t recv_RAW_DATA(conn_rec *c, h2_filter_cin *cin, } else { session->io.bytes_read += n; - if (len <= n) { + if ((apr_ssize_t)len <= n) { break; } - len -= n; + len -= (apr_size_t)n; data += n; } } @@ -277,6 +278,7 @@ apr_bucket *h2_bucket_observer_beam(struct h2_bucket_beam *beam, apr_bucket_brigade *dest, const apr_bucket *src) { + (void)beam; if (H2_BUCKET_IS_OBSERVER(src)) { h2_bucket_observer *l = (h2_bucket_observer *)src->data; apr_bucket *b = h2_bucket_observer_create(dest->bucket_alloc, diff --git a/modules/http2/h2_from_h1.c b/modules/http2/h2_from_h1.c index d69c53c21b..20645d9f2d 100644 --- a/modules/http2/h2_from_h1.c +++ b/modules/http2/h2_from_h1.c @@ -625,10 +625,10 @@ static void make_chunk(h2_task *task, apr_bucket_brigade *bb, * to the end of the brigade. */ char buffer[128]; apr_bucket *c; - int len; + apr_size_t len; - len = apr_snprintf(buffer, H2_ALEN(buffer), - "%"APR_UINT64_T_HEX_FMT"\r\n", (apr_uint64_t)chunk_len); + len = (apr_size_t)apr_snprintf(buffer, H2_ALEN(buffer), + "%"APR_UINT64_T_HEX_FMT"\r\n", (apr_uint64_t)chunk_len); c = apr_bucket_heap_create(buffer, len, NULL, bb->bucket_alloc); APR_BUCKET_INSERT_BEFORE(first, c); c = apr_bucket_heap_create("\r\n", 2, NULL, bb->bucket_alloc); diff --git a/modules/http2/h2_push.c b/modules/http2/h2_push.c index 9a3b19bdc2..750088af2d 100644 --- a/modules/http2/h2_push.c +++ b/modules/http2/h2_push.c @@ -59,7 +59,7 @@ static const char *policy_str(h2_push_policy policy) typedef struct { const h2_request *req; - int push_policy; + apr_uint32_t push_policy; apr_pool_t *pool; apr_array_header_t *pushes; const char *s; @@ -434,7 +434,7 @@ static int head_iter(void *ctx, const char *key, const char *value) } apr_array_header_t *h2_push_collect(apr_pool_t *p, const h2_request *req, - int push_policy, const h2_headers *res) + apr_uint32_t push_policy, const h2_headers *res) { if (req && push_policy != H2_PUSH_NONE) { /* Collect push candidates from the request/response pair. @@ -528,13 +528,14 @@ static void calc_sha256_hash(h2_push_diary *diary, apr_uint64_t *phash, h2_push static unsigned int val_apr_hash(const char *str) { - apr_ssize_t len = strlen(str); + apr_ssize_t len = (apr_ssize_t)strlen(str); return apr_hashfunc_default(str, &len); } static void calc_apr_hash(h2_push_diary *diary, apr_uint64_t *phash, h2_push *push) { apr_uint64_t val; + (void)diary; #if APR_UINT64_MAX > UINT_MAX val = ((apr_uint64_t)(val_apr_hash(push->req->scheme)) << 32); val ^= ((apr_uint64_t)(val_apr_hash(push->req->authority)) << 16); @@ -621,10 +622,10 @@ static h2_push_diary_entry *move_to_last(h2_push_diary *diary, apr_size_t idx) { h2_push_diary_entry *entries = (h2_push_diary_entry*)diary->entries->elts; h2_push_diary_entry e; - apr_size_t lastidx = diary->entries->nelts-1; + apr_size_t lastidx = (apr_size_t)diary->entries->nelts; /* move entry[idx] to the end */ - if (idx < lastidx) { + if (idx+1 < lastidx) { e = entries[idx]; memmove(entries+idx, entries+idx+1, sizeof(e) * (lastidx - idx)); entries[lastidx] = e; @@ -670,7 +671,7 @@ apr_array_header_t *h2_push_diary_update(h2_session *session, apr_array_header_t /* Intentional no APLOGNO */ ap_log_cerror(APLOG_MARK, GCSLOG_LEVEL, 0, session->c, "push_diary_update: already there PUSH %s", push->req->path); - move_to_last(session->push_diary, idx); + move_to_last(session->push_diary, (apr_size_t)idx); } else { /* Intentional no APLOGNO */ @@ -830,7 +831,7 @@ apr_status_t h2_push_diary_digest_get(h2_push_diary *diary, apr_pool_t *pool, nelts = diary->entries->nelts; - if (nelts > APR_UINT32_MAX) { + if ((apr_uint32_t)nelts > APR_UINT32_MAX) { /* should not happen */ return APR_ENOTIMPL; } diff --git a/modules/http2/h2_push.h b/modules/http2/h2_push.h index bc24e68771..0533853934 100644 --- a/modules/http2/h2_push.h +++ b/modules/http2/h2_push.h @@ -61,7 +61,7 @@ struct h2_push_diary { */ apr_array_header_t *h2_push_collect(apr_pool_t *p, const struct h2_request *req, - int push_policy, + apr_uint32_t push_policy, const struct h2_headers *res); /** diff --git a/modules/http2/h2_version.h b/modules/http2/h2_version.h index d4e705340d..c88982e1da 100644 --- a/modules/http2/h2_version.h +++ b/modules/http2/h2_version.h @@ -27,7 +27,7 @@ * @macro * Version number of the http2 module as c string */ -#define MOD_HTTP2_VERSION "1.11.0-DEV" +#define MOD_HTTP2_VERSION "1.11.2-DEV" /** * @macro @@ -35,7 +35,7 @@ * release. This is a 24 bit number with 8 bits for major number, 8 bits * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203. */ -#define MOD_HTTP2_VERSION_NUM 0x010b00 +#define MOD_HTTP2_VERSION_NUM 0x010b02 #endif /* mod_h2_h2_version_h */ diff --git a/modules/http2/h2_workers.h b/modules/http2/h2_workers.h index 356158201c..d1a97255c3 100644 --- a/modules/http2/h2_workers.h +++ b/modules/http2/h2_workers.h @@ -38,8 +38,8 @@ struct h2_workers { apr_pool_t *pool; int next_worker_id; - int min_workers; - int max_workers; + apr_uint32_t min_workers; + apr_uint32_t max_workers; int max_idle_secs; int aborted; diff --git a/modules/http2/mod_http2.c b/modules/http2/mod_http2.c index 3d278e9f2f..34c6a10e8c 100644 --- a/modules/http2/mod_http2.c +++ b/modules/http2/mod_http2.c @@ -184,7 +184,7 @@ static apr_status_t http2_req_engine_pull(h2_req_engine *ngn, int capacity, request_rec **pr) { - return h2_mplx_req_engine_pull(ngn, block, capacity, pr); + return h2_mplx_req_engine_pull(ngn, block, (apr_uint32_t)capacity, pr); } static void http2_req_engine_done(h2_req_engine *ngn, conn_rec *r_conn, -- 2.40.0