diff --git a/CMakeLists.txt b/CMakeLists.txt index 68d2f11f6..90cecc8be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -657,6 +657,12 @@ CHECK_C_SOURCE_COMPILES("#include return 0; }" LWS_HAVE_RTA_PREF) +CHECK_C_SOURCE_COMPILES("#include + int main(void) { + suseconds_t x = 0; + return (int)x; + }" LWS_HAVE_SUSECONDS_T) + if (NOT PID_T_SIZE) set(pid_t int) endif() @@ -722,7 +728,7 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) # always warn all and generate debug info if (UNIX AND NOT LWS_PLAT_FREERTOS) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wstrict-aliasing ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) + set(CMAKE_C_FLAGS "-Wall -Wconversion -Wsign-compare -Wstrict-aliasing ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) else() set(CMAKE_C_FLAGS "-Wall -Wsign-compare ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" ) endif() diff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in index 2c12a6107..55b367943 100644 --- a/cmake/lws_config.h.in +++ b/cmake/lws_config.h.in @@ -87,6 +87,7 @@ #cmakedefine LWS_HAVE_SYS_CAPABILITY_H #cmakedefine LWS_HAVE_TLS_CLIENT_METHOD #cmakedefine LWS_HAVE_TLSV1_2_CLIENT_METHOD +#cmakedefine LWS_HAVE_SUSECONDS_T #cmakedefine LWS_HAVE_UV_VERSION_H #cmakedefine LWS_HAVE_VFORK #cmakedefine LWS_HAVE_X509_get_key_usage diff --git a/include/libwebsockets.h b/include/libwebsockets.h index 18cbe61ce..764b6b168 100644 --- a/include/libwebsockets.h +++ b/include/libwebsockets.h @@ -88,6 +88,14 @@ typedef unsigned long long lws_intptr_t; #define O_RDONLY _O_RDONLY #endif +typedef int uid_t; +typedef int gid_t; +typedef unsigned short sa_family_t; +#if !defined(LWS_HAVE_SUSECONDS_T) +typedef unsigned int useconds_t; +typedef int suseconds_t; +#endif + #define LWS_INLINE __inline #define LWS_VISIBLE #define LWS_WARN_UNUSED_RESULT diff --git a/include/libwebsockets/lws-context-vhost.h b/include/libwebsockets/lws-context-vhost.h index d23d49988..796cc476f 100644 --- a/include/libwebsockets/lws-context-vhost.h +++ b/include/libwebsockets/lws-context-vhost.h @@ -563,10 +563,10 @@ struct lws_context_creation_info { * 0 defaults to 10s. */ #endif /* WITH_NETWORK */ - int gid; + gid_t gid; /**< CONTEXT: group id to change to after setting listen socket, * or -1. See also .username below. */ - int uid; + uid_t uid; /**< CONTEXT: user id to change to after setting listen socket, * or -1. See also .groupname below. */ uint64_t options; diff --git a/include/libwebsockets/lws-diskcache.h b/include/libwebsockets/lws-diskcache.h index bec8082d6..ebca888d5 100644 --- a/include/libwebsockets/lws-diskcache.h +++ b/include/libwebsockets/lws-diskcache.h @@ -100,7 +100,7 @@ lws_diskcache_destroy(struct lws_diskcache_scan **lds); * will transition to use when it drops root privileges. */ LWS_VISIBLE LWS_EXTERN int -lws_diskcache_prepare(const char *cache_base_dir, int mode, int uid); +lws_diskcache_prepare(const char *cache_base_dir, int mode, uid_t uid); #define LWS_DISKCACHE_QUERY_NO_CACHE 0 #define LWS_DISKCACHE_QUERY_EXISTS 1 diff --git a/include/libwebsockets/lws-http.h b/include/libwebsockets/lws-http.h index 313af1d8b..c2f0e57fe 100644 --- a/include/libwebsockets/lws-http.h +++ b/include/libwebsockets/lws-http.h @@ -954,7 +954,7 @@ lws_http_cookie_get(struct lws *wsi, const char *name, char *buf, size_t *max); */ #define LWS_H2_STREAM_SID -1 LWS_VISIBLE LWS_EXTERN int -lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump); +lws_h2_update_peer_txcredit(struct lws *wsi, unsigned int sid, int bump); /** diff --git a/include/libwebsockets/lws-logs.h b/include/libwebsockets/lws-logs.h index f1c91b1c8..422bbeb4d 100644 --- a/include/libwebsockets/lws-logs.h +++ b/include/libwebsockets/lws-logs.h @@ -59,7 +59,7 @@ * returns length written in p */ LWS_VISIBLE LWS_EXTERN int -lwsl_timestamp(int level, char *p, int len); +lwsl_timestamp(int level, char *p, size_t len); #if defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_NETWORK) #define _lws_log(aaa, ...) SMSG(__VA_ARGS__) diff --git a/include/libwebsockets/lws-lwsac.h b/include/libwebsockets/lws-lwsac.h index fd8735c56..229503985 100644 --- a/include/libwebsockets/lws-lwsac.h +++ b/include/libwebsockets/lws-lwsac.h @@ -229,7 +229,7 @@ lwsac_unreference(struct lwsac **head); * cases */ LWS_VISIBLE LWS_EXTERN int -lwsac_extend(struct lwsac *head, int amount); +lwsac_extend(struct lwsac *head, size_t amount); /* helpers to keep a file cached in memory */ diff --git a/include/libwebsockets/lws-misc.h b/include/libwebsockets/lws-misc.h index fe139fee5..98c80295e 100644 --- a/include/libwebsockets/lws-misc.h +++ b/include/libwebsockets/lws-misc.h @@ -542,7 +542,7 @@ lws_get_child(const struct lws *wsi); * and subdir creation / permissions down /var/cache dynamically. */ LWS_VISIBLE LWS_EXTERN void -lws_get_effective_uid_gid(struct lws_context *context, int *uid, int *gid); +lws_get_effective_uid_gid(struct lws_context *context, uid_t *uid, gid_t *gid); /** * lws_get_udp() - get wsi's udp struct @@ -871,7 +871,7 @@ LWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_us[8]; */ LWS_VISIBLE LWS_EXTERN int -lws_humanize(char *buf, int len, uint64_t value, +lws_humanize(char *buf, size_t len, uint64_t value, const lws_humanize_unit_t *schema); LWS_VISIBLE LWS_EXTERN void diff --git a/include/libwebsockets/lws-purify.h b/include/libwebsockets/lws-purify.h index 09849f7e2..68acc6055 100644 --- a/include/libwebsockets/lws-purify.h +++ b/include/libwebsockets/lws-purify.h @@ -41,7 +41,7 @@ * possible to do it in-place, ie, with escaped == string */ LWS_VISIBLE LWS_EXTERN const char * -lws_sql_purify(char *escaped, const char *string, int len); +lws_sql_purify(char *escaped, const char *string, size_t len); /** * lws_sql_purify_len() - return length of purified version of input string @@ -93,12 +93,12 @@ lws_filename_purify_inplace(char *filename); LWS_VISIBLE LWS_EXTERN int lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len); + size_t len); LWS_VISIBLE LWS_EXTERN int -lws_plat_write_file(const char *filename, void *buf, int len); +lws_plat_write_file(const char *filename, void *buf, size_t len); LWS_VISIBLE LWS_EXTERN int -lws_plat_read_file(const char *filename, void *buf, int len); +lws_plat_read_file(const char *filename, void *buf, size_t len); LWS_VISIBLE LWS_EXTERN int lws_plat_recommended_rsa_bits(void); diff --git a/include/libwebsockets/lws-writeable.h b/include/libwebsockets/lws-writeable.h index 7f84d4ccf..884891107 100644 --- a/include/libwebsockets/lws-writeable.h +++ b/include/libwebsockets/lws-writeable.h @@ -166,7 +166,7 @@ lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, * wsi. */ LWS_VISIBLE LWS_EXTERN int -lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, size_t len) LWS_WARN_DEPRECATED; /** diff --git a/lib/core-net/adopt.c b/lib/core-net/adopt.c index 876548cdc..2427d30c6 100644 --- a/lib/core-net/adopt.c +++ b/lib/core-net/adopt.c @@ -27,7 +27,7 @@ static int lws_get_idlest_tsi(struct lws_context *context) { - unsigned int lowest = ~0; + unsigned int lowest = ~0u; int n = 0, hit = -1; for (; n < context->count_threads; n++) { @@ -69,7 +69,7 @@ lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi, const char *de __lws_lc_tag(&vhost->context->lcg[LWSLCG_WSI], &new_wsi->lc, desc); new_wsi->wsistate |= LWSIFR_SERVER; - new_wsi->tsi = n; + new_wsi->tsi = (char)n; lwsl_debug("%s joining vhost %s, tsi %d\n", new_wsi->lc.gutag, vhost->name, new_wsi->tsi); @@ -169,9 +169,9 @@ lws_adopt_descriptor_vhost1(struct lws_vhost *vh, lws_adoption_type type, if (!LWS_SSL_ENABLED(new_wsi->a.vhost) || !(type & LWS_ADOPT_SOCKET)) - type &= ~LWS_ADOPT_ALLOW_SSL; + type &= (unsigned int)~LWS_ADOPT_ALLOW_SSL; - if (lws_role_call_adoption_bind(new_wsi, type, vh_prot_name)) { + if (lws_role_call_adoption_bind(new_wsi, (int)type, vh_prot_name)) { lwsl_err("%s: no role for desc type 0x%x\n", __func__, type); goto bail; } @@ -348,7 +348,7 @@ lws_adopt_descriptor_vhost2(struct lws *new_wsi, lws_adoption_type type, if (!LWS_SSL_ENABLED(new_wsi->a.vhost) || !(type & LWS_ADOPT_SOCKET)) - type &= ~LWS_ADOPT_ALLOW_SSL; + type &= (unsigned int)~LWS_ADOPT_ALLOW_SSL; /* * A new connection was accepted. Give the user a chance to @@ -401,13 +401,13 @@ lws_adopt_descriptor_vhost2(struct lws *new_wsi, lws_adoption_type type, * by deferring callback to this point, after insertion to fds, * lws_callback_on_writable() can work from the callback */ - if ((new_wsi->a.protocol->callback)(new_wsi, n, new_wsi->user_space, + if ((new_wsi->a.protocol->callback)(new_wsi, (enum lws_callback_reasons)n, new_wsi->user_space, NULL, 0)) goto fail; /* role may need to do something after all adoption completed */ - lws_role_call_adoption_bind(new_wsi, type | _LWS_ADOPT_FINISH, + lws_role_call_adoption_bind(new_wsi, (int)type | _LWS_ADOPT_FINISH, new_wsi->a.protocol->name); #if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) @@ -771,7 +771,7 @@ lws_create_adopt_udp(struct lws_vhost *vhost, const char *ads, int port, wsi->do_bind = !!(flags & LWS_CAUDP_BIND); wsi->do_broadcast = !!(flags & LWS_CAUDP_BROADCAST); wsi->pf_packet = !!(flags & LWS_CAUDP_PF_PACKET); - wsi->c_port = port; + wsi->c_port = (uint16_t)(unsigned int)port; if (retry_policy) wsi->retry_policy = retry_policy; else diff --git a/lib/core-net/client/client.c b/lib/core-net/client/client.c index 184556269..ef7df9d34 100644 --- a/lib/core-net/client/client.c +++ b/lib/core-net/client/client.c @@ -43,10 +43,10 @@ lws_set_proxy(struct lws_vhost *vhost, const char *proxy) p = strrchr(proxy, '@'); if (p) { /* auth is around */ - if ((unsigned int)(p - proxy) > sizeof(authstring) - 1) + if (lws_ptr_diff_size_t(p, proxy) > sizeof(authstring) - 1) goto auth_too_long; - lws_strncpy(authstring, proxy, p - proxy + 1); + lws_strncpy(authstring, proxy, lws_ptr_diff_size_t(p, proxy) + 1); // null termination not needed on input if (lws_b64_encode_string(authstring, lws_ptr_diff(p, proxy), vhost->proxy_basic_auth_token, @@ -104,7 +104,7 @@ lws_set_proxy(struct lws_vhost *vhost, const char *proxy) } if (p) { *p = '\0'; - vhost->http.http_proxy_port = atoi(p + 1); + vhost->http.http_proxy_port = (unsigned int)atoi(p + 1); } lwsl_info(" Proxy %s:%u\n", vhost->http.http_proxy_address, diff --git a/lib/core-net/client/connect.c b/lib/core-net/client/connect.c index 7f344a539..8d12d647a 100644 --- a/lib/core-net/client/connect.c +++ b/lib/core-net/client/connect.c @@ -91,7 +91,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) struct lws *wsi, *safe = NULL; const struct lws_protocols *p; const char *cisin[CIS_COUNT]; - int tid = 0, n, m, tsi = 0; + int tid = 0, n, tsi = 0; size_t size; char *pc; @@ -220,7 +220,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) wsi->user_space = NULL; wsi->pending_timeout = NO_PENDING_TIMEOUT; wsi->position_in_fds_table = LWS_NO_FDS_POS; - wsi->ocport = wsi->c_port = i->port; + wsi->ocport = wsi->c_port = (uint16_t)(unsigned int)i->port; wsi->sys_tls_client_cert = i->sys_tls_client_cert; #if defined(LWS_ROLE_H2) @@ -268,7 +268,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) } #if defined(LWS_WITH_TLS) - wsi->tls.use_ssl = i->ssl_connection; + wsi->tls.use_ssl = (unsigned int)i->ssl_connection; #else if (i->ssl_connection & LCCSCF_USE_SSL) { lwsl_err("%s: lws not configured for tls\n", __func__); @@ -354,10 +354,11 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) for (n = 0; n < CIS_COUNT; n++) if (cisin[n]) { + size_t mm; wsi->stash->cis[n] = pc; - m = (int)strlen(cisin[n]) + 1; - memcpy(pc, cisin[n], m); - pc += m; + mm = strlen(cisin[n]) + 1; + memcpy(pc, cisin[n], mm); + pc += mm; } /* diff --git a/lib/core-net/client/connect2.c b/lib/core-net/client/connect2.c index f687ba1f3..6db6ba95c 100644 --- a/lib/core-net/client/connect2.c +++ b/lib/core-net/client/connect2.c @@ -259,8 +259,8 @@ solo: wsi->a.context->detailed_latency_cb) { wsi->detlat.type = LDLT_NAME_RESOLUTION; wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); @@ -276,7 +276,7 @@ solo: if (wsi->a.vhost->http.http_proxy_port) { ads = wsi->a.vhost->http.http_proxy_address; - port = wsi->a.vhost->http.http_proxy_port; + port = (int)wsi->a.vhost->http.http_proxy_port; #else if (0) { #endif @@ -288,7 +288,7 @@ solo: } else if (wsi->a.vhost->socks_proxy_port) { lwsl_client("Sending SOCKS Greeting\n"); ads = wsi->a.vhost->socks_proxy_address; - port = wsi->a.vhost->socks_proxy_port; + port = (int)wsi->a.vhost->socks_proxy_port; #endif } else { diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index 994aa84f8..d544bc857 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -60,6 +60,8 @@ lws_client_connect_check(struct lws *wsi) int en = 0; socklen_t sl = sizeof(e); + (void)en; + /* * This resets SO_ERROR after reading it. If there's an error * condition, the connect definitively failed. @@ -239,8 +241,8 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, wsi->a.context->detailed_latency_cb) { wsi->detlat.type = LDLT_NAME_RESOLUTION; wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); @@ -279,7 +281,7 @@ next_dns_result: sa46_sockport(&wsi->sa46_peer, htons(port)); psa = sa46_sockaddr(&wsi->sa46_peer); - n = sa46_socklen(&wsi->sa46_peer); + n = (int)sa46_socklen(&wsi->sa46_peer); #if defined(LWS_WITH_UNIX_SOCK) ads_known: @@ -404,7 +406,7 @@ ads_known: * Finally, make the actual connection attempt */ - m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, n); + m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, (unsigned int)n); if (m == -1) { /* * Since we're nonblocking, connect not having completed is not @@ -490,8 +492,8 @@ conn_good: if (wsi->a.context->detailed_latency_cb) { wsi->detlat.type = LDLT_CONNECTION; wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); wsi->detlat.earliest_write_req = diff --git a/lib/core-net/client/connect4.c b/lib/core-net/client/connect4.c index 969599bd9..b3e503df3 100644 --- a/lib/core-net/client/connect4.c +++ b/lib/core-net/client/connect4.c @@ -93,9 +93,9 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, _WSI_TOKEN_CLIENT_PEER_ADDRESS, wsi->a.vhost->http.http_proxy_address)) goto failed; - wsi->c_port = wsi->a.vhost->http.http_proxy_port; + wsi->c_port = (uint16_t)wsi->a.vhost->http.http_proxy_port; - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, (int)plen, + n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, (unsigned int)plen, MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing to proxy socket\n"); @@ -104,7 +104,7 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, } lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); lwsi_set_state(wsi, LRS_WAITING_PROXY_REPLY); @@ -220,7 +220,7 @@ send_hs: LRS_H1C_ISSUE_HANDSHAKE2); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); goto provoke_service; } @@ -233,7 +233,7 @@ send_hs: if (m) { n = user_callback_handle_rxflow( wsi->a.protocol->callback, wsi, - m, wsi->user_space, NULL, 0); + (enum lws_callback_reasons)m, wsi->user_space, NULL, 0); if (n < 0) { lwsl_info("RAW_PROXY_CLI_ADOPT err\n"); goto failed; @@ -260,7 +260,7 @@ send_hs: */ lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); assert(lws_socket_is_valid(wsi->desc.sockfd)); @@ -301,7 +301,7 @@ send_hs: provoke_service: #endif lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); assert(lws_socket_is_valid(wsi->desc.sockfd)); diff --git a/lib/core-net/client/sort-dns.c b/lib/core-net/client/sort-dns.c index 0957a90a6..4f9fdc572 100644 --- a/lib/core-net/client/sort-dns.c +++ b/lib/core-net/client/sort-dns.c @@ -633,7 +633,7 @@ lws_sort_dns(struct lws *wsi, const struct addrinfo *result) return 1; memcpy(&ds->dest, ai->ai_addr, ai->ai_addrlen); - ds->dest.sa4.sin_family = ai->ai_family; + ds->dest.sa4.sin_family = (sa_family_t)ai->ai_family; lws_sa46_write_numeric_address(&ds->dest, afip, sizeof(afip)); diff --git a/lib/core-net/close.c b/lib/core-net/close.c index 05d845083..90c6cb261 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -30,7 +30,7 @@ lws_close_trans_q_leader(struct lws_dll2 *d, void *user) { struct lws *w = lws_container_of(d, struct lws, dll2_cli_txn_queue); - __lws_close_free_wsi(w, -1, "trans q leader closing"); + __lws_close_free_wsi(w, (enum lws_close_status)-1, "trans q leader closing"); return 0; } @@ -594,7 +594,7 @@ just_kill_connection: __lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN); lwsi_set_state(wsi, LRS_SHUTDOWN); __lws_set_timeout(wsi, PENDING_TIMEOUT_SHUTDOWN_FLUSH, - context->timeout_secs); + (int)context->timeout_secs); return; } diff --git a/lib/core-net/detailed-latency.c b/lib/core-net/detailed-latency.c index e176b4beb..a8c1d0988 100644 --- a/lib/core-net/detailed-latency.c +++ b/lib/core-net/detailed-latency.c @@ -61,7 +61,7 @@ lws_det_lat_plot_cb(struct lws_context *context, const lws_detlat_t *d) return 1; } - p += lws_snprintf(p, lws_ptr_diff(end, p), + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%llu %c %u %u %u %u %u %zu %zu\n", (unsigned long long)lws_now_usecs(), types[d->type], d->latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE], @@ -73,7 +73,7 @@ lws_det_lat_plot_cb(struct lws_context *context, const lws_detlat_t *d) d->latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX], d->acc_size, d->req_size); - write(context->latencies_fd, buf, lws_ptr_diff(p, buf)); + write(context->latencies_fd, buf, lws_ptr_diff_size_t(p, buf)); return 0; } diff --git a/lib/core-net/dummy-callback.c b/lib/core-net/dummy-callback.c index e998aa9f2..4a5afff7a 100644 --- a/lib/core-net/dummy-callback.c +++ b/lib/core-net/dummy-callback.c @@ -32,7 +32,7 @@ static int proxy_header(struct lws *wsi, struct lws *par, unsigned char *temp, int temp_len, int index, unsigned char **p, unsigned char *end) { - int n = lws_hdr_total_length(par, index); + int n = lws_hdr_total_length(par, (enum lws_token_indexes)index); if (n < 1) { lwsl_debug("%s: no index %d:\n", __func__, index); @@ -40,7 +40,7 @@ proxy_header(struct lws *wsi, struct lws *par, unsigned char *temp, return 0; } - if (lws_hdr_copy(par, (char *)temp, temp_len, index) < 0) { + if (lws_hdr_copy(par, (char *)temp, temp_len, (enum lws_token_indexes)index) < 0) { lwsl_notice("%s: unable to copy par hdr idx %d (len %d)\n", __func__, index, n); return -1; @@ -48,7 +48,7 @@ proxy_header(struct lws *wsi, struct lws *par, unsigned char *temp, lwsl_debug("%s: index %d: %s\n", __func__, index, (char *)temp); - if (lws_add_http_header_by_token(wsi, index, temp, n, p, end)) { + if (lws_add_http_header_by_token(wsi, (enum lws_token_indexes)index, temp, n, p, end)) { lwsl_notice("%s: unable to append par hdr idx %d (len %d)\n", __func__, index, n); return -1; @@ -169,9 +169,9 @@ lws_callback_ws_proxy(struct lws *wsi, enum lws_callback_reasons reason, return -1; pkt->len = len; - pkt->first = lws_is_first_fragment(wsi); - pkt->final = lws_is_final_fragment(wsi); - pkt->binary = lws_frame_is_binary(wsi); + pkt->first = (char)lws_is_first_fragment(wsi); + pkt->final = (char)lws_is_final_fragment(wsi); + pkt->binary = (char)lws_frame_is_binary(wsi); memcpy(((uint8_t *)&pkt[1]) + LWS_PRE, in, len); @@ -186,7 +186,7 @@ lws_callback_ws_proxy(struct lws *wsi, enum lws_callback_reasons reason, pkt = (struct lws_proxy_pkt *)dll; if (lws_write(wsi, ((unsigned char *)&pkt[1]) + - LWS_PRE, pkt->len, lws_write_ws_flags( + LWS_PRE, pkt->len, (enum lws_write_protocol)lws_write_ws_flags( pkt->binary ? LWS_WRITE_BINARY : LWS_WRITE_TEXT, pkt->first, pkt->final)) < 0) return -1; @@ -213,9 +213,9 @@ lws_callback_ws_proxy(struct lws *wsi, enum lws_callback_reasons reason, return -1; pkt->len = len; - pkt->first = lws_is_first_fragment(wsi); - pkt->final = lws_is_final_fragment(wsi); - pkt->binary = lws_frame_is_binary(wsi); + pkt->first = (char)lws_is_first_fragment(wsi); + pkt->final = (char)lws_is_final_fragment(wsi); + pkt->binary = (char)lws_frame_is_binary(wsi); memcpy(((uint8_t *)&pkt[1]) + LWS_PRE, in, len); @@ -230,7 +230,7 @@ lws_callback_ws_proxy(struct lws *wsi, enum lws_callback_reasons reason, pkt = (struct lws_proxy_pkt *)dll; if (lws_write(wsi, ((unsigned char *)&pkt[1]) + - LWS_PRE, pkt->len, lws_write_ws_flags( + LWS_PRE, pkt->len, (enum lws_write_protocol)lws_write_ws_flags( pkt->binary ? LWS_WRITE_BINARY : LWS_WRITE_TEXT, pkt->first, pkt->final)) < 0) return -1; @@ -337,9 +337,9 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_HEADERS) wsi->reason_bf &= - ~LWS_CB_REASON_AUX_BF__CGI_HEADERS; + (char)~LWS_CB_REASON_AUX_BF__CGI_HEADERS; else - wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__CGI; + wsi->reason_bf &= (char)~LWS_CB_REASON_AUX_BF__CGI; if (wsi->http.cgi && wsi->http.cgi->cgi_transaction_over) { lwsl_info("%s: txn over\n", __func__); @@ -371,7 +371,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__PROXY_HEADERS) { - wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__PROXY_HEADERS; + wsi->reason_bf &= (char)~LWS_CB_REASON_AUX_BF__PROXY_HEADERS; n = LWS_WRITE_HTTP_HEADERS; if (!wsi->http.prh_content_length) @@ -382,7 +382,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, (int)wsi->http.prh_content_length); n = lws_write(wsi, wsi->http.pending_return_headers + LWS_PRE, - wsi->http.pending_return_headers_len, n); + wsi->http.pending_return_headers_len, (enum lws_write_protocol)n); lws_free_set_NULL(wsi->http.pending_return_headers); @@ -406,7 +406,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, * suitable size to send or what's available, whichever * is the smaller. */ - wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__PROXY; + wsi->reason_bf &= (char)~LWS_CB_REASON_AUX_BF__PROXY; if (!lws_get_child(wsi)) break; @@ -427,7 +427,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, lwsl_info("%s: LWS_CB_REASON_AUX_BF__PROXY_TRANS_END\n", __func__); - wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__PROXY_TRANS_END; + wsi->reason_bf &= (char)~LWS_CB_REASON_AUX_BF__PROXY_TRANS_END; if (stream_close(wsi)) return -1; @@ -473,7 +473,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, n = lws_write(lws_get_parent(wsi), (unsigned char *)buf + LWS_PRE, - len + n + 2, LWS_WRITE_HTTP); + (size_t)(unsigned int)(len + (unsigned int)n + 2), LWS_WRITE_HTTP); } else n = lws_write(lws_get_parent(wsi), (unsigned char *)in, len, LWS_WRITE_HTTP); @@ -558,13 +558,13 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (lws_finalize_http_header(parent, &p, end)) return 1; - parent->http.prh_content_length = -1; + parent->http.prh_content_length = (size_t)-1; if (lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) - parent->http.prh_content_length = atoll( + parent->http.prh_content_length = (size_t)atoll( lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)); - parent->http.pending_return_headers_len = lws_ptr_diff(p, start); + parent->http.pending_return_headers_len = lws_ptr_diff_size_t(p, start); parent->http.pending_return_headers = lws_malloc(parent->http.pending_return_headers_len + LWS_PRE, "return proxy headers"); @@ -606,8 +606,8 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (!lws_get_parent(wsi)) break; // lwsl_err("%s: LWS_CALLBACK_CLOSED_CLIENT_HTTP\n", __func__); - lws_set_timeout(lws_get_parent(wsi), LWS_TO_KILL_ASYNC, - PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE); + lws_set_timeout(lws_get_parent(wsi), (enum pending_timeout)LWS_TO_KILL_ASYNC, + (int)PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE); break; case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: @@ -670,7 +670,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, n = lws_get_socket_fd(args->stdwsi[LWS_STDERR]); if (n < 0) break; - n = read(n, buf, sizeof(buf) - 2); + n = (int)read(n, buf, sizeof(buf) - 2); if (n > 0) { if (buf[n - 1] != '\n') buf[n++] = '\n'; @@ -732,7 +732,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, } wsi->http.cgi->inflate.next_in = args->data; - wsi->http.cgi->inflate.avail_in = args->len; + wsi->http.cgi->inflate.avail_in = (unsigned int)args->len; do { @@ -759,7 +759,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, sizeof(wsi->http.cgi->inflate_buf)) { int written; - written = write(args->stdwsi[LWS_STDIN]->desc.filefd, + written = (int)write(args->stdwsi[LWS_STDIN]->desc.filefd, wsi->http.cgi->inflate_buf, sizeof(wsi->http.cgi->inflate_buf) - wsi->http.cgi->inflate.avail_out); @@ -790,7 +790,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, } #endif /* WITH_ZLIB */ - n = write(n, args->data, args->len); + n = (int)write(n, args->data, (unsigned int)args->len); // lwsl_hexdump_notice(args->data, args->len); if (n < args->len) lwsl_notice("LWS_CALLBACK_CGI_STDIN_DATA: " @@ -800,7 +800,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, if (wsi->http.cgi->post_in_expected && args->stdwsi[LWS_STDIN] && args->stdwsi[LWS_STDIN]->desc.filefd > 0) { - wsi->http.cgi->post_in_expected -= n; + wsi->http.cgi->post_in_expected -= (unsigned int)n; if (!wsi->http.cgi->post_in_expected) { struct lws *siwsi = args->stdwsi[LWS_STDIN]; diff --git a/lib/core-net/lws-dsh.c b/lib/core-net/lws-dsh.c index 9a6a48725..46aec64dd 100644 --- a/lib/core-net/lws-dsh.c +++ b/lib/core-net/lws-dsh.c @@ -52,7 +52,7 @@ lws_dsh_align(size_t length) lws_dsh_t * lws_dsh_create(lws_dll2_owner_t *owner, size_t buf_len, int count_kinds) { - size_t oha_len = sizeof(lws_dsh_obj_head_t) * ++count_kinds; + size_t oha_len = sizeof(lws_dsh_obj_head_t) * (unsigned int)(++count_kinds); lws_dsh_obj_t *obj; lws_dsh_t *dsh; int n; diff --git a/lib/core-net/network.c b/lib/core-net/network.c index 1a26f2d55..f5e6b3ab3 100644 --- a/lib/core-net/network.c +++ b/lib/core-net/network.c @@ -57,7 +57,7 @@ lws_get_addresses(struct lws_vhost *vh, void *ads, char *name, if (LWS_IPV6_ENABLED(vh)) { if (!lws_plat_inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ads)->sin6_addr, - rip, rip_len)) { + rip, (socklen_t)rip_len)) { lwsl_err("inet_ntop: %s", strerror(LWS_ERRNO)); return -1; } @@ -67,7 +67,7 @@ lws_get_addresses(struct lws_vhost *vh, void *ads, char *name, memmove(rip, rip + 7, strlen(rip) - 6); getnameinfo((struct sockaddr *)ads, sizeof(struct sockaddr_in6), - name, name_len, NULL, 0, 0); + name, (socklen_t)name_len, NULL, 0, 0); return 0; } else @@ -81,7 +81,7 @@ lws_get_addresses(struct lws_vhost *vh, void *ads, char *name, #if !defined(LWS_PLAT_FREERTOS) if (getnameinfo((struct sockaddr *)ads, sizeof(struct sockaddr_in), - name, name_len, NULL, 0, 0)) + name, (unsigned int)name_len, NULL, 0, 0)) return -1; #endif @@ -106,7 +106,7 @@ lws_get_addresses(struct lws_vhost *vh, void *ads, char *name, if (addr4.sin_family == AF_UNSPEC) return -1; - if (lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len) == NULL) + if (lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, (unsigned int)rip_len) == NULL) return -1; return 0; @@ -243,7 +243,7 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, memset(&serv_addr6, 0, sizeof(serv_addr6)); if (iface) { m = interface_to_sa(vhost, iface, - (struct sockaddr_in *)v, n, 1); + (struct sockaddr_in *)v, (unsigned int)n, 1); if (m == LWS_ITOSA_NOT_USABLE) { lwsl_info("%s: netif %s: Not usable\n", __func__, iface); @@ -254,11 +254,11 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, __func__, iface); return m; } - serv_addr6.sin6_scope_id = lws_get_addr_scope(iface); + serv_addr6.sin6_scope_id = (unsigned int)lws_get_addr_scope(iface); } serv_addr6.sin6_family = AF_INET6; - serv_addr6.sin6_port = htons(port); + serv_addr6.sin6_port = (uint16_t)htons((uint16_t)port); } else #endif { @@ -271,7 +271,7 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, #if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) if (iface) { m = interface_to_sa(vhost, iface, - (struct sockaddr_in *)v, n, 0); + (struct sockaddr_in *)v, (unsigned int)n, 0); if (m == LWS_ITOSA_NOT_USABLE) { lwsl_info("%s: netif %s: Not usable\n", __func__, iface); @@ -284,14 +284,14 @@ lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, } } #endif - serv_addr4.sin_port = htons(port); + serv_addr4.sin_port = htons((uint16_t)(unsigned int)port); } /* ipv4 */ /* just checking for the interface extant */ if (sockfd == LWS_SOCK_INVALID) return LWS_ITOSA_USABLE; - n = bind(sockfd, v, n); + n = bind(sockfd, v, (unsigned int)n); #ifdef LWS_WITH_UNIX_SOCK if (n < 0 && LWS_UNIX_SOCK_ENABLED(vhost)) { lwsl_err("ERROR on binding fd %d to \"%s\" (%d %d)\n", @@ -423,7 +423,7 @@ lws_retry_sul_schedule(struct lws_context *context, int tid, lwsl_info("%s: sul %p: scheduling retry in %dms\n", __func__, sul, (int)ms); - lws_sul_schedule(context, tid, sul, cb, ms * 1000); + lws_sul_schedule(context, tid, sul, cb, (int64_t)(ms * 1000)); return 0; } @@ -655,7 +655,7 @@ lws_parse_numeric_address(const char *ads, uint8_t *result, size_t max_len) memset(result, 0, max_len); do { - ts.e = lws_tokenize(&ts); + ts.e = (int8_t)lws_tokenize(&ts); switch (ts.e) { case LWS_TOKZE_TOKEN: dm = 0; @@ -733,10 +733,10 @@ lws_parse_numeric_address(const char *ads, uint8_t *result, size_t max_len) */ if (ow == 16) return 16; - memcpy(temp, &orig[skip_point], ow - skip_point); - memset(&orig[skip_point], 0, 16 - skip_point); + memcpy(temp, &orig[skip_point], (unsigned int)(ow - skip_point)); + memset(&orig[skip_point], 0, (unsigned int)(16 - skip_point)); memcpy(&orig[16 - (ow - skip_point)], temp, - ow - skip_point); + (unsigned int)(ow - skip_point)); return 16; } @@ -788,7 +788,7 @@ lws_sa46_parse_numeric_address(const char *ads, lws_sockaddr46 *sa46) int lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len) { - char c, elided = 0, soe = 0, zb = -1, n, ipv4 = 0; + char c, elided = 0, soe = 0, zb = (char)-1, n, ipv4 = 0; const char *e = buf + len; char *obuf = buf; int q = 0; @@ -801,7 +801,7 @@ lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len) return -1; for (c = 0; c < (char)size / 2; c++) { - uint16_t v = (ads[q] << 8) | ads[q + 1]; + uint16_t v = (uint16_t)((ads[q] << 8) | ads[q + 1]); if (buf + 8 > e) return -1; @@ -819,7 +819,7 @@ lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len) } if (ipv4) { - n = lws_snprintf(buf, e - buf, "%u.%u", + n = (char)lws_snprintf(buf, lws_ptr_diff_size_t(e, buf), "%u.%u", ads[q - 2], ads[q - 1]); buf += n; if (c == 6) @@ -830,7 +830,7 @@ lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len) if (c) *buf++ = ':'; - buf += lws_snprintf(buf, e - buf, "%x", v); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(e, buf), "%x", v); if (soe && v) { soe = 0; @@ -954,7 +954,7 @@ lws_sa46_on_net(const lws_sockaddr46 *sa46a, const lws_sockaddr46 *sa46_net, while (net_len > 0) { if (net_len < 8) - mask <<= 8 - net_len; + mask = (uint8_t)(mask << (8 - net_len)); if (((*p1++) & mask) != ((*p2++) & mask)) return 1; @@ -968,7 +968,7 @@ lws_sa46_on_net(const lws_sockaddr46 *sa46a, const lws_sockaddr46 *sa46_net, void lws_sa46_copy_address(lws_sockaddr46 *sa46a, const void *in, int af) { - sa46a->sa4.sin_family = af; + sa46a->sa4.sin_family = (sa_family_t)af; if (af == AF_INET) memcpy(&sa46a->sa4.sin_addr, in, 4); diff --git a/lib/core-net/output.c b/lib/core-net/output.c index 0f4c98f13..0c46f2c43 100644 --- a/lib/core-net/output.c +++ b/lib/core-net/output.c @@ -105,25 +105,25 @@ lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) /* limit sending */ if (wsi->a.protocol->tx_packet_size) - n = (int)wsi->a.protocol->tx_packet_size; + n = (unsigned int)wsi->a.protocol->tx_packet_size; else { - n = (int)wsi->a.protocol->rx_buffer_size; + n = (unsigned int)wsi->a.protocol->rx_buffer_size; if (!n) n = context->pt_serv_buf_size; } n += LWS_PRE + 4; if (n > len) - n = (int)len; + n = (unsigned int)len; /* nope, send it on the socket directly */ - m = lws_ssl_capable_write(wsi, buf, n); + m = (unsigned int)lws_ssl_capable_write(wsi, buf, n); lwsl_info("%s: ssl_capable_write (%d) says %d\n", __func__, n, m); /* something got written, it can have been truncated now */ wsi->could_have_pending = 1; - switch (m) { + switch ((int)m) { case LWS_SSL_CAPABLE_ERROR: /* we're going to close, let close know sends aren't possible */ wsi->socket_is_permanently_unusable = 1; @@ -157,7 +157,7 @@ lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) lwsl_info("%s: %s: buflist_out flushed\n", __func__, lws_wsi_tag(wsi)); - m = (int)real_len; + m = (unsigned int)real_len; if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE) { lwsl_info("*%s signalling to close now\n", lws_wsi_tag(wsi)); @@ -190,7 +190,7 @@ lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) /* always callback on writeable */ lws_callback_on_writable(wsi); - return m; + return (int)m; } #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) @@ -200,7 +200,7 @@ lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) if (m == real_len) /* what we just sent went out cleanly */ - return m; + return (int)m; /* * We were not able to send everything... and we were not sending from @@ -274,14 +274,14 @@ lws_write(struct lws *wsi, unsigned char *buf, size_t len, #if defined(LWS_WITH_DETAILED_LATENCY) if (wsi->a.context->detailed_latency_cb) { wsi->detlat.req_size = len; - wsi->detlat.acc_size = m; + wsi->detlat.acc_size = (unsigned int)m; wsi->detlat.type = LDLT_WRITE; if (wsi->detlat.earliest_write_req_pre_write) wsi->detlat.latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE] = - us - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(us - wsi->detlat.earliest_write_req_pre_write); else wsi->detlat.latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE] = 0; - wsi->detlat.latencies[LAT_DUR_USERCB] = lws_now_usecs() - us; + wsi->detlat.latencies[LAT_DUR_USERCB] = (uint32_t)(lws_now_usecs() - us); lws_det_lat_cb(wsi->a.context, &wsi->detlat); } @@ -291,7 +291,7 @@ lws_write(struct lws *wsi, unsigned char *buf, size_t len, } int -lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) { struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; @@ -304,11 +304,19 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len) if (lws_wsi_is_udp(wsi)) { socklen_t slt = sizeof(wsi->udp->sa46); - n = recvfrom(wsi->desc.sockfd, (char *)buf, len, 0, + n = (int)recvfrom(wsi->desc.sockfd, (char *)buf, +#if defined(WIN32) + (int) +#endif + len, 0, sa46_sockaddr(&wsi->udp->sa46), &slt); } else #endif - n = recv(wsi->desc.sockfd, (char *)buf, len, 0); + n = (int)recv(wsi->desc.sockfd, (char *)buf, +#if defined(WIN32) + (int) +#endif + len, 0); if (n >= 0) { @@ -324,9 +332,9 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len) #if defined(LWS_WITH_SERVER_STATUS) if (wsi->a.vhost) - wsi->a.vhost->conn_stats.rx += n; + wsi->a.vhost->conn_stats.rx = (unsigned long long)(wsi->a.vhost->conn_stats.rx + (unsigned long long)(long long)n); #endif - lws_stats_bump(pt, LWSSTATS_B_READ, n); + lws_stats_bump(pt, LWSSTATS_B_READ, (unsigned int)n); return n; } @@ -341,7 +349,7 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len) } int -lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) { int n = 0; #if defined(LWS_PLAT_OPTEE) @@ -361,25 +369,39 @@ lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len) wsi->a.context->udp_loss_sim_tx_pc) { lwsl_warn("%s: dropping udp tx\n", __func__); /* pretend it was sent */ - n = len; + n = (int)(ssize_t)len; goto post_send; } } if (lws_has_buffered_out(wsi)) - n = sendto(wsi->desc.sockfd, (const char *)buf, + n = (int)sendto(wsi->desc.sockfd, (const char *)buf, +#if defined(WIN32) + (int) +#endif len, 0, sa46_sockaddr(&wsi->udp->sa46_pending), sa46_socklen(&wsi->udp->sa46_pending)); else - n = sendto(wsi->desc.sockfd, (const char *)buf, + n = (int)sendto(wsi->desc.sockfd, (const char *)buf, +#if defined(WIN32) + (int) +#endif len, 0, sa46_sockaddr(&wsi->udp->sa46), sa46_socklen(&wsi->udp->sa46)); } else #endif if (wsi->role_ops->file_handle) - n = write((int)(lws_intptr_t)wsi->desc.filefd, buf, len); + n = (int)write((int)(lws_intptr_t)wsi->desc.filefd, buf, +#if defined(WIN32) + (int) +#endif + len); else - n = send(wsi->desc.sockfd, (char *)buf, len, MSG_NOSIGNAL); + n = (int)send(wsi->desc.sockfd, (char *)buf, +#if defined(WIN32) + (int) +#endif + len, MSG_NOSIGNAL); // lwsl_info("%s: sent len %d result %d", __func__, len, n); #if defined(LWS_WITH_UDP) @@ -399,7 +421,7 @@ post_send: } lwsl_debug("ERROR writing len %d to skt fd %d err %d / errno %d\n", - len, wsi->desc.sockfd, n, LWS_ERRNO); + (int)(ssize_t)len, wsi->desc.sockfd, n, LWS_ERRNO); return LWS_SSL_CAPABLE_ERROR; } diff --git a/lib/core-net/pollfd.c b/lib/core-net/pollfd.c index d31f9aa36..20868820e 100644 --- a/lib/core-net/pollfd.c +++ b/lib/core-net/pollfd.c @@ -150,7 +150,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) lwsl_debug("%s: %s: fd %d events %d -> %d\n", __func__, lws_wsi_tag(wsi), pa->fd, pfd->events, (pfd->events & ~_and) | _or); pa->prev_events = pfd->events; - pa->events = pfd->events = (pfd->events & ~_and) | _or; + pa->events = pfd->events = (short)((pfd->events & ~_and) | _or); if (wsi->mux_substream) return 0; @@ -287,7 +287,7 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) #if !defined(_WIN32) if (!wsi->a.context->max_fds_unrelated_to_ulimit && - wsi->desc.sockfd - lws_plat_socket_offset() >= context->max_fds) { + wsi->desc.sockfd - lws_plat_socket_offset() >= (int)context->max_fds) { lwsl_err("Socket fd %d is too high (%d) offset %d\n", wsi->desc.sockfd, context->max_fds, lws_plat_socket_offset()); @@ -315,7 +315,7 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) if (insert_wsi(context, wsi)) return -1; pt->count_conns++; - wsi->position_in_fds_table = pt->fds_count; + wsi->position_in_fds_table = (int)pt->fds_count; pt->fds[wsi->position_in_fds_table].fd = wsi->desc.sockfd; pt->fds[wsi->position_in_fds_table].events = LWS_POLLIN; @@ -368,7 +368,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) #if !defined(_WIN32) if (!wsi->a.context->max_fds_unrelated_to_ulimit && - wsi->desc.sockfd - lws_plat_socket_offset() > context->max_fds) { + wsi->desc.sockfd - lws_plat_socket_offset() > (int)context->max_fds) { lwsl_err("fd %d too high (%d)\n", wsi->desc.sockfd, context->max_fds); @@ -583,7 +583,7 @@ lws_same_vh_protocol_insert(struct lws *wsi, int n) lws_dll2_add_head(&wsi->same_vh_protocol, &wsi->a.vhost->same_vh_protocol_owner[n]); - wsi->bound_vhost_index = n; + wsi->bound_vhost_index = (uint8_t)n; lws_vhost_unlock(wsi->a.vhost); } diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 65c425aa0..a29e82f26 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -53,7 +53,7 @@ extern "C" { #endif #define __lws_sul_insert_us(owner, sul, _us) \ - (sul)->us = lws_now_usecs() + _us; \ + (sul)->us = lws_now_usecs() + (lws_usec_t)(_us); \ __lws_sul_insert(owner, sul) @@ -603,7 +603,7 @@ __lws_vhost_destroy2(struct lws_vhost *vh); #define mux_to_wsi(_m) lws_container_of(_m, struct lws, mux) void -lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, int sid); +lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, unsigned int sid); int lws_wsi_mux_mark_parents_needing_writeable(struct lws *wsi); struct lws * @@ -1125,7 +1125,7 @@ int _lws_plat_service_forced_tsi(struct lws_context *context, int tsi); int -lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len); +lws_rxflow_cache(struct lws *wsi, unsigned char *buf, size_t n, size_t len); int lws_service_flag_pending(struct lws_context *context, int tsi); @@ -1365,7 +1365,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi); int lws_pthread_self_to_tsi(struct lws_context *context); const char * LWS_WARN_UNUSED_RESULT -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt); +lws_plat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt); int LWS_WARN_UNUSED_RESULT lws_plat_inet_pton(int af, const char *src, void *dst); diff --git a/lib/core-net/sequencer.c b/lib/core-net/sequencer.c index 42b43cd33..aa6a0cbce 100644 --- a/lib/core-net/sequencer.c +++ b/lib/core-net/sequencer.c @@ -198,7 +198,7 @@ lws_seq_sul_pending_cb(lws_sorted_usec_list_t *sul) dh = lws_dll2_get_head(&seq->seq_event_owner); seqe = lws_container_of(dh, lws_seq_event_t, seq_event_list); - n = seq->cb(seq, (void *)&seq[1], seqe->e, seqe->data, seqe->aux); + n = (int)seq->cb(seq, (void *)&seq[1], (int)seqe->e, seqe->data, seqe->aux); /* ... have to lock here though, because we will change the list */ diff --git a/lib/core-net/server.c b/lib/core-net/server.c index 79d041ba5..00a92671f 100644 --- a/lib/core-net/server.c +++ b/lib/core-net/server.c @@ -68,7 +68,7 @@ lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len) if (len < 100) return 0; - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "{\n \"name\":\"%s\",\n" " \"port\":\"%d\",\n" " \"use_ssl\":\"%d\",\n" @@ -105,12 +105,12 @@ lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len) if (vh->http.mount_list) { const struct lws_http_mount *m = vh->http.mount_list; - buf += lws_snprintf(buf, end - buf, ",\n \"mounts\":["); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ",\n \"mounts\":["); first = 1; while (m) { if (!first) - buf += lws_snprintf(buf, end - buf, ","); - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ","); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n {\n \"mountpoint\":\"%s\",\n" " \"origin\":\"%s%s\",\n" " \"cache_max_age\":\"%d\",\n" @@ -126,25 +126,25 @@ lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len) m->cache_revalidate, m->cache_intermediaries); if (m->def) - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ",\n \"default\":\"%s\"", m->def); - buf += lws_snprintf(buf, end - buf, "\n }"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n }"); first = 0; m = m->mount_next; } - buf += lws_snprintf(buf, end - buf, "\n ]"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n ]"); } #endif if (vh->protocols) { n = 0; first = 1; - buf += lws_snprintf(buf, end - buf, ",\n \"ws-protocols\":["); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ",\n \"ws-protocols\":["); while (n < vh->count_protocols) { if (!first) - buf += lws_snprintf(buf, end - buf, ","); - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ","); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n {\n \"%s\":{\n" " \"status\":\"ok\"\n }\n }" , @@ -152,12 +152,12 @@ lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len) first = 0; n++; } - buf += lws_snprintf(buf, end - buf, "\n ]"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n ]"); } - buf += lws_snprintf(buf, end - buf, "\n}"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n}"); - return buf - orig; + return lws_ptr_diff(buf, orig); } @@ -179,7 +179,7 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, // uv_uptime(&d); //#endif - buf += lws_snprintf(buf, end - buf, "{ " + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "{ " "\"version\":\"%s\",\n" "\"uptime\":\"%ld\",\n", lws_get_library_version(), @@ -195,7 +195,7 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, m = getloadavg(d, 3); for (n = 0; n < m; n++) { - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\"l%d\":\"%.2f\",\n", n + 1, d[n]); } @@ -205,23 +205,23 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, fd = lws_open("/proc/self/statm", LWS_O_RDONLY); if (fd >= 0) { char contents[96], pure[96]; - n = read(fd, contents, sizeof(contents) - 1); + n = (int)read(fd, contents, sizeof(contents) - 1); if (n > 0) { contents[n] = '\0'; if (contents[n - 1] == '\n') contents[--n] = '\0'; lws_json_purify(pure, contents, sizeof(pure), NULL); - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\"statm\": \"%s\",\n", pure); } close(fd); } - buf += lws_snprintf(buf, end - buf, "\"heap\":%lld,\n\"contexts\":[\n", + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\"heap\":%lld,\n\"contexts\":[\n", (long long)lws_get_allocated_heap()); - buf += lws_snprintf(buf, end - buf, "{ " + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "{ " "\"context_uptime\":\"%llu\",\n" "\"cgi_spawned\":\"%d\",\n" "\"pt_fd_max\":\"%d\",\n" @@ -234,12 +234,12 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, context->max_http_header_pool, context->deprecated); - buf += lws_snprintf(buf, end - buf, "\"pt\":[\n "); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\"pt\":[\n "); for (n = 0; n < context->count_threads; n++) { pt = &context->pt[n]; if (n) - buf += lws_snprintf(buf, end - buf, ","); - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ","); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "\n {\n" " \"fds_count\":\"%d\",\n" " \"ah_pool_inuse\":\"%d\",\n" @@ -252,9 +252,9 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, pt->count_wsi_allocated); } - buf += lws_snprintf(buf, end - buf, "]"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "]"); - buf += lws_snprintf(buf, end - buf, ", \"vhosts\":[\n "); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ", \"vhosts\":[\n "); first = 1; vh = context->vhost_list; @@ -265,9 +265,9 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, if (!hide_vhosts) { if (!first) - if(buf != end) + if (buf != end) *buf++ = ','; - buf += lws_json_dump_vhost(vh, buf, end - buf); + buf += lws_json_dump_vhost(vh, buf, lws_ptr_diff(end, buf)); first = 0; } if (vh->lserv_wsi) @@ -275,7 +275,7 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, vh = vh->vhost_next; } - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "],\n\"listen_wsi\":\"%d\",\n" " \"rx\":\"%llu\",\n" " \"tx\":\"%llu\",\n" @@ -309,15 +309,15 @@ lws_json_dump_context(const struct lws_context *context, char *buf, int len, } } #endif - buf += lws_snprintf(buf, end - buf, ",\n \"cgi_alive\":\"%d\"\n ", + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), ",\n \"cgi_alive\":\"%d\"\n ", cgi_count); - buf += lws_snprintf(buf, end - buf, "}"); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "}"); - buf += lws_snprintf(buf, end - buf, "]}\n "); + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "]}\n "); - return buf - orig; + return lws_ptr_diff(buf, orig); } #endif diff --git a/lib/core-net/service.c b/lib/core-net/service.c index 1eda1619b..080c271dc 100644 --- a/lib/core-net/service.c +++ b/lib/core-net/service.c @@ -49,7 +49,7 @@ lws_callback_as_writeable(struct lws *wsi) wsi->detlat.earliest_write_req; wsi->detlat.earliest_write_req = 0; wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = - ((uint32_t)us - wsi->detlat.earliest_write_req_pre_write); + (uint32_t)(us - wsi->detlat.earliest_write_req_pre_write); } #endif n = wsi->role_ops->writeable_cb[lwsi_role_server(wsi)]; @@ -249,7 +249,7 @@ bail_die: } int -lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len) +lws_rxflow_cache(struct lws *wsi, unsigned char *buf, size_t n, size_t len) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; uint8_t *buffered; @@ -279,7 +279,7 @@ lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len) /* a new rxflow, buffer it and warn caller */ - lwsl_debug("%s: rxflow append %d\n", __func__, len - n); + lwsl_debug("%s: rxflow append %d\n", __func__, (int)(len - n)); m = lws_buflist_append_segment(&wsi->buflist, buf + n, len - n); if (m < 0) @@ -391,7 +391,7 @@ lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, ebuf->token = pt->serv_buf + LWS_PRE; if (!ebuf->len || (unsigned int)ebuf->len > wsi->a.context->pt_serv_buf_size - LWS_PRE) - ebuf->len = wsi->a.context->pt_serv_buf_size - LWS_PRE; + ebuf->len = (int)(wsi->a.context->pt_serv_buf_size - LWS_PRE); e = ebuf->len; ep = ebuf->token; @@ -412,7 +412,7 @@ lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, /* we're going to read something */ ebuf->token = ep; - ebuf->len = n = lws_ssl_capable_read(wsi, ep, e); + ebuf->len = n = lws_ssl_capable_read(wsi, ep, (size_t)e); lwsl_debug("%s: %s: %s: ssl_capable_read %d\n", __func__, lws_wsi_tag(wsi), hint, ebuf->len); @@ -437,7 +437,7 @@ lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, * Stash what we read, since there's earlier buflist material */ - n = lws_buflist_append_segment(&wsi->buflist, ebuf->token, ebuf->len); + n = lws_buflist_append_segment(&wsi->buflist, ebuf->token, (size_t)ebuf->len); if (n < 0) return -1; if (n && lws_dll2_is_detached(&wsi->dll_buflist)) @@ -498,12 +498,12 @@ lws_buflist_aware_finished_consuming(struct lws *wsi, struct lws_tokens *ebuf, /* any remainder goes on the buflist */ - if (used != ebuf->len) { + if (used < ebuf->len && ebuf->len >= 0 && used >= 0) { // lwsl_notice("%s %s bac appending %d\n", __func__, hint, // ebuf->len - used); m = lws_buflist_append_segment(&wsi->buflist, ebuf->token + used, - ebuf->len - used); + (unsigned int)(ebuf->len - used)); if (m < 0) return 1; /* OOM */ if (m) { @@ -618,9 +618,10 @@ lws_service_flag_pending(struct lws_context *context, int tsi) if (wsi->position_in_fds_table >= 0) { - pt->fds[wsi->position_in_fds_table].revents |= - pt->fds[wsi->position_in_fds_table].events & - LWS_POLLIN; + pt->fds[wsi->position_in_fds_table].revents = (short)( + pt->fds[wsi->position_in_fds_table].revents | + (pt->fds[wsi->position_in_fds_table].events & + LWS_POLLIN)); if (pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN) /* diff --git a/lib/core-net/socks5-client.c b/lib/core-net/socks5-client.c index 975f204c3..f0db8f8c3 100644 --- a/lib/core-net/socks5-client.c +++ b/lib/core-net/socks5-client.c @@ -61,9 +61,9 @@ lws_set_socks(struct lws_vhost *vhost, const char *socks) } lws_strncpy(vhost->socks_user, socks, - p_colon - socks + 1); + lws_ptr_diff_size_t(p_colon, socks) + 1); lws_strncpy(vhost->socks_password, p_colon + 1, - p_at - (p_colon + 1) + 1); + lws_ptr_diff_size_t(p_at, (p_colon + 1)) + 1); } lwsl_info(" Socks auth, user: %s, password: %s\n", @@ -82,7 +82,7 @@ lws_set_socks(struct lws_vhost *vhost, const char *socks) } else { if (p_colon) { *p_colon = '\0'; - vhost->socks_proxy_port = atoi(p_colon + 1); + vhost->socks_proxy_port = (unsigned int)atoi(p_colon + 1); } } @@ -121,8 +121,8 @@ lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, break; case SOCKS_MSG_USERNAME_PASSWORD: - n = strlen(wsi->a.vhost->socks_user); - passwd_len = strlen(wsi->a.vhost->socks_password); + n = (ssize_t)strlen(wsi->a.vhost->socks_user); + passwd_len = (ssize_t)strlen(wsi->a.vhost->socks_password); if (n > 254 || passwd_len > 254) return 1; @@ -134,21 +134,21 @@ lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, *p++ = SOCKS_SUBNEGOTIATION_VERSION_1; /* length of the user name */ - *p++ = n; + *p++ = (uint8_t)n; /* user name */ - memcpy(p, wsi->a.vhost->socks_user, n); - p += n; + memcpy(p, wsi->a.vhost->socks_user, (size_t)n); + p += (uint8_t)n; /* length of the password */ - *p++ = passwd_len; + *p++ = (uint8_t)passwd_len; /* password */ - memcpy(p, wsi->a.vhost->socks_password, passwd_len); + memcpy(p, wsi->a.vhost->socks_password, (size_t)passwd_len); p += passwd_len; break; case SOCKS_MSG_CONNECT: - n = strlen(wsi->stash->cis[CIS_ADDRESS]); + n = (ssize_t)strlen(wsi->stash->cis[CIS_ADDRESS]); if (n > 254 || lws_ptr_diff(end, p) < 5 + n + 2) return 1; @@ -164,17 +164,17 @@ lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, /* address type */ *p++ = SOCKS_ATYP_DOMAINNAME; /* length of ---> */ - *p++ = n; + *p++ = (uint8_t)n; /* the address we tell SOCKS proxy to connect to */ - memcpy(p, wsi->stash->cis[CIS_ADDRESS], n); + memcpy(p, wsi->stash->cis[CIS_ADDRESS], (size_t)n); p += n; - net_num = htons(wsi->c_port); + net_num = (short)htons(wsi->c_port); /* the port we tell SOCKS proxy to connect to */ - *p++ = cp[0]; - *p++ = cp[1]; + *p++ = (uint8_t)cp[0]; + *p++ = (uint8_t)cp[1]; break; @@ -232,7 +232,7 @@ lws_socks5c_greet(struct lws *wsi, const char **pcce) return -1; } // lwsl_hexdump_notice(pt->serv_buf, plen); - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, plen, + n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, (size_t)plen, MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing socks greeting\n"); @@ -241,7 +241,7 @@ lws_socks5c_greet(struct lws *wsi, const char **pcce) } lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); lwsi_set_state(wsi, LRS_WAITING_SOCKS_GREETING_REPLY); @@ -266,7 +266,7 @@ lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd, return LW5CHS_RET_BAIL3; } - n = recv(wsi->desc.sockfd, pt->serv_buf, + n = (int)recv(wsi->desc.sockfd, pt->serv_buf, wsi->a.context->pt_serv_buf_size, 0); if (n < 0) { if (LWS_ERRNO == LWS_EAGAIN) { @@ -330,7 +330,7 @@ socks_send_msg_fail: PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; socks_send: // lwsl_hexdump_notice(pt->serv_buf, len); - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, len, + n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, (size_t)len, MSG_NOSIGNAL); if (n < 0) { lwsl_debug("ERROR writing to socks proxy\n"); @@ -338,9 +338,9 @@ socks_send: return LW5CHS_RET_BAIL3; } - lws_set_timeout(wsi, pending_timeout, - wsi->a.context->timeout_secs); - lwsi_set_state(wsi, conn_mode); + lws_set_timeout(wsi, (enum pending_timeout)pending_timeout, + (int)wsi->a.context->timeout_secs); + lwsi_set_state(wsi, (lws_wsi_state_t)conn_mode); break; socks_reply_fail: @@ -365,7 +365,7 @@ socks_reply_fail: } #endif - wsi->c_port = wsi->a.vhost->socks_proxy_port; + wsi->c_port = (uint16_t)wsi->a.vhost->socks_proxy_port; /* clear his proxy connection timeout */ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 7b251532e..f69963680 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -240,7 +240,7 @@ lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, /* allocate the vh priv array only on demand */ if (!vhost->protocol_vh_privs) { vhost->protocol_vh_privs = (void **)lws_zalloc( - vhost->count_protocols * sizeof(void *), + (size_t)vhost->count_protocols * sizeof(void *), "protocol_vh_privs"); if (!vhost->protocol_vh_privs) return NULL; @@ -259,7 +259,7 @@ lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, return NULL; } - vhost->protocol_vh_privs[n] = lws_zalloc(size, "vh priv"); + vhost->protocol_vh_privs[n] = lws_zalloc((size_t)size, "vh priv"); return vhost->protocol_vh_privs[n]; } @@ -347,14 +347,14 @@ lws_protocol_init_vhost(struct lws_vhost *vh, int *any) "protocol for vh %s to %s\n", vh->name, vh->protocols[n].name); - vh->default_protocol_index = n; + vh->default_protocol_index = (unsigned char)n; } if (!strcmp(pvo->name, "raw")) { lwsl_info("Setting raw " "protocol for vh %s to %s\n", vh->name, vh->protocols[n].name); - vh->raw_protocol_index = n; + vh->raw_protocol_index = (unsigned char)n; } pvo = pvo->next; } @@ -529,7 +529,7 @@ lws_create_vhost(struct lws_context *context, #endif #if defined(LWS_WITH_CLIENT) if (info->connect_timeout_secs) - vh->connect_timeout_secs = info->connect_timeout_secs; + vh->connect_timeout_secs = (int)info->connect_timeout_secs; else vh->connect_timeout_secs = 20; #endif @@ -579,7 +579,7 @@ lws_create_vhost(struct lws_context *context, vh->keepalive_timeout = 5; if (info->timeout_secs_ah_idle) - vh->timeout_secs_ah_idle = info->timeout_secs_ah_idle; + vh->timeout_secs_ah_idle = (int)info->timeout_secs_ah_idle; else vh->timeout_secs_ah_idle = 10; @@ -601,11 +601,11 @@ lws_create_vhost(struct lws_context *context, if (n) { vh->tls.key_path = vh->tls.alloc_cert_path = - lws_malloc(n, "vh paths"); + lws_malloc((unsigned int)n, "vh paths"); if (info->ssl_cert_filepath) { n = (int)strlen(info->ssl_cert_filepath) + 1; memcpy(vh->tls.alloc_cert_path, - info->ssl_cert_filepath, n); + info->ssl_cert_filepath, (unsigned int)n); vh->tls.key_path += n; } if (info->ssl_private_key_filepath) @@ -633,10 +633,11 @@ lws_create_vhost(struct lws_context *context, * - his user protocols */ lwsp = lws_zalloc(sizeof(struct lws_protocols) * - (vh->count_protocols + - abs_pcol_count + sec_pcol_count + - context->plugin_protocol_count + - fx + 1), + ((unsigned int)vh->count_protocols + + (unsigned int)abs_pcol_count + + (unsigned int)sec_pcol_count + + (unsigned int)context->plugin_protocol_count + + (unsigned int)fx + 1), "vhost-specific plugin table"); if (!lwsp) { lwsl_err("OOM\n"); @@ -652,7 +653,7 @@ lws_create_vhost(struct lws_context *context, for (n = 0; n < m; n++) memcpy(&lwsp[n], info->pprotocols[n], sizeof(lwsp[0])); } else - memcpy(lwsp, pcols, sizeof(struct lws_protocols) * m); + memcpy(lwsp, pcols, sizeof(struct lws_protocols) * (unsigned int)m); /* * 2: abstract protocols @@ -727,7 +728,7 @@ lws_create_vhost(struct lws_context *context, vh->same_vh_protocol_owner = (struct lws_dll2_owner *) lws_zalloc(sizeof(struct lws_dll2_owner) * - vh->count_protocols, "same vh list"); + (unsigned int)vh->count_protocols, "same vh list"); #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) vh->http.mount_list = info->mounts; #endif @@ -819,7 +820,7 @@ lws_create_vhost(struct lws_context *context, goto bail; } #ifndef WIN32 - if (context->uid != -1) + if (context->uid != (uid_t)-1) if (chown(info->log_filepath, context->uid, context->gid) == -1) lwsl_err("unable to chown log file %s\n", @@ -1356,7 +1357,7 @@ lws_vhost_destroy(struct lws_vhost *vh) /* part 2 is deferred to allow all the handle closes to complete */ df->next = vh->context->deferred_free_list; - df->deadline = lws_now_secs(); + df->deadline = (long)lws_now_secs(); df->payload = vh; vh->context->deferred_free_list = df; diff --git a/lib/core-net/wsi-timeout.c b/lib/core-net/wsi-timeout.c index bef81edb7..a51a34ec9 100644 --- a/lib/core-net/wsi-timeout.c +++ b/lib/core-net/wsi-timeout.c @@ -136,7 +136,7 @@ __lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs) lwsl_debug("%s: %s: %d secs, reason %d\n", __func__, lws_wsi_tag(wsi), secs, reason); - wsi->pending_timeout = reason; + wsi->pending_timeout = (char)reason; } void @@ -194,7 +194,7 @@ lws_set_timeout_us(struct lws *wsi, enum pending_timeout reason, lws_usec_t us) lwsl_notice("%s: %s: %llu us, reason %d\n", __func__, lws_wsi_tag(wsi), (unsigned long long)us, reason); - wsi->pending_timeout = reason; + wsi->pending_timeout = (char)reason; lws_pt_unlock(pt); } diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c index f494af1e1..c96a0cb21 100644 --- a/lib/core-net/wsi.c +++ b/lib/core-net/wsi.c @@ -43,7 +43,7 @@ void lwsi_set_role(struct lws *wsi, lws_wsi_state_t role) void lwsi_set_state(struct lws *wsi, lws_wsi_state_t lrs) { - wsi->wsistate = (wsi->wsistate & (~LRS_MASK)) | lrs; + wsi->wsistate = (wsi->wsistate & (unsigned int)(~LRS_MASK)) | lrs; lwsl_debug("lwsi_set_state(%s, 0x%lx)\n", lws_wsi_tag(wsi), (unsigned long)wsi->wsistate); @@ -144,8 +144,9 @@ lws_callback_all_protocol(struct lws_context *context, if (!wsi) continue; if (wsi->a.protocol == protocol) - protocol->callback(wsi, reason, wsi->user_space, - NULL, 0); + protocol->callback(wsi, + (enum lws_callback_reasons)reason, + wsi->user_space, NULL, 0); } pt++; } @@ -170,7 +171,7 @@ lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, continue; if (wsi->a.vhost == vh && (wsi->a.protocol == protocol || !protocol)) - wsi->a.protocol->callback(wsi, reason, + wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)reason, wsi->user_space, argp, len); } pt++; @@ -187,12 +188,12 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, } int -lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, size_t len) { int n; for (n = 0; n < wsi->a.vhost->count_protocols; n++) - if (wsi->a.vhost->protocols[n].callback(wsi, reason, NULL, in, len)) + if (wsi->a.vhost->protocols[n].callback(wsi, (enum lws_callback_reasons)reason, NULL, in, len)) return 1; return 0; @@ -232,7 +233,7 @@ __lws_wsi_create_with_role(struct lws_context *context, int tsi, lws_role_transition(wsi, 0, LRS_UNCONNECTED, ops); wsi->pending_timeout = NO_PENDING_TIMEOUT; wsi->a.protocol = NULL; - wsi->tsi = tsi; + wsi->tsi = (char)tsi; wsi->a.vhost = NULL; wsi->desc.sockfd = LWS_SOCK_INVALID; wsi->position_in_fds_table = LWS_NO_FDS_POS; @@ -313,7 +314,7 @@ lws_callback_vhost_protocols_vhost(struct lws_vhost *vh, int reason, void *in, for (n = 0; n < wsi->a.vhost->count_protocols; n++) { wsi->a.protocol = &vh->protocols[n]; - if (wsi->a.protocol->callback(wsi, reason, NULL, in, len)) { + if (wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)reason, NULL, in, len)) { lws_free(wsi); return 1; } @@ -352,9 +353,9 @@ lws_rx_flow_control(struct lws *wsi, int _enable) /* any bit set in rxflow_bitmap DISABLEs rxflow control */ if (en & LWS_RXFLOW_REASON_APPLIES_ENABLE_BIT) - wsi->rxflow_bitmap &= ~(en & 0xff); + wsi->rxflow_bitmap &= (uint8_t)~(en & 0xff); else - wsi->rxflow_bitmap |= en & 0xff; + wsi->rxflow_bitmap |= (uint8_t)(en & 0xff); if ((LWS_RXFLOW_PENDING_CHANGE | (!wsi->rxflow_bitmap)) == wsi->rxflow_change_to) @@ -448,7 +449,7 @@ __lws_rx_flow_control(struct lws *wsi) /* now the pending is cleared, we can change rxflow state */ - wsi->rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE; + wsi->rxflow_change_to &= (~LWS_RXFLOW_PENDING_CHANGE) & 3; lwsl_info("rxflow: %s change_to %d\n", lws_wsi_tag(wsi), wsi->rxflow_change_to & LWS_RXFLOW_ALLOW); @@ -560,7 +561,7 @@ lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state, #if (_LWS_ENABLED_LOGS & LLL_DEBUG) const char *name = "(unset)"; #endif - wsi->wsistate = role | state; + wsi->wsistate = (unsigned int)role | (unsigned int)state; if (ops) wsi->role_ops = ops; #if (_LWS_ENABLED_LOGS & LLL_DEBUG) @@ -630,7 +631,8 @@ lws_parse_uri(char *p, const char **prot, const char **ads, int *port, const char * lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len) { - int n = 0, sl = (int)strlen(name); + int n = 0; + size_t sl = strlen(name); while (lws_hdr_copy_fragment(wsi, buf, len, WSI_TOKEN_HTTP_URI_ARGS, n) >= 0) { @@ -724,7 +726,7 @@ lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t le lws_fakewsi_prep_plwsa_ctx(pt->context); #if !defined(LWS_PLAT_FREERTOS) && LWS_MAX_SMP > 1 - ((struct lws *)plwsa)->tsi = (int)(pt - &pt->context->pt[0]); + ((struct lws *)plwsa)->tsi = (char)(int)(pt - &pt->context->pt[0]); #endif while (v) { @@ -735,7 +737,7 @@ lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t le for (n = 0; n < v->count_protocols; n++) { plwsa->protocol = p; if (p->callback && - p->callback((struct lws *)plwsa, reason, NULL, in, len)) + p->callback((struct lws *)plwsa, (enum lws_callback_reasons)reason, NULL, in, len)) ret |= 1; p++; } @@ -1209,7 +1211,7 @@ lws_wsi_client_stash_item(struct lws *wsi, int stash_idx, int hdr_idx) #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) /* if not, use the ah stash if applicable */ - return lws_hdr_simple_ptr(wsi, hdr_idx); + return lws_hdr_simple_ptr(wsi, (enum lws_token_indexes)hdr_idx); #else return NULL; #endif @@ -1219,7 +1221,7 @@ lws_wsi_client_stash_item(struct lws *wsi, int stash_idx, int hdr_idx) #if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT) void -lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, int sid) +lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, unsigned int sid) { lwsl_info("%s: %s, par %s: assign sid %d (curr %d)\n", __func__, lws_wsi_tag(wsi), lws_wsi_tag(parent_wsi), sid, wsi->mux.my_sid); @@ -1285,7 +1287,7 @@ lws_wsi_mux_close_children(struct lws *wsi, int reason) assert (wsi2 != *w); (*w)->mux.sibling_list = NULL; (*w)->socket_is_permanently_unusable = 1; - __lws_close_free_wsi(*w, reason, "mux child recurse"); + __lws_close_free_wsi(*w, (enum lws_close_status)reason, "mux child recurse"); *w = wsi2; } } diff --git a/lib/core/buflist.c b/lib/core/buflist.c index 8f2f25361..b89330ad7 100644 --- a/lib/core/buflist.c +++ b/lib/core/buflist.c @@ -149,7 +149,7 @@ lws_buflist_use_segment(struct lws_buflist **head, size_t len) assert(b->pos <= b->len); if (b->pos < b->len) - return (int)(b->len - b->pos); + return (unsigned int)(b->len - b->pos); if (lws_buflist_destroy_segment(head)) /* last segment was just destroyed */ diff --git a/lib/core/context.c b/lib/core/context.c index 350cc3d2b..822623ef3 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -391,7 +391,7 @@ lws_create_context(const struct lws_context_creation_info *info) pid_t pid_daemon = get_daemonize_pid(); #endif #if defined(LWS_WITH_NETWORK) - int count_threads = 1; + unsigned short count_threads = 1; uint8_t *u; #endif #if defined(__ANDROID__) @@ -405,7 +405,8 @@ lws_create_context(const struct lws_context_creation_info *info) s1 = 4096, #endif size = sizeof(struct lws_context); - int n, lpf = info->fd_limit_per_thread; + int n; + unsigned int lpf = info->fd_limit_per_thread; const lws_plugin_evlib_t *plev = NULL; #if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) struct lws_plugin *evlib_plugin_list = NULL; @@ -448,7 +449,7 @@ lws_create_context(const struct lws_context_creation_info *info) #if defined(LWS_WITH_NETWORK) if (info->count_threads) - count_threads = info->count_threads; + count_threads = (unsigned short)info->count_threads; if (count_threads > LWS_MAX_SMP) count_threads = LWS_MAX_SMP; @@ -511,7 +512,7 @@ lws_create_context(const struct lws_context_creation_info *info) LWS_TOKENIZE_F_NO_FLOATS; do { - ts.e = lws_tokenize(&ts); + ts.e = (int8_t)lws_tokenize(&ts); if (ts.e != LWS_TOKZE_TOKEN) continue; @@ -711,7 +712,8 @@ lws_create_context(const struct lws_context_creation_info *info) #endif #if defined(LWS_WITH_NETWORK) - context->undestroyed_threads = context->count_threads = count_threads; + context->undestroyed_threads = count_threads; + context->count_threads = count_threads; #if defined(LWS_WITH_DETAILED_LATENCY) context->detailed_latency_cb = info->detailed_latency_cb; context->detailed_latency_filepath = info->detailed_latency_filepath; @@ -816,7 +818,8 @@ lws_create_context(const struct lws_context_creation_info *info) if (info->rlimit_nofile) { struct rlimit rl; - rl.rlim_cur = rl.rlim_max = info->rlimit_nofile; + rl.rlim_cur = (unsigned int)info->rlimit_nofile; + rl.rlim_max = (unsigned int)info->rlimit_nofile; setrlimit(RLIMIT_NOFILE, &rl); } #endif @@ -834,7 +837,7 @@ lws_create_context(const struct lws_context_creation_info *info) goto free_context_fail; } - context->max_fds = rt.rlim_cur; + context->max_fds = (unsigned int)rt.rlim_cur; #else #if defined(WIN32) || defined(_WIN32) || defined(LWS_AMAZON_RTOS) || defined(LWS_ESP_PLATFORM) context->max_fds = getdtablesize(); @@ -849,10 +852,10 @@ lws_create_context(const struct lws_context_creation_info *info) __func__); else if (l != -1l) - context->max_fds = (int)l; + context->max_fds = (unsigned int)l; } #endif - if (context->max_fds < 0) { + if ((int)context->max_fds < 0) { lwsl_err("%s: problem getting process max files\n", __func__); @@ -866,7 +869,7 @@ lws_create_context(const struct lws_context_creation_info *info) * figure out what if this is something it can deal with. */ if (info->fd_limit_per_thread) { - int mf = lpf * context->count_threads; + unsigned int mf = lpf * context->count_threads; if (mf < context->max_fds) { context->max_fds_unrelated_to_ulimit = 1; @@ -890,10 +893,10 @@ lws_create_context(const struct lws_context_creation_info *info) if (ar->alpn) { if (!first) *p++ = ','; - p += lws_snprintf(p, - context->tls.alpn_discovered + + p += lws_snprintf(p, (unsigned int)( + (context->tls.alpn_discovered + sizeof(context->tls.alpn_discovered) - - 2 - p, "%s", ar->alpn); + 2) - p), "%s", ar->alpn); first = 0; } } LWS_FOR_EVERY_AVAILABLE_ROLE_END; @@ -915,7 +918,7 @@ lws_create_context(const struct lws_context_creation_info *info) else if (info->max_http_header_data2) context->max_http_header_data = - info->max_http_header_data2; + (unsigned short)info->max_http_header_data2; else context->max_http_header_data = LWS_DEF_HEADER_LEN; @@ -924,7 +927,7 @@ lws_create_context(const struct lws_context_creation_info *info) else if (info->max_http_header_pool2) context->max_http_header_pool = - info->max_http_header_pool2; + (unsigned short)info->max_http_header_pool2; else context->max_http_header_pool = context->max_fds; #endif @@ -986,7 +989,7 @@ lws_create_context(const struct lws_context_creation_info *info) u += context->pt_serv_buf_size; context->pt[n].context = context; - context->pt[n].tid = n; + context->pt[n].tid = (uint8_t)n; #if !defined(LWS_PLAT_FREERTOS) /* @@ -1049,9 +1052,9 @@ lws_create_context(const struct lws_context_creation_info *info) * fds table contains pollfd structs for as many pollfds as we can * handle... spread across as many service threads as we have going */ - n = sizeof(struct lws_pollfd) * context->count_threads * - context->fd_limit_per_thread; - context->pt[0].fds = lws_zalloc(n, "fds table"); + n = (int)(sizeof(struct lws_pollfd) * context->count_threads * + context->fd_limit_per_thread); + context->pt[0].fds = lws_zalloc((unsigned int)n, "fds table"); if (context->pt[0].fds == NULL) { lwsl_err("OOM allocating %d fds\n", context->max_fds); goto bail; @@ -1960,7 +1963,7 @@ next: for (n = 0; n < LWS_SYSBLOB_TYPE_COUNT; n++) lws_system_blob_destroy( - lws_system_get_blob(context, n, 0)); + lws_system_get_blob(context, (lws_system_blob_item_t)n, 0)); /* * Context lock is about to go away diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index a44e6d5f5..6db75fdc8 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -55,13 +55,13 @@ lws_ser_wu64be(uint8_t *b, uint64_t u64) uint16_t lws_ser_ru16be(const uint8_t *b) { - return (b[0] << 8) | b[1]; + return (uint16_t)((b[0] << 8) | b[1]); } uint32_t lws_ser_ru32be(const uint8_t *b) { - return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; + return (unsigned int)((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]); } uint64_t @@ -118,15 +118,15 @@ lws_vbi_decode(const void *buf, uint64_t *value, size_t len) signed char char_to_hex(const char c) { if (c >= '0' && c <= '9') - return c - '0'; + return (signed char)(c - '0'); if (c >= 'a' && c <= 'f') - return c - 'a' + 10; + return (signed char)(c - 'a' + 10); if (c >= 'A' && c <= 'F') - return c - 'A' + 10; + return (signed char)(c - 'A' + 10); - return -1; + return (signed char)-1; } int @@ -144,7 +144,7 @@ lws_hex_to_byte_array(const char *h, uint8_t *dest, int max) if (t1 < 0) return -1; - *dest++ = (t << 4) | t1; + *dest++ = (uint8_t)((t << 4) | t1); } if (max < 0) @@ -254,7 +254,7 @@ lws_now_secs(void) gettimeofday(&tv, NULL); - return tv.tv_sec; + return (unsigned long)tv.tv_sec; } #endif @@ -453,7 +453,7 @@ lws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen np++; } - *alen = lws_ptr_diff(np, as); + *alen = (unsigned int)lws_ptr_diff(np, as); return as; } @@ -477,7 +477,7 @@ lws_json_simple_strcmp(const char *buf, size_t len, const char *name, static const char *hex = "0123456789ABCDEF"; const char * -lws_sql_purify(char *escaped, const char *string, int len) +lws_sql_purify(char *escaped, const char *string, size_t len) { const char *p = string; char *q = escaped; @@ -675,7 +675,7 @@ lws_urldecode(char *string, const char *escaped, int len) if (n < 0) return -1; escaped++; - sum = n << 4; + sum = (char)(n << 4); state++; break; @@ -684,7 +684,7 @@ lws_urldecode(char *string, const char *escaped, int len) if (n < 0) return -1; escaped++; - *string++ = sum | n; + *string++ = (char)(sum | n); len--; state = 0; break; @@ -708,7 +708,7 @@ lws_finalize_startup(struct lws_context *context) #if !defined(LWS_PLAT_FREERTOS) void -lws_get_effective_uid_gid(struct lws_context *context, int *uid, int *gid) +lws_get_effective_uid_gid(struct lws_context *context, uid_t *uid, gid_t *gid) { *uid = context->uid; *gid = context->gid; @@ -750,7 +750,7 @@ lws_timingsafe_bcmp(const void *a, const void *b, uint32_t len) uint8_t sum = 0; while (len--) - sum |= (*pa++ ^ *pb++); + sum |= (uint8_t)(*pa++ ^ *pb++); return sum; } @@ -791,7 +791,7 @@ lws_tokenize(struct lws_tokenize *ts) c = *ts->start++; ts->len--; - utf8 = lws_check_byte_utf8((unsigned char)utf8, c); + utf8 = lws_check_byte_utf8((unsigned char)utf8, (unsigned char)c); if (utf8 < 0) return LWS_TOKZE_ERR_BROKEN_UTF8; @@ -1019,7 +1019,7 @@ lws_tokenize_init(struct lws_tokenize *ts, const char *start, int flags) { ts->start = start; ts->len = 0x7fffffff; - ts->flags = flags; + ts->flags = (uint16_t)(unsigned int)flags; ts->delim = LWSTZ_DT_NEED_FIRST_CONTENT; } @@ -1206,7 +1206,8 @@ lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr) const char * lws_cmdline_option(int argc, const char **argv, const char *val) { - int n = (int)strlen(val), c = argc; + size_t n = strlen(val); + int c = argc; while (--c > 0) { @@ -1263,10 +1264,10 @@ lws_cmdline_option_handle_builtin(int argc, const char **argv, break; #if defined(LWS_WITH_UDP) case 1: - info->udp_loss_sim_tx_pc = m; + info->udp_loss_sim_tx_pc = (uint8_t)m; break; case 2: - info->udp_loss_sim_rx_pc = m; + info->udp_loss_sim_rx_pc = (uint8_t)m; break; case 3: #else @@ -1314,7 +1315,7 @@ decim(char *r, uint64_t v, char chars, char leading) while (n >= 0) { if (v / q) - *r-- = '0' + ((v / q) % 10); + *r-- = (char)('0' + (char)((v / q) % 10)); else *r-- = leading ? '0' : ' '; q = q * 10; @@ -1329,7 +1330,7 @@ decim(char *r, uint64_t v, char chars, char leading) } int -lws_humanize(char *p, int len, uint64_t v, const lws_humanize_unit_t *schema) +lws_humanize(char *p, size_t len, uint64_t v, const lws_humanize_unit_t *schema) { char *end = p + len; @@ -1338,7 +1339,7 @@ lws_humanize(char *p, int len, uint64_t v, const lws_humanize_unit_t *schema) if (schema->factor == 1) { *p++ = ' '; p += decim(p, v, 4, 0); - return lws_snprintf(p, lws_ptr_diff(end, p), + return lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "%s ", schema->name); } @@ -1348,7 +1349,7 @@ lws_humanize(char *p, int len, uint64_t v, const lws_humanize_unit_t *schema) p += decim(p, (v % schema->factor) / (schema->factor / 1000), 3, 1); - return lws_snprintf(p, lws_ptr_diff(end, p), + return lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "%s", schema->name); } schema++; diff --git a/lib/core/logs.c b/lib/core/logs.c index b618dec24..36280c466 100644 --- a/lib/core/logs.c +++ b/lib/core/logs.c @@ -153,7 +153,7 @@ lws_lc_tag(lws_lifecycle_t *lc) #if defined(LWS_LOGS_TIMESTAMP) int -lwsl_timestamp(int level, char *p, int len) +lwsl_timestamp(int level, char *p, size_t len) { #ifndef LWS_PLAT_OPTEE time_t o_now; @@ -167,7 +167,7 @@ lwsl_timestamp(int level, char *p, int len) gettimeofday(&tv, NULL); o_now = tv.tv_sec; - now = ((unsigned long long)tv.tv_sec * 10000) + (tv.tv_usec / 100); + now = ((unsigned long long)tv.tv_sec * 10000) + (unsigned int)(tv.tv_usec / 100); #ifndef _WIN32_WCE #ifdef WIN32 @@ -231,7 +231,7 @@ _lwsl_emit_stderr(int level, const char *line, int ts) int n, m = LWS_ARRAY_SIZE(colours) - 1; if (!tty) - tty = isatty(2) | 2; + tty = (char)(isatty(2) | 2); buf[0] = '\0'; #if defined(LWS_LOGS_TIMESTAMP) @@ -353,7 +353,7 @@ lwsl_hexdump_level(int hexdump_level, const void *vbuf, size_t len) for (m = 0; m < 16 && (start + m) < len; m++) { if (buf[start + m] >= ' ' && buf[start + m] < 127) - *p++ = buf[start + m]; + *p++ = (char)buf[start + m]; else *p++ = '.'; } diff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h index eb0668de1..622610c0a 100644 --- a/lib/core/private-lib-core.h +++ b/lib/core/private-lib-core.h @@ -586,13 +586,14 @@ struct lws_context { uint32_t last_free_heap; #endif - int max_fds; + unsigned int max_fds; #if !defined(LWS_NO_DAEMONIZE) pid_t started_with_parent; #endif #if !defined(LWS_PLAT_FREERTOS) - int uid, gid; + uid_t uid; + gid_t gid; int fd_random; int count_cgi_spawned; #endif @@ -603,8 +604,8 @@ struct lws_context { unsigned int fd_limit_per_thread; unsigned int timeout_secs; unsigned int pt_serv_buf_size; - int max_http_header_data; - int max_http_header_pool; + unsigned int max_http_header_data; + unsigned int max_http_header_pool; int simultaneous_ssl_restriction; int simultaneous_ssl; #if defined(LWS_WITH_PEER_LIMITS) @@ -629,8 +630,8 @@ struct lws_context { unsigned int nl_initial_done:1; #endif - short count_threads; - short undestroyed_threads; + unsigned short count_threads; + unsigned short undestroyed_threads; short plugin_protocol_count; short plugin_extension_count; short server_string_len; @@ -756,10 +757,10 @@ lws_vhost_unlock(struct lws_vhost *vhost) #endif int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len); +lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, size_t len); int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len); +lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, size_t len); int LWS_WARN_UNUSED_RESULT lws_ssl_pending_no_ssl(struct lws *wsi); diff --git a/lib/core/vfs.c b/lib/core/vfs.c index 8cd2a4611..e14d41592 100644 --- a/lib/core/vfs.c +++ b/lib/core/vfs.c @@ -53,7 +53,8 @@ lws_vfs_file_seek_set(lws_fop_fd_t fop_fd, lws_fileofs_t offset) { lws_fileofs_t ofs; - ofs = fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, offset - fop_fd->pos); + ofs = fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, + offset - (lws_fileofs_t)fop_fd->pos); return ofs; } @@ -62,8 +63,8 @@ lws_vfs_file_seek_set(lws_fop_fd_t fop_fd, lws_fileofs_t offset) lws_fileofs_t lws_vfs_file_seek_end(lws_fop_fd_t fop_fd, lws_fileofs_t offset) { - return fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, fop_fd->len + - fop_fd->pos + offset); + return fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, + (lws_fileofs_t)fop_fd->len + (lws_fileofs_t)fop_fd->pos + offset); } @@ -100,7 +101,7 @@ lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path, if (p >= vfs_path + pf->fi[n].len) if (!strncmp(p - (pf->fi[n].len - 1), pf->fi[n].sig, - pf->fi[n].len - 1)) { + (unsigned int)(pf->fi[n].len - 1))) { *vpath = p + 1; return pf; } diff --git a/lib/event-libs/glib/glib.c b/lib/event-libs/glib/glib.c index 5022a100c..c34108c4d 100644 --- a/lib/event-libs/glib/glib.c +++ b/lib/event-libs/glib/glib.c @@ -116,7 +116,7 @@ lws_glib_dispatch(GSource *src, GSourceFunc x, gpointer userData) GIOCondition cond; cond = g_source_query_unix_fd(src, sub->tag); - eventfd.revents = cond; + eventfd.revents = (short)cond; /* translate from glib event namespace to platform */ @@ -177,7 +177,7 @@ lws_glib_hrtimer_cb(void *p) us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, lws_now_usecs()); if (us) { - ms = us / LWS_US_PER_MS; + ms = (unsigned int)(us / LWS_US_PER_MS); if (!ms) ms = 1; @@ -344,7 +344,7 @@ elops_init_pt_glib(struct lws_context *context, void *_loop, int tsi) */ static void -elops_io_glib(struct lws *wsi, int flags) +elops_io_glib(struct lws *wsi, unsigned int flags) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_wsi_eventlibs_glib *wsipr = wsi_to_priv_glib(wsi); @@ -364,19 +364,19 @@ elops_io_glib(struct lws *wsi, int flags) if (flags & LWS_EV_READ) { if (flags & LWS_EV_STOP) - cond &= ~(G_IO_IN | G_IO_HUP); + cond &= (unsigned int)~(G_IO_IN | G_IO_HUP); else cond |= G_IO_IN | G_IO_HUP; } if (flags & LWS_EV_WRITE) { if (flags & LWS_EV_STOP) - cond &= ~G_IO_OUT; + cond &= (unsigned int)~G_IO_OUT; else cond |= G_IO_OUT; } - wsipr->w_read.actual_events = cond; + wsipr->w_read.actual_events = (uint8_t)cond; lwsl_debug("%s: %s, fd %d, 0x%x/0x%x\n", __func__, lws_wsi_tag(wsi), wsi->desc.sockfd, flags, (int)cond); diff --git a/lib/event-libs/libev/libev.c b/lib/event-libs/libev/libev.c index 1f054c96c..ae71ee4ff 100644 --- a/lib/event-libs/libev/libev.c +++ b/lib/event-libs/libev/libev.c @@ -142,8 +142,8 @@ elops_init_pt_ev(struct lws_context *context, void *_loop, int tsi) struct ev_loop *loop = (struct ev_loop *)_loop; struct lws_vhost *vh = context->vhost_list; const char *backend_name; + unsigned int backend; int status = 0; - int backend; lwsl_info("%s: loop %p\n", __func__, _loop); @@ -296,7 +296,7 @@ elops_accept_ev(struct lws *wsi) } static void -elops_io_ev(struct lws *wsi, int flags) +elops_io_ev(struct lws *wsi, unsigned int flags) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_pt_eventlibs_libev *ptpr = pt_to_priv_ev(pt); diff --git a/lib/event-libs/libevent/libevent.c b/lib/event-libs/libevent/libevent.c index 1ff170972..2c99b777d 100644 --- a/lib/event-libs/libevent/libevent.c +++ b/lib/event-libs/libevent/libevent.c @@ -40,8 +40,13 @@ lws_event_hrtimer_cb(evutil_socket_t fd, short event, void *p) us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, lws_now_usecs()); if (us) { - tv.tv_sec = us / LWS_US_PER_SEC; - tv.tv_usec = us - (tv.tv_sec * LWS_US_PER_SEC); +#if defined(__APPLE__) + tv.tv_sec = (int)(us / LWS_US_PER_SEC); + tv.tv_usec = (int)(us - (tv.tv_sec * LWS_US_PER_SEC)); +#else + tv.tv_sec = (long)(us / LWS_US_PER_SEC); + tv.tv_usec = (long)(us - (tv.tv_sec * LWS_US_PER_SEC)); +#endif evtimer_add(ptpr->hrtimer, &tv); } lws_pt_unlock(pt); @@ -86,8 +91,8 @@ lws_event_idle_timer_cb(evutil_socket_t fd, short event, void *p) us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, lws_now_usecs()); if (us) { - tv.tv_sec = us / LWS_US_PER_SEC; - tv.tv_usec = us - (tv.tv_sec * LWS_US_PER_SEC); + tv.tv_sec = (suseconds_t)(us / LWS_US_PER_SEC); + tv.tv_usec = (suseconds_t)(us - (tv.tv_sec * LWS_US_PER_SEC)); evtimer_add(ptpr->hrtimer, &tv); } lws_pt_unlock(pt); @@ -265,7 +270,7 @@ elops_accept_event(struct lws *wsi) ptpr = pt_to_priv_event(pt); if (wsi->role_ops->file_handle) - fd = (ev_intptr_t) wsi->desc.filefd; + fd = (evutil_socket_t)(ev_intptr_t) wsi->desc.filefd; else fd = wsi->desc.sockfd; @@ -278,7 +283,7 @@ elops_accept_event(struct lws *wsi) } static void -elops_io_event(struct lws *wsi, int flags) +elops_io_event(struct lws *wsi, unsigned int flags) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index 2d668da64..d3b8549c0 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -46,7 +46,7 @@ lws_uv_sultimer_cb(uv_timer_t *timer lws_now_usecs()); if (us) uv_timer_start(&pt_to_priv_uv(pt)->sultimer, lws_uv_sultimer_cb, - LWS_US_TO_MS(us), 0); + LWS_US_TO_MS((uint64_t)us), 0); lws_pt_unlock(pt); lws_context_unlock(pt->context); } @@ -80,7 +80,7 @@ lws_uv_idle(uv_idle_t *handle lws_now_usecs()); if (us) uv_timer_start(&pt_to_priv_uv(pt)->sultimer, lws_uv_sultimer_cb, - LWS_US_TO_MS(us), 0); + LWS_US_TO_MS((uint64_t)us), 0); /* there is nobody who needs service forcing, shut down idle */ uv_idle_stop(handle); @@ -549,7 +549,7 @@ elops_accept_uv(struct lws *wsi) } static void -elops_io_uv(struct lws *wsi, int flags) +elops_io_uv(struct lws *wsi, unsigned int flags) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_io_watcher_libuv *w = &(wsi_to_priv_uv(wsi)->w_read); @@ -597,7 +597,7 @@ elops_io_uv(struct lws *wsi, int flags) uv_poll_start(w->pwatcher, current_events, lws_io_cb); } - w->actual_events = current_events; + w->actual_events = (uint8_t)current_events; } static int diff --git a/lib/event-libs/private-lib-event-libs.h b/lib/event-libs/private-lib-event-libs.h index c0d087f1a..35bfcd885 100644 --- a/lib/event-libs/private-lib-event-libs.h +++ b/lib/event-libs/private-lib-event-libs.h @@ -51,7 +51,7 @@ struct lws_event_loop_ops { /* event loop accept processing */ int (*sock_accept)(struct lws *wsi); /* control wsi active events */ - void (*io)(struct lws *wsi, int flags); + void (*io)(struct lws *wsi, unsigned int flags); /* run the event loop for a pt */ void (*run_pt)(struct lws_context *context, int tsi); /* called before pt is destroyed */ diff --git a/lib/jose/jwe/enc/aescbc.c b/lib/jose/jwe/enc/aescbc.c index d15475d51..bf559d91f 100755 --- a/lib/jose/jwe/enc/aescbc.c +++ b/lib/jose/jwe/enc/aescbc.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -79,7 +79,7 @@ lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *cek, /* second half is the AES ENC_KEY */ el.buf = cek + (hlen / 2); - el.len = hlen / 2; + el.len = (uint32_t)(hlen / 2); if (lws_genaes_create(&aesctx, LWS_GAESO_ENC, LWS_GAESM_CBC, &el, LWS_GAESP_WITH_PADDING, NULL)) { @@ -113,11 +113,11 @@ lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *cek, * Additional Authenticated Data A expressed as a 64-bit unsigned * big-endian integer. */ - lws_jwe_be64(aad_len * 8, al); + lws_jwe_be64((unsigned int)aad_len * 8, al); /* first half of the CEK is the MAC key */ if (lws_genhmac_init(&hmacctx, jwe->jose.enc_alg->hmac_type, - cek, hlen / 2)) + cek, (unsigned int)hlen / 2)) return -1; /* @@ -134,7 +134,7 @@ lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *cek, * M are used as T. */ - if (lws_genhmac_update(&hmacctx, aad, aad_len) || + if (lws_genhmac_update(&hmacctx, aad, (unsigned int)aad_len) || lws_genhmac_update(&hmacctx, jwe->jws.map.buf[LJWE_IV], LWS_JWE_AES_IV_BYTES) || /* since we encrypted it, this is the ciphertext */ @@ -153,9 +153,9 @@ lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *cek, } /* create tag */ - memcpy((void *)jwe->jws.map.buf[LJWE_ATAG], digest, hlen / 2); + memcpy((void *)jwe->jws.map.buf[LJWE_ATAG], digest, (unsigned int)hlen / 2); - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } int @@ -197,16 +197,16 @@ lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, * */ - lws_jwe_be64(aad_len * 8, al); + lws_jwe_be64((unsigned int)aad_len * 8, al); /* first half of enc_cek is the MAC key */ if (lws_genhmac_init(&hmacctx, jwe->jose.enc_alg->hmac_type, enc_cek, - hlen / 2)) { + (unsigned int)hlen / 2)) { lwsl_err("%s: lws_genhmac_init fail\n", __func__); return -1; } - if (lws_genhmac_update(&hmacctx, aad, aad_len) || + if (lws_genhmac_update(&hmacctx, aad, (unsigned int)aad_len) || lws_genhmac_update(&hmacctx, (uint8_t *)jwe->jws.map.buf[LJWE_IV], jwe->jws.map.len[LJWE_IV]) || lws_genhmac_update(&hmacctx, (uint8_t *)jwe->jws.map.buf[LJWE_CTXT], @@ -224,17 +224,17 @@ lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, /* first half of digest is the auth tag */ - if (lws_timingsafe_bcmp(digest, jwe->jws.map.buf[LJWE_ATAG], hlen / 2)) { + if (lws_timingsafe_bcmp(digest, jwe->jws.map.buf[LJWE_ATAG], (unsigned int)hlen / 2)) { lwsl_err("%s: auth failed: hmac tag (%d) != ATAG (%d)\n", __func__, hlen / 2, jwe->jws.map.len[LJWE_ATAG]); - lwsl_hexdump_notice(jwe->jws.map.buf[LJWE_ATAG], hlen / 2); - lwsl_hexdump_notice(digest, hlen / 2); + lwsl_hexdump_notice(jwe->jws.map.buf[LJWE_ATAG], (unsigned int)hlen / 2); + lwsl_hexdump_notice(digest, (unsigned int)hlen / 2); return -1; } /* second half of enc cek is the CEK KEY */ el.buf = enc_cek + (hlen / 2); - el.len = hlen / 2; + el.len = (unsigned int)hlen / 2; if (lws_genaes_create(&aesctx, LWS_GAESO_DEC, LWS_GAESM_CBC, &el, LWS_GAESP_NO_PADDING, NULL)) { @@ -257,8 +257,8 @@ lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, __func__, jwe->jws.map.len[LJWE_CTXT]); return -1; } - jwe->jws.map.len[LJWE_CTXT] -= jwe->jws.map.buf[LJWE_CTXT][ - jwe->jws.map.len[LJWE_CTXT] - 1]; + jwe->jws.map.len[LJWE_CTXT] = (uint32_t)((int)jwe->jws.map.len[LJWE_CTXT] - + jwe->jws.map.buf[LJWE_CTXT][jwe->jws.map.len[LJWE_CTXT] - 1]); n |= lws_genaes_destroy(&aesctx, NULL, 0); if (n) { @@ -266,6 +266,6 @@ lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, return -1; } - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } diff --git a/lib/jose/jwe/enc/aesgcm.c b/lib/jose/jwe/enc/aesgcm.c index 28488b08e..ef822ad29 100644 --- a/lib/jose/jwe/enc/aesgcm.c +++ b/lib/jose/jwe/enc/aesgcm.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -86,7 +86,7 @@ lws_jwe_encrypt_gcm(struct lws_jwe *jwe, /* aad */ - n = lws_genaes_crypt(&aesctx, aad, aad_len, NULL, + n = lws_genaes_crypt(&aesctx, aad, (unsigned int)aad_len, NULL, (uint8_t *)jwe->jws.map.buf[LJWE_IV], (uint8_t *)jwe->jws.map.buf[LJWE_ATAG], &ivs, LWS_AESGCM_TAG); @@ -110,7 +110,7 @@ lws_jwe_encrypt_gcm(struct lws_jwe *jwe, return -1; } - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } int @@ -149,7 +149,7 @@ lws_jwe_auth_and_decrypt_gcm(struct lws_jwe *jwe, return -1; } - n = lws_genaes_crypt(&aesctx, aad, aad_len, + n = lws_genaes_crypt(&aesctx, aad, (unsigned int)aad_len, NULL, (uint8_t *)jwe->jws.map.buf[LJWE_IV], (uint8_t *)jwe->jws.map.buf[LJWE_ATAG], &ivs, 16); @@ -169,5 +169,5 @@ lws_jwe_auth_and_decrypt_gcm(struct lws_jwe *jwe, return -1; } - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } diff --git a/lib/jose/jwe/enc/aeskw.c b/lib/jose/jwe/enc/aeskw.c index 78cf4f95c..7d5ae0a6f 100644 --- a/lib/jose/jwe/enc/aeskw.c +++ b/lib/jose/jwe/enc/aeskw.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -61,7 +61,7 @@ lws_jwe_encrypt_aeskw_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) /* Allocate temp space for ATAG and IV */ if (lws_jws_alloc_element(&jwe->jws.map, LJWE_ATAG, temp + (ot - *temp_len), - temp_len, hlen / 2, 0)) + temp_len, (unsigned int)hlen / 2, 0)) return -1; if (lws_jws_alloc_element(&jwe->jws.map, LJWE_IV, temp + (ot - *temp_len), @@ -74,7 +74,7 @@ lws_jwe_encrypt_aeskw_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) n = lws_jwe_encrypt_cbc_hs(jwe, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY], (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_encrypt_cbc_hs failed\n", __func__); return -1; @@ -110,7 +110,7 @@ lws_jwe_encrypt_aeskw_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) memcpy((uint8_t *)jwe->jws.map.buf[LJWE_EKEY], enc_cek, jwe->jws.map.len[LJWE_EKEY]); - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } @@ -164,14 +164,14 @@ lws_jwe_auth_and_decrypt_aeskw_cbc_hs(struct lws_jwe *jwe) n = lws_jwe_auth_and_decrypt_cbc_hs(jwe, enc_cek, (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_auth_and_decrypt_cbc_hs failed\n", __func__); return -1; } - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } diff --git a/lib/jose/jwe/jwe-ecdh-es-aeskw.c b/lib/jose/jwe/jwe-ecdh-es-aeskw.c index fc073b014..07c8c3472 100644 --- a/lib/jose/jwe/jwe-ecdh-es-aeskw.c +++ b/lib/jose/jwe/jwe-ecdh-es-aeskw.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -293,7 +293,7 @@ lws_jwe_encrypt_ecdh(struct lws_jwe *jwe, char *temp, int *temp_len, /* generate the actual CEK in cek */ - if (lws_get_random(jwe->jws.context, cek, enc_hlen) != + if (lws_get_random(jwe->jws.context, cek, (unsigned int)enc_hlen) != (size_t)enc_hlen) { lwsl_err("Problem getting random\n"); goto bail; @@ -302,7 +302,7 @@ lws_jwe_encrypt_ecdh(struct lws_jwe *jwe, char *temp, int *temp_len, /* wrap with the derived key */ el.buf = derived; - el.len = enc_hlen / 2; + el.len = (unsigned int)enc_hlen / 2; if (lws_genaes_create(&aesctx, LWS_GAESO_ENC, LWS_GAESM_KW, &el, 1, NULL)) { @@ -313,7 +313,7 @@ lws_jwe_encrypt_ecdh(struct lws_jwe *jwe, char *temp, int *temp_len, /* wrap CEK into EKEY */ - n = lws_genaes_crypt(&aesctx, cek, enc_hlen, + n = lws_genaes_crypt(&aesctx, cek, (unsigned int)enc_hlen, (void *)jwe->jws.map.buf[LJWE_EKEY], NULL, NULL, NULL, 0); m = lws_genaes_destroy(&aesctx, NULL, 0); @@ -326,18 +326,18 @@ lws_jwe_encrypt_ecdh(struct lws_jwe *jwe, char *temp, int *temp_len, goto bail; } - jwe->jws.map.len[LJWE_EKEY] = enc_hlen + 8; + jwe->jws.map.len[LJWE_EKEY] = (unsigned int)enc_hlen + 8; /* Wrapped CEK is in EKEY. Random CEK is in cek. */ } else /* direct derived CEK is in cek */ - memcpy(cek, derived, enc_hlen); + memcpy(cek, derived, (unsigned int)enc_hlen); /* rewrite the protected JOSE header to have the epk pieces */ jwe->jws.map.buf[LJWE_JOSE] = temp; - m = n = lws_snprintf(temp, *temp_len, + m = n = lws_snprintf(temp, (size_t)*temp_len, "{\"alg\":\"%s\", \"enc\":\"%s\", \"epk\":", jwe->jose.alg->alg, jwe->jose.enc_alg->alg); *temp_len -= n; @@ -349,10 +349,10 @@ lws_jwe_encrypt_ecdh(struct lws_jwe *jwe, char *temp, int *temp_len, } m += n; - n = lws_snprintf(temp + (ot - *temp_len), *temp_len, "}"); + n = lws_snprintf(temp + (ot - *temp_len), (size_t)*temp_len, "}"); *temp_len -= n + 1; m += n; - jwe->jws.map.len[LJWE_JOSE] = m; + jwe->jws.map.len[LJWE_JOSE] = (unsigned int)m; /* create a b64 version of the JOSE header, needed later for AAD */ @@ -368,8 +368,8 @@ bail: lws_genec_destroy(&ecctx); /* cleanse the shared secret (watch out for cek at parent too) */ - lws_explicit_bzero(shared_secret, ekbytes); - lws_explicit_bzero(derived, ekbytes); + lws_explicit_bzero(shared_secret, (unsigned int)ekbytes); + lws_explicit_bzero(derived, (unsigned int)ekbytes); return ret; } @@ -388,7 +388,7 @@ lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) if (jwe->jose.alg->algtype_crypto != LWS_JOSE_ENCTYPE_NONE) { if (lws_jws_alloc_element(&jwe->jws.map, LJWE_EKEY, temp + (ot - *temp_len), temp_len, - enc_hlen + 8, 0)) + (unsigned int)enc_hlen + 8, 0)) goto bail; } @@ -406,7 +406,7 @@ lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) if (lws_jws_alloc_element(&jwe->jws.map, LJWE_ATAG, temp + (ot - *temp_len), - temp_len, enc_hlen / 2, 0)) + temp_len, (unsigned int)enc_hlen / 2, 0)) goto bail; if (lws_jws_alloc_element(&jwe->jws.map, LJWE_IV, @@ -419,7 +419,7 @@ lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) n = lws_jwe_encrypt_cbc_hs(jwe, cek, (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_notice("%s: lws_jwe_encrypt_cbc_hs failed\n", __func__); goto bail; @@ -436,7 +436,7 @@ bail: jwe->jws.map.len[LJWE_EKEY] = 0; } - lws_explicit_bzero(cek, ekbytes); + lws_explicit_bzero(cek, (unsigned int)ekbytes); return ret; } @@ -551,7 +551,7 @@ lws_jwe_auth_and_decrypt_ecdh(struct lws_jwe *jwe) /* unwrap with the KEK we derived */ el.buf = derived; - el.len = enc_hlen / 2; + el.len = (unsigned int)enc_hlen / 2; if (lws_genaes_create(&aesctx, LWS_GAESO_DEC, LWS_GAESM_KW, &el, 1, NULL)) { @@ -577,13 +577,13 @@ lws_jwe_auth_and_decrypt_ecdh(struct lws_jwe *jwe) goto bail; } } else - memcpy(shared_secret, derived, enc_hlen); + memcpy(shared_secret, derived, (unsigned int)enc_hlen); /* either way, the recovered CEK is in shared_secret */ if (lws_jwe_auth_and_decrypt_cbc_hs(jwe, shared_secret, (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]) < 0) { + (int)jwe->jws.map_b64.len[LJWE_JOSE]) < 0) { lwsl_err("%s: lws_jwe_auth_and_decrypt_cbc_hs fail\n", __func__); goto bail; } @@ -593,9 +593,9 @@ lws_jwe_auth_and_decrypt_ecdh(struct lws_jwe *jwe) bail: /* cleanse wrapped on stack that contained the CEK / wrapped key */ - lws_explicit_bzero(derived, ekbytes); + lws_explicit_bzero(derived, (unsigned int)ekbytes); /* cleanse the shared secret */ - lws_explicit_bzero(shared_secret, ekbytes); + lws_explicit_bzero(shared_secret, (unsigned int)ekbytes); return ret; } diff --git a/lib/jose/jwe/jwe-rsa-aescbc.c b/lib/jose/jwe/jwe-rsa-aescbc.c index c2ff06ffd..21e4e50f8 100644 --- a/lib/jose/jwe/jwe-rsa-aescbc.c +++ b/lib/jose/jwe/jwe-rsa-aescbc.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -70,7 +70,7 @@ lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, return -1; if (lws_jws_alloc_element(&jwe->jws.map, LJWE_ATAG, temp + (ot - *temp_len), - temp_len, hlen / 2, 0)) + temp_len, (unsigned int)hlen / 2, 0)) return -1; if (lws_jws_alloc_element(&jwe->jws.map, LJWE_IV, temp + (ot - *temp_len), @@ -91,7 +91,7 @@ lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, n = lws_jwe_encrypt_cbc_hs(jwe, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY], (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_encrypt_cbc_hs failed\n", __func__); return -1; @@ -109,17 +109,17 @@ lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, /* encrypt the CEK using RSA, mbedtls can't handle both in and out are * the EKEY, so copy the unencrypted ekey out temporarily */ - memcpy(ekey, jwe->jws.map.buf[LJWE_EKEY], hlen); + memcpy(ekey, jwe->jws.map.buf[LJWE_EKEY], (unsigned int)hlen); - n = lws_genrsa_public_encrypt(&rsactx, (uint8_t *)ekey, hlen, + n = lws_genrsa_public_encrypt(&rsactx, (uint8_t *)ekey, (unsigned int)hlen, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY]); lws_genrsa_destroy(&rsactx); - lws_explicit_bzero(ekey, hlen); /* cleanse the temp CEK copy */ + lws_explicit_bzero(ekey, (unsigned int)hlen); /* cleanse the temp CEK copy */ if (n < 0) { lwsl_err("%s: encrypt cek fail\n", __func__); return -1; } - jwe->jws.map.len[LJWE_EKEY] = n; /* update to encrypted EKEY size */ + jwe->jws.map.len[LJWE_EKEY] = (unsigned int)n; /* update to encrypted EKEY size */ /* * We end up with IV, ATAG, set, EKEY encrypted and CTXT is ciphertext, @@ -172,7 +172,7 @@ lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe) n = lws_jwe_auth_and_decrypt_cbc_hs(jwe, enc_cek, (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_auth_and_decrypt_cbc_hs failed\n", __func__); @@ -192,5 +192,5 @@ lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe) jwe->jws.map.len[LJWE_CTXT] -= n; #endif - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } diff --git a/lib/jose/jwe/jwe-rsa-aesgcm.c b/lib/jose/jwe/jwe-rsa-aesgcm.c index 00161289f..b75c6741c 100644 --- a/lib/jose/jwe/jwe-rsa-aesgcm.c +++ b/lib/jose/jwe/jwe-rsa-aesgcm.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -67,7 +67,7 @@ lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, char *temp, int *temp_len) * just reuse it. It will be cleansed in the JWE destroy. */ if (!jwe->cek_valid) { - if (lws_get_random(jwe->jws.context, jwe->cek, ekbytes) != + if (lws_get_random(jwe->jws.context, jwe->cek, (unsigned int)ekbytes) != (size_t)ekbytes) { lwsl_err("%s: Problem getting random\n", __func__); return -1; @@ -77,14 +77,14 @@ lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, char *temp, int *temp_len) if (lws_jws_dup_element(&jwe->jws.map, LJWE_EKEY, temp + (ot - *temp_len), temp_len, - jwe->cek, ekbytes, 0)) + jwe->cek, (unsigned int)ekbytes, 0)) return -1; /* encrypt the payload */ n = lws_jwe_encrypt_gcm(jwe, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY], (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_encrypt_gcm failed\n", __func__); @@ -102,7 +102,7 @@ lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, char *temp, int *temp_len) goto bail; } - n = lws_genrsa_public_encrypt(&rsactx, jwe->cek, ekbytes, + n = lws_genrsa_public_encrypt(&rsactx, jwe->cek, (unsigned int)ekbytes, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY]); lws_genrsa_destroy(&rsactx); if (n < 0) { @@ -111,9 +111,9 @@ lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, char *temp, int *temp_len) } /* set the EKEY length to the actual enciphered length */ - jwe->jws.map.len[LJWE_EKEY] = n; + jwe->jws.map.len[LJWE_EKEY] = (unsigned int)n; - ret = jwe->jws.map.len[LJWE_CTXT]; + ret = (int32_t)jwe->jws.map.len[LJWE_CTXT]; bail: @@ -163,7 +163,7 @@ lws_jwe_auth_and_decrypt_rsa_aes_gcm(struct lws_jwe *jwe) n = lws_jwe_auth_and_decrypt_gcm(jwe, enc_cek, (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE], - jwe->jws.map_b64.len[LJWE_JOSE]); + (int)jwe->jws.map_b64.len[LJWE_JOSE]); if (n < 0) { lwsl_err("%s: lws_jwe_auth_and_decrypt_gcm_hs failed\n", __func__); @@ -179,5 +179,5 @@ lws_jwe_auth_and_decrypt_rsa_aes_gcm(struct lws_jwe *jwe) jwe->jws.map.len[LJWE_CTXT] -= n; #endif - return jwe->jws.map.len[LJWE_CTXT]; + return (int)jwe->jws.map.len[LJWE_CTXT]; } diff --git a/lib/jose/jwe/jwe.c b/lib/jose/jwe/jwe.c index 61e7c6ad7..d000e133f 100755 --- a/lib/jose/jwe/jwe.c +++ b/lib/jose/jwe/jwe.c @@ -118,7 +118,7 @@ append_string: n = lws_b64_decode_string_len( (const char *)args->jws->map_b64.buf[m], - args->jws->map_b64.len[m], + (int)args->jws->map_b64.len[m], (char *)args->temp, *args->temp_len); if (n < 0) { lwsl_err("%s: b64 decode failed\n", __func__); @@ -127,7 +127,7 @@ append_string: args->temp += n; *args->temp_len -= n; - args->jws->map.len[m] = n; + args->jws->map.len[m] = (uint32_t)n; } return 0; @@ -184,10 +184,10 @@ be32(uint32_t i, uint32_t *p32) { uint8_t *p = (uint8_t *)p32; - *p++ = (i >> 24) & 0xff; - *p++ = (i >> 16) & 0xff; - *p++ = (i >> 8) & 0xff; - *p++ = i & 0xff; + *p++ = (uint8_t)((i >> 24) & 0xff); + *p++ = (uint8_t)((i >> 16) & 0xff); + *p++ = (uint8_t)((i >> 8) & 0xff); + *p++ = (uint8_t)(i & 0xff); return (uint8_t *)p32; } @@ -282,10 +282,10 @@ lws_jwa_concat_kdf(struct lws_jwe *jwe, int direct, uint8_t *out, if (/* counter */ lws_genhash_update(&hash_ctx, be32(ctr++, &t), 4) || /* Z */ - lws_genhash_update(&hash_ctx, shared_secret, sslen) || + lws_genhash_update(&hash_ctx, shared_secret, (unsigned int)sslen) || /* other info */ lws_genhash_update(&hash_ctx, be32((uint32_t)strlen(aid), &t), 4) || - lws_genhash_update(&hash_ctx, aid, aidlen) || + lws_genhash_update(&hash_ctx, aid, (unsigned int)aidlen) || lws_genhash_update(&hash_ctx, be32(jwe->jose.e[LJJHI_APU].len, &t), 4) || lws_genhash_update(&hash_ctx, jwe->jose.e[LJJHI_APU].buf, @@ -326,7 +326,7 @@ lws_jwe_auth_and_decrypt(struct lws_jwe *jwe, char *temp, int *temp_len) char dotstar[96]; if (lws_jwe_parse_jose(&jwe->jose, jwe->jws.map.buf[LJWS_JOSE], - jwe->jws.map.len[LJWS_JOSE], + (int)jwe->jws.map.len[LJWS_JOSE], temp, temp_len) < 0) { lws_strnncpy(dotstar, jwe->jws.map.buf[LJWS_JOSE], jwe->jws.map.len[LJWS_JOSE], sizeof(dotstar)); @@ -395,7 +395,7 @@ lws_jwe_encrypt(struct lws_jwe *jwe, char *temp, int *temp_len) jwe->jose.enc_alg->algtype_crypto == LWS_JOSE_ENCTYPE_AES_GCM; if (lws_jwe_parse_jose(&jwe->jose, jwe->jws.map.buf[LJWS_JOSE], - jwe->jws.map.len[LJWS_JOSE], temp, temp_len) < 0) { + (int)jwe->jws.map.len[LJWS_JOSE], temp, temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); goto bail; } @@ -497,7 +497,7 @@ lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) out += n; *out++ = '.'; - out_len -= n + 1; + out_len -= (unsigned int)n + 1; n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_EKEY], jwe->jws.map.len[LJWE_EKEY], out, out_len); @@ -508,7 +508,7 @@ lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) out += n; *out++ = '.'; - out_len -= n + 1; + out_len -= (unsigned int)n + 1; n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_IV], jwe->jws.map.len[LJWE_IV], out, out_len); if (n < 0 || (int)out_len == n) { @@ -518,7 +518,7 @@ lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) out += n; *out++ = '.'; - out_len -= n + 1; + out_len -= (unsigned int)n + 1; n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_CTXT], jwe->jws.map.len[LJWE_CTXT], out, out_len); @@ -529,7 +529,7 @@ lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) out += n; *out++ = '.'; - out_len -= n + 1; + out_len -= (unsigned int)n + 1; n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_ATAG], jwe->jws.map.len[LJWE_ATAG], out, out_len); if (n < 0 || (int)out_len == n) { @@ -539,7 +539,7 @@ lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) out += n; *out++ = '\0'; - out_len -= n; + out_len -= (unsigned int)n; return (int)(orig - out_len); } @@ -562,7 +562,7 @@ lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, * here temporarily. */ n = LWS_PRE + 2048; - buf = malloc(n); + buf = malloc((unsigned int)n); if (!buf) { lwsl_notice("%s: malloc %d failed\n", __func__, n); return -1; @@ -578,7 +578,7 @@ lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, if (!jwe->jose.alg || !jwe->jose.alg->alg) goto bail; - p += lws_snprintf(p, lws_ptr_diff(end, p), "{\"alg\":\"%s\",\"jwk\":", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"alg\":\"%s\",\"jwk\":", jwe->jose.alg->alg); m = lws_ptr_diff(end, p); n = lws_jwk_export(&jwe->jwk, 0, p, &m); @@ -588,7 +588,7 @@ lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, goto bail; } p += n; - p += lws_snprintf(p, end - p, ",\"nonce\":\"%s\"}", nonce); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ",\"nonce\":\"%s\"}", nonce); /* * prepare the signed outer JSON with all the parts in @@ -597,53 +597,53 @@ lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, p1 = out; end1 = out + out_len - 1; - p1 += lws_snprintf(p1, end1 - p1, "{\"protected\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "{\"protected\":\""); jws.map_b64.buf[LJWS_JOSE] = p1; - n = lws_jws_base64_enc(start, p - start, p1, end1 - p1); + n = lws_jws_base64_enc(start, lws_ptr_diff_size_t(p, start), p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode protected\n", __func__); goto bail; } - jws.map_b64.len[LJWS_JOSE] = n; + jws.map_b64.len[LJWS_JOSE] = (unsigned int)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\",\"payload\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\"payload\":\""); jws.map_b64.buf[LJWS_PYLD] = p1; - n = lws_jws_base64_enc(payload, len, p1, end1 - p1); + n = lws_jws_base64_enc(payload, len, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode payload\n", __func__); goto bail; } - jws.map_b64.len[LJWS_PYLD] = n; + jws.map_b64.len[LJWS_PYLD] = (unsigned int)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\",\"header\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\"header\":\""); jws.map_b64.buf[LJWS_UHDR] = p1; - n = lws_jws_base64_enc(payload, len, p1, end1 - p1); + n = lws_jws_base64_enc(payload, len, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode payload\n", __func__); goto bail; } - jws.map_b64.len[LJWS_UHDR] = n; + jws.map_b64.len[LJWS_UHDR] = (unsigned int)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\",\"signature\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\"signature\":\""); /* * taking the b64 protected header and the b64 payload, sign them * and place the signature into the packet */ - n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, end1 - p1); + n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("sig gen failed\n"); goto bail; } jws.map_b64.buf[LJWS_SIG] = p1; - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (unsigned int)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\"}"); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\"}"); free(buf); @@ -746,30 +746,30 @@ lws_jwe_render_flattened(struct lws_jwe *jwe, char *out, size_t out_len) "{\"alg\":\"%s\",\"enc\":\"%s\"}", jwe->jose.alg->alg, jwe->jose.enc_alg->alg); - p1 += lws_snprintf(p1, end1 - p1, "{\"protected\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "{\"protected\":\""); jwe->jws.map_b64.buf[LJWS_JOSE] = p1; - n = lws_jws_base64_enc(protected, plen, p1, end1 - p1); + n = lws_jws_base64_enc(protected, (size_t)plen, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode protected\n", __func__); goto bail; } - jwe->jws.map_b64.len[LJWS_JOSE] = n; + jwe->jws.map_b64.len[LJWS_JOSE] = (unsigned int)n; p1 += n; /* unprotected not supported atm */ - p1 += lws_snprintf(p1, end1 - p1, "\",\n\"header\":"); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\n\"header\":"); lws_strnncpy(p1, buf, jlen, end1 - p1); p1 += strlen(p1); for (m = 0; m < (int)LWS_ARRAY_SIZE(protected_en); m++) if (jwe->jws.map.buf[protected_idx[m]]) { - p1 += lws_snprintf(p1, end1 - p1, ",\n\"%s\":\"", + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), ",\n\"%s\":\"", protected_en[m]); //jwe->jws.map_b64.buf[protected_idx[m]] = p1; n = lws_jws_base64_enc(jwe->jws.map.buf[protected_idx[m]], jwe->jws.map.len[protected_idx[m]], - p1, end1 - p1); + p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode %s\n", __func__, protected_en[m]); @@ -777,10 +777,10 @@ lws_jwe_render_flattened(struct lws_jwe *jwe, char *out, size_t out_len) } //jwe->jws.map_b64.len[protected_idx[m]] = n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\""); } - p1 += lws_snprintf(p1, end1 - p1, "\n}\n"); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\n}\n"); return lws_ptr_diff(p1, out); diff --git a/lib/jose/jwk/jwk.c b/lib/jose/jwk/jwk.c index 1ad918675..592d5a285 100644 --- a/lib/jose/jwk/jwk.c +++ b/lib/jose/jwk/jwk.c @@ -222,7 +222,7 @@ lws_jwk_dump(struct lws_jwk *jwk) } static int -_lws_jwk_set_el_jwk(struct lws_gencrypto_keyelem *e, char *in, int len) +_lws_jwk_set_el_jwk(struct lws_gencrypto_keyelem *e, char *in, size_t len) { e->buf = lws_malloc(len + 1, "jwk"); if (!e->buf) @@ -230,7 +230,7 @@ _lws_jwk_set_el_jwk(struct lws_gencrypto_keyelem *e, char *in, int len) memcpy(e->buf, in, len); e->buf[len] = '\0'; - e->len = len; + e->len = (uint32_t)len; return 0; } @@ -238,7 +238,8 @@ _lws_jwk_set_el_jwk(struct lws_gencrypto_keyelem *e, char *in, int len) static int _lws_jwk_set_el_jwk_b64(struct lws_gencrypto_keyelem *e, char *in, int len) { - int dec_size = lws_base64_size(len), n; + size_t dec_size = (unsigned int)lws_base64_size(len); + int n; e->buf = lws_malloc(dec_size, "jwk"); if (!e->buf) @@ -246,10 +247,10 @@ _lws_jwk_set_el_jwk_b64(struct lws_gencrypto_keyelem *e, char *in, int len) /* same decoder accepts both url or original styles */ - n = lws_b64_decode_string_len(in, len, (char *)e->buf, dec_size - 1); + n = lws_b64_decode_string_len(in, len, (char *)e->buf, (int)dec_size - 1); if (n < 0) return -1; - e->len = n; + e->len = (uint32_t)n; return 0; } @@ -257,7 +258,8 @@ _lws_jwk_set_el_jwk_b64(struct lws_gencrypto_keyelem *e, char *in, int len) static int _lws_jwk_set_el_jwk_b64u(struct lws_gencrypto_keyelem *e, char *in, int len) { - int dec_size = lws_base64_size(len), n; + size_t dec_size = (size_t)lws_base64_size(len); + int n; e->buf = lws_malloc(dec_size, "jwk"); if (!e->buf) @@ -265,10 +267,10 @@ _lws_jwk_set_el_jwk_b64u(struct lws_gencrypto_keyelem *e, char *in, int len) /* same decoder accepts both url or original styles */ - n = lws_b64_decode_string_len(in, len, (char *)e->buf, dec_size - 1); + n = lws_b64_decode_string_len(in, len, (char *)e->buf, (int)dec_size - 1); if (n < 0) return -1; - e->len = n; + e->len = (uint32_t)n; return 0; } @@ -299,7 +301,8 @@ cb_jwk(struct lejp_ctx *ctx, char reason) { struct lws_jwk_parse_state *jps = (struct lws_jwk_parse_state *)ctx->user; struct lws_jwk *jwk = jps->jwk; - unsigned int idx, poss, n; + unsigned int idx, n; + unsigned short poss; char dotstar[64]; if (reason == LEJPCB_VAL_STR_START) @@ -485,7 +488,7 @@ cont: if (idx & F_META) { if (_lws_jwk_set_el_jwk(&jwk->meta[idx & 0x7f], - jps->b64, jps->pos) < 0) + jps->b64, (unsigned int)jps->pos) < 0) goto bail; break; @@ -516,7 +519,7 @@ cont: } if (_lws_jwk_set_el_jwk(&jwk->e[idx & 0x7f], - jps->b64, jps->pos) < 0) + jps->b64, (unsigned int)jps->pos) < 0) goto bail; break; } @@ -553,14 +556,16 @@ lws_jwk_init_jps(struct lejp_ctx *jctx, struct lws_jwk_parse_state *jps, int lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len) { - jwk->e[LWS_GENCRYPTO_KTY_OCT].buf = lws_malloc(len, __func__); + unsigned int ulen = (unsigned int)len; + + jwk->e[LWS_GENCRYPTO_KTY_OCT].buf = lws_malloc(ulen, __func__); if (!jwk->e[LWS_GENCRYPTO_KTY_OCT].buf) return -1; jwk->kty = LWS_GENCRYPTO_KTY_OCT; - jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].len = len; + jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].len = ulen; - memcpy(jwk->e[LWS_GENCRYPTO_KTY_OCT].buf, key, len); + memcpy(jwk->e[LWS_GENCRYPTO_KTY_OCT].buf, key, ulen); return 0; } @@ -574,7 +579,7 @@ lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk, memset(jwk, 0, sizeof(*jwk)); - jwk->kty = kty; + jwk->kty = (int)kty; jwk->private_key = 1; switch (kty) { @@ -593,7 +598,7 @@ lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk, } break; case LWS_GENCRYPTO_KTY_OCT: - sn = lws_gencrypto_bits_to_bytes(bits); + sn = (unsigned int)lws_gencrypto_bits_to_bytes(bits); jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf = lws_malloc(sn, "oct"); jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].len = (uint32_t)sn; if (lws_get_random(context, @@ -682,7 +687,7 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) * ie, meta and key data elements appear interleaved in name alpha order */ - p += lws_snprintf(p, end - p, "{"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{"); switch (jwk->kty) { case LWS_GENCRYPTO_KTY_OCT: @@ -716,7 +721,7 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) if (!first) *p++ = ','; first = 0; - p += lws_snprintf(p, end - p, "\"%s\":\"%s\"", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"%s\":\"%s\"", l->name, kty_names[jwk->kty]); break; case JWK_META_KEY_OPS: @@ -726,7 +731,7 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) q = (const char *)jwk->meta[l->idx].buf; q_end = q + jwk->meta[l->idx].len; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"%s\":[", l->name); /* * For the public version, usages that @@ -748,7 +753,7 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) if (!f) *p++ = ','; f = 0; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"%s\"", tok); } q++; @@ -766,12 +771,12 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) if (!first) *p++ = ','; first = 0; - p += lws_snprintf(p, end - p, "\"%s\":\"", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"%s\":\"", l->name); lws_strnncpy(p, (const char *)jwk->meta[l->idx].buf, jwk->meta[l->idx].len, end - p); p += strlen(p); - p += lws_snprintf(p, end - p, "\""); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\""); break; } } @@ -782,7 +787,7 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) *p++ = ','; first = 0; - p += lws_snprintf(p, end - p, "\"%s\":\"", l->name); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"%s\":\"", l->name); if (jwk->kty == LWS_GENCRYPTO_KTY_EC && l->idx == (int)LWS_GENCRYPTO_EC_KEYEL_CRV) { @@ -793,19 +798,19 @@ lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) } else m = lws_jws_base64_enc( (const char *)jwk->e[l->idx].buf, - jwk->e[l->idx].len, p, end - p - 4); + jwk->e[l->idx].len, p, lws_ptr_diff_size_t(end, p) - 4); if (m < 0) { lwsl_notice("%s: enc failed\n", __func__); return -1; } p += m; - p += lws_snprintf(p, end - p, "\""); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\""); } l++; } - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), (flags & LWSJWKF_EXPORT_NOCRLF) ? "}" : "}\n"); *len -= lws_ptr_diff(p, start); @@ -817,19 +822,20 @@ int lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32) { struct lws_genhash_ctx hash_ctx; - int tmpsize = 2536, n; + size_t tmpsize = 2536; char *tmp; + int n, m = (int)tmpsize; tmp = lws_malloc(tmpsize, "rfc7638 tmp"); - n = lws_jwk_export(jwk, LWSJWKF_EXPORT_NOCRLF, tmp, &tmpsize); + n = lws_jwk_export(jwk, LWSJWKF_EXPORT_NOCRLF, tmp, &m); if (n < 0) goto bail; if (lws_genhash_init(&hash_ctx, LWS_GENHASH_TYPE_SHA256)) goto bail; - if (lws_genhash_update(&hash_ctx, tmp, n)) { + if (lws_genhash_update(&hash_ctx, tmp, (unsigned int)n)) { lws_genhash_destroy(&hash_ctx, NULL); goto bail; @@ -851,11 +857,11 @@ int lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx, const char *in, int len) { - jwk->meta[idx].buf = lws_malloc(len, __func__); + jwk->meta[idx].buf = lws_malloc((unsigned int)len, __func__); if (!jwk->meta[idx].buf) return 1; - jwk->meta[idx].len = len; - memcpy(jwk->meta[idx].buf, in, len); + jwk->meta[idx].len = (uint32_t)(unsigned int)len; + memcpy(jwk->meta[idx].buf, in, (unsigned int)len); return 0; } @@ -864,7 +870,7 @@ int lws_jwk_load(struct lws_jwk *jwk, const char *filename, lws_jwk_key_import_callback cb, void *user) { - int buflen = 4096; + unsigned int buflen = 4096; char *buf = lws_malloc(buflen, "jwk-load"); int n; @@ -875,7 +881,7 @@ lws_jwk_load(struct lws_jwk *jwk, const char *filename, if (n < 0) goto bail; - n = lws_jwk_import(jwk, cb, user, buf, n); + n = lws_jwk_import(jwk, cb, user, buf, (unsigned int)n); lws_free(buf); return n; @@ -889,7 +895,7 @@ int lws_jwk_save(struct lws_jwk *jwk, const char *filename) { int buflen = 4096; - char *buf = lws_malloc(buflen, "jwk-save"); + char *buf = lws_malloc((unsigned int)buflen, "jwk-save"); int n, m; if (!buf) @@ -899,7 +905,7 @@ lws_jwk_save(struct lws_jwk *jwk, const char *filename) if (n < 0) goto bail; - m = lws_plat_write_file(filename, buf, n); + m = lws_plat_write_file(filename, buf, (size_t)n); lws_free(buf); if (m) diff --git a/lib/jose/jws/jose.c b/lib/jose/jws/jose.c index 4d68a82b5..c9fdf5883 100644 --- a/lib/jose/jws/jose.c +++ b/lib/jose/jws/jose.c @@ -364,19 +364,19 @@ append_string: if (reason == LEJPCB_VAL_STR_END) { n = lws_b64_decode_string_len( (const char *)args->jose->e[ctx->path_match - 1].buf, - args->jose->e[ctx->path_match - 1].len, + (int)args->jose->e[ctx->path_match - 1].len, (char *)args->jose->e[ctx->path_match - 1].buf, - args->jose->e[ctx->path_match - 1].len + 1); + (int)args->jose->e[ctx->path_match - 1].len + 1); if (n < 0) { lwsl_err("%s: b64 decode failed\n", __func__); return -1; } - args->temp -= args->jose->e[ctx->path_match - 1].len - n - 1; + args->temp -= (int)args->jose->e[ctx->path_match - 1].len - n - 1; *args->temp_len += - args->jose->e[ctx->path_match - 1].len - n - 1; + (int)args->jose->e[ctx->path_match - 1].len - n - 1; - args->jose->e[ctx->path_match - 1].len = n; + args->jose->e[ctx->path_match - 1].len = (uint32_t)n; } return 0; @@ -419,13 +419,13 @@ lws_jose_parse(struct lws_jose *jose, const uint8_t *buf, int n, &jose->recipient[jose->recipients].jwk_ephemeral, NULL, NULL); - args.is_jwe = is_jwe; - args.temp = temp; - args.temp_len = temp_len; - args.jose = jose; - args.recip = 0; - args.recipients_array = 0; - jose->recipients = 0; + args.is_jwe = (unsigned int)is_jwe; + args.temp = temp; + args.temp_len = temp_len; + args.jose = jose; + args.recip = 0; + args.recipients_array = 0; + jose->recipients = 0; lejp_construct(&jctx, lws_jws_jose_cb, &args, jws_jose, LWS_ARRAY_SIZE(jws_jose)); @@ -488,7 +488,7 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, case LJJHI_ENC: /* JWE only: Optional: string */ case LJJHI_ZIP: /* JWE only: Optional: string ("DEF"=deflate) */ if (jose->e[n].buf) { - out += lws_snprintf(out, end - out, + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "%s\"%s\":\"%s\"", sub ? ",\n" : "", jws_jose[n], jose->e[n].buf); sub = 1; @@ -503,17 +503,17 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, case LJJHI_TAG: /* Additional arg for JWE AES: b64url */ case LJJHI_P2S: /* Additional arg for JWE PBES2: b64url: salt */ if (jose->e[n].buf) { - out += lws_snprintf(out, end - out, + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "%s\"%s\":\"", sub ? ",\n" : "", jws_jose[n]); sub = 1; m = lws_b64_encode_string_url((const char *) - jose->e[n].buf, jose->e[n].len, + jose->e[n].buf, (int)jose->e[n].len, out, lws_ptr_diff(end, out)); if (m < 0) return -1; out += m; - out += lws_snprintf(out, end - out, "\""); + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "\""); } break; @@ -522,17 +522,17 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, case LJJHI_X5C: /* Optional: base64 (NOT -url): actual cert */ if (jose->e[n].buf) { - out += lws_snprintf(out, end - out, + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "%s\"%s\":\"", sub ? ",\n" : "", jws_jose[n]); sub = 1; m = lws_b64_encode_string((const char *) - jose->e[n].buf, jose->e[n].len, + jose->e[n].buf, (int)jose->e[n].len, out, lws_ptr_diff(end, out)); if (m < 0) return -1; out += m; - out += lws_snprintf(out, end - out, "\""); + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "\""); } break; @@ -543,7 +543,7 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, if (!jwk || !jwk->kty) break; - out += lws_snprintf(out, end - out, "%s\"%s\":", + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "%s\"%s\":", sub ? ",\n" : "", jws_jose[n]); sub = 1; vl = lws_ptr_diff(end, out); @@ -562,7 +562,7 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, if (!jose->e[n].buf) break; - out += lws_snprintf(out, end - out, + out += lws_snprintf(out, lws_ptr_diff_size_t(end, out), "%s\"%s\":[", sub ? ",\n" : "", jws_jose[n]); sub = 1; @@ -585,7 +585,7 @@ lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, f = 0; } - *out++ = jose->e[n].buf[m]; + *out++ = (char)jose->e[n].buf[m]; m++; } diff --git a/lib/jose/jws/jws.c b/lib/jose/jws/jws.c index e2c6f2a83..549796afb 100644 --- a/lib/jose/jws/jws.c +++ b/lib/jose/jws/jws.c @@ -120,7 +120,7 @@ append_string: n = lws_b64_decode_string_len( (const char *)args->jws->map_b64.buf[m], - args->jws->map_b64.len[m], + (int)args->jws->map_b64.len[m], (char *)args->temp, *args->temp_len); if (n < 0) { lwsl_err("%s: b64 decode failed: in len %d, m %d\n", __func__, (int)args->jws->map_b64.len[m], m); @@ -129,7 +129,7 @@ append_string: args->temp += n; *args->temp_len -= n; - args->jws->map.len[m] = n; + args->jws->map.len[m] = (unsigned int)n; } return 0; @@ -218,11 +218,11 @@ lws_jws_encode_b64_element(struct lws_jws_map *map, int idx, if (*temp_len < lws_base64_size((int)in_len)) return -1; - n = lws_jws_base64_enc(in, in_len, temp, *temp_len); + n = lws_jws_base64_enc(in, in_len, temp, (size_t)*temp_len); if (n < 0) return -1; - map->len[idx] = n; + map->len[idx] = (unsigned int)n; map->buf[idx] = temp; *temp_len -= n; @@ -339,7 +339,7 @@ lws_jws_compact_decode(const char *in, int len, struct lws_jws_map *map, return -1; while (m < blocks) { - n = lws_b64_decode_string_len(map_b64->buf[m], map_b64->len[m], + n = lws_b64_decode_string_len(map_b64->buf[m], (int)map_b64->len[m], out, *out_len); if (n < 0) { lwsl_err("%s: b64 decode failed\n", __func__); @@ -350,7 +350,7 @@ lws_jws_compact_decode(const char *in, int len, struct lws_jws_map *map, map->buf[m] = out; else map->buf[m] = NULL; - map->len[m++] = n; + map->len[m++] = (unsigned int)n; out += n; *out_len -= n; @@ -368,7 +368,7 @@ lws_jws_compact_decode_map(struct lws_jws_map *map_b64, struct lws_jws_map *map, int n, m = 0; for (n = 0; n < LWS_JWS_MAX_COMPACT_BLOCKS; n++) { - n = lws_b64_decode_string_len(map_b64->buf[m], map_b64->len[m], + n = lws_b64_decode_string_len(map_b64->buf[m], (int)map_b64->len[m], out, *out_len); if (n < 0) { lwsl_err("%s: b64 decode failed\n", __func__); @@ -376,7 +376,7 @@ lws_jws_compact_decode_map(struct lws_jws_map *map_b64, struct lws_jws_map *map, } /* replace the map entry with the decoded content */ map->buf[m] = out; - map->len[m++] = n; + map->len[m++] = (unsigned int)n; out += n; *out_len -= n; @@ -400,7 +400,7 @@ lws_jws_encode_section(const char *in, size_t in_len, int first, char **p, if (!first) *(*p)++ = '.'; - n = lws_jws_base64_enc(in, in_len, *p, len - 1); + n = lws_jws_base64_enc(in, in_len, *p, (unsigned int)len - 1); if (n < 0) return -1; @@ -422,7 +422,7 @@ lws_jws_compact_encode(struct lws_jws_map *map_b64, /* b64-encoded */ map_b64->len[n] = 0; continue; } - m = lws_jws_base64_enc(map->buf[n], map->len[n], buf, *len); + m = lws_jws_base64_enc(map->buf[n], map->len[n], buf, (size_t)*len); if (m < 0) return -1; buf += m; @@ -461,7 +461,7 @@ lws_jws_sig_confirm(struct lws_jws_map *map_b64, struct lws_jws_map *map, if (!map_b64->buf[LJWS_SIG] && !map->buf[LJWS_UHDR]) b = 2; - if (lws_jws_parse_jose(&jose, map->buf[LJWS_JOSE], map->len[LJWS_JOSE], + if (lws_jws_parse_jose(&jose, map->buf[LJWS_JOSE], (int)map->len[LJWS_JOSE], temp, &temp_len) < 0 || !jose.alg) { lwsl_notice("%s: parse failed\n", __func__); return -1; @@ -571,7 +571,7 @@ lws_jws_sig_confirm(struct lws_jws_map *map_b64, struct lws_jws_map *map, /* 7) Compare the computed and decoded hashes */ - if (lws_timingsafe_bcmp(digest, map->buf[2], h_len)) { + if (lws_timingsafe_bcmp(digest, map->buf[2], (uint32_t)h_len)) { lwsl_notice("digest mismatch\n"); return -1; @@ -783,13 +783,13 @@ lws_jws_sign_from_b64(struct lws_jose *jose, struct lws_jws *jws, return -1; } - n = jws->jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len; - buf = lws_malloc(lws_base64_size(n), "jws sign"); + n = (int)jws->jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len; + buf = lws_malloc((unsigned int)lws_base64_size(n), "jws sign"); if (!buf) return -1; n = lws_genrsa_hash_sign(&rsactx, digest, jose->alg->hash_type, - buf, n); + buf, (unsigned int)n); lws_genrsa_destroy(&rsactx); if (n < 0) { lwsl_err("%s: lws_genrsa_hash_sign failed\n", __func__); @@ -798,7 +798,7 @@ lws_jws_sign_from_b64(struct lws_jose *jose, struct lws_jws *jws, return -1; } - n = lws_jws_base64_enc((char *)buf, n, b64_sig, sig_len); + n = lws_jws_base64_enc((char *)buf, (unsigned int)n, b64_sig, sig_len); lws_free(buf); if (n < 0) { lwsl_err("%s: lws_jws_base64_enc failed\n", __func__); @@ -847,14 +847,14 @@ lws_jws_sign_from_b64(struct lws_jose *jose, struct lws_jws *jws, return -1; } m = lws_gencrypto_bits_to_bytes(jose->alg->keybits_fixed) * 2; - buf = lws_malloc(m, "jws sign"); + buf = lws_malloc((unsigned int)m, "jws sign"); if (!buf) return -1; n = lws_genecdsa_hash_sign_jws(&ecdsactx, digest, jose->alg->hash_type, jose->alg->keybits_fixed, - (uint8_t *)buf, m); + (uint8_t *)buf, (unsigned int)m); lws_genec_destroy(&ecdsactx); if (n < 0) { lws_free(buf); @@ -863,7 +863,7 @@ lws_jws_sign_from_b64(struct lws_jose *jose, struct lws_jws *jws, return -1; } - n = lws_jws_base64_enc((char *)buf, m, b64_sig, sig_len); + n = lws_jws_base64_enc((char *)buf, (unsigned int)m, b64_sig, sig_len); lws_free(buf); return n; @@ -896,29 +896,29 @@ lws_jws_write_flattened_json(struct lws_jws *jws, char *flattened, size_t len) if (len < 1) return 1; - n += lws_snprintf(flattened + n, len - n , "{\"payload\": \""); + n += (unsigned int)lws_snprintf(flattened + n, len - n , "{\"payload\": \""); lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_PYLD], jws->map_b64.len[LJWS_PYLD], len - n); - n += strlen(flattened + n); + n = n + strlen(flattened + n); - n += lws_snprintf(flattened + n, len - n , "\",\n \"protected\": \""); + n += (unsigned int)lws_snprintf(flattened + n, len - n , "\",\n \"protected\": \""); lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_JOSE], jws->map_b64.len[LJWS_JOSE], len - n); - n += strlen(flattened + n); + n = n + strlen(flattened + n); if (jws->map_b64.buf[LJWS_UHDR]) { - n += lws_snprintf(flattened + n, len - n , "\",\n \"header\": "); + n += (unsigned int)lws_snprintf(flattened + n, len - n , "\",\n \"header\": "); lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_UHDR], jws->map_b64.len[LJWS_UHDR], len - n); - n += strlen(flattened + n); + n = n + strlen(flattened + n); } - n += lws_snprintf(flattened + n, len - n , "\",\n \"signature\": \""); + n += (unsigned int)lws_snprintf(flattened + n, len - n , "\",\n \"signature\": \""); lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_SIG], jws->map_b64.len[LJWS_SIG], len - n); - n += strlen(flattened + n); + n = n + strlen(flattened + n); - n += lws_snprintf(flattened + n, len - n , "\"}\n"); + n += (unsigned int)lws_snprintf(flattened + n, len - n , "\"}\n"); return (n >= len - 1); } @@ -969,7 +969,7 @@ lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, * blocks */ - n = lws_jws_compact_decode(com, (int)len, &jws.map, &jws.map_b64, + n = (size_t)lws_jws_compact_decode(com, (int)len, &jws.map, &jws.map_b64, temp, &tl); if (n != 3) { lwsl_err("%s: concat_map failed: %d\n", __func__, (int)n); @@ -984,7 +984,7 @@ lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, */ if (lws_jws_parse_jose(&jose, jws.map.buf[LJWS_JOSE], - jws.map.len[LJWS_JOSE], temp, &tl) < 0) { + (int)jws.map.len[LJWS_JOSE], temp, &tl) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); goto bail; } @@ -998,7 +998,7 @@ lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, n = strlen(jose.alg->alg); do { - ts.e = lws_tokenize(&ts); + ts.e = (int8_t)lws_tokenize(&ts); if (ts.e == LWS_TOKZE_TOKEN && ts.token_len == n && !strncmp(jose.alg->alg, ts.token, ts.token_len)) break; @@ -1067,8 +1067,8 @@ lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, return 1; } - jws.map.len[LJWS_JOSE] = lws_snprintf((char *)jws.map.buf[LJWS_JOSE], - tl, "{\"alg\":\"%s\"}", alg); + jws.map.len[LJWS_JOSE] = (uint32_t)lws_snprintf((char *)jws.map.buf[LJWS_JOSE], + (size_t)tl, "{\"alg\":\"%s\"}", alg); temp += otl - tl; otl = tl; @@ -1079,18 +1079,18 @@ lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, if (n + 2 >= tl) goto bail; - q = lws_malloc(n + 2, __func__); + q = lws_malloc((unsigned int)n + 2, __func__); if (!q) goto bail; va_start(ap, format); - vsnprintf(q, n + 2, format, ap); + vsnprintf(q, (unsigned int)n + 2, format, ap); va_end(ap); /* add the plaintext from stdin to the map and a b64 version */ jws.map.buf[LJWS_PYLD] = q; - jws.map.len[LJWS_PYLD] = n; + jws.map.len[LJWS_PYLD] = (uint32_t)n; if (lws_jws_encode_b64_element(&jws.map_b64, LJWS_PYLD, temp, &tl, jws.map.buf[LJWS_PYLD], @@ -1113,7 +1113,7 @@ lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, /* prepare the space for the b64 signature in the map */ if (lws_jws_alloc_element(&jws.map_b64, LJWS_SIG, temp, &tl, - lws_base64_size(LWS_JWE_LIMIT_KEY_ELEMENT_BYTES), + (size_t)lws_base64_size(LWS_JWE_LIMIT_KEY_ELEMENT_BYTES), 0)) goto bail1; @@ -1126,7 +1126,7 @@ lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, goto bail1; /* set the actual b64 signature size */ - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (uint32_t)n; /* create the compact JWS representation */ if (lws_jws_write_compact(&jws, out, *out_len)) diff --git a/lib/misc/base64-decode.c b/lib/misc/base64-decode.c index a47743df7..f8e8e49a4 100644 --- a/lib/misc/base64-decode.c +++ b/lib/misc/base64-decode.c @@ -59,7 +59,7 @@ _lws_b64_encode_string(const char *encode, const char *in, int in_len, int len = 0; for (i = 0; i < 3; i++) { if (in_len) { - triple[i] = *in++; + triple[i] = (unsigned char)*in++; len++; in_len--; } else @@ -121,20 +121,20 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, v = 0; s->c = 0; while (in < end_in && *in && !v) { - s->c = v = *in++; + s->c = v = (unsigned char)*in++; /* support the url base64 variant too */ if (v == '-') s->c = v = '+'; if (v == '_') s->c = v = '/'; - v = (v < 43 || v > 122) ? 0 : decode[v - 43]; + v = (uint8_t)((v < 43 || v > 122) ? 0 : decode[v - 43]); if (v) - v = (v == '$') ? 0 : v - 61; + v = (uint8_t)((v == '$') ? 0 : v - 61); } if (s->c) { s->len++; if (v) - s->quad[s->i] = v - 1; + s->quad[s->i] = (uint8_t)(v - 1); } else s->quad[s->i] = 0; } @@ -154,19 +154,19 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, s->len--; if (s->len >= 2) - *out++ = s->quad[0] << 2 | s->quad[1] >> 4; + *out++ = (uint8_t)(s->quad[0] << 2 | s->quad[1] >> 4); if (s->len >= 3) - *out++ = s->quad[1] << 4 | s->quad[2] >> 2; + *out++ = (uint8_t)(s->quad[1] << 4 | s->quad[2] >> 2); if (s->len >= 4) - *out++ = ((s->quad[2] << 6) & 0xc0) | s->quad[3]; + *out++ = (uint8_t)(((s->quad[2] << 6) & 0xc0) | s->quad[3]); s->done += s->len - 1; s->len = 0; } *out = '\0'; - *in_len = in - orig_in; - *out_size = out - orig_out; + *in_len = (unsigned int)(in - orig_in); + *out_size = (unsigned int)(out - orig_out); return 0; } @@ -181,7 +181,7 @@ lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, */ static size_t -_lws_b64_decode_string(const char *in, int in_len, char *out, int out_size) +_lws_b64_decode_string(const char *in, int in_len, char *out, size_t out_size) { struct lws_b64state state; size_t il = (size_t)in_len, ol = out_size; @@ -201,13 +201,13 @@ _lws_b64_decode_string(const char *in, int in_len, char *out, int out_size) int lws_b64_decode_string(const char *in, char *out, int out_size) { - return (int)_lws_b64_decode_string(in, -1, out, out_size); + return (int)_lws_b64_decode_string(in, -1, out, (unsigned int)out_size); } int lws_b64_decode_string_len(const char *in, int in_len, char *out, int out_size) { - return (int)_lws_b64_decode_string(in, in_len, out, out_size); + return (int)_lws_b64_decode_string(in, in_len, out, (unsigned int)out_size); } #if 0 diff --git a/lib/misc/daemonize.c b/lib/misc/daemonize.c index ef066f160..6dec9d6f7 100644 --- a/lib/misc/daemonize.c +++ b/lib/misc/daemonize.c @@ -64,7 +64,7 @@ child_handler(int signum) exit(0); } len = sprintf(sz, "%u", (unsigned int)pid_daemon); - sent = write(fd, sz, len); + sent = (int)write(fd, sz, (size_t)len); if (sent != len) fprintf(stderr, "unable to write pid to lock file %s, code=%d (%s)\n", @@ -117,7 +117,7 @@ lws_daemonize(const char *_lock_path) if (fd >= 0) { char buf[10]; - n = read(fd, buf, sizeof(buf)); + n = (int)read(fd, buf, sizeof(buf)); close(fd); if (n) { int ret; @@ -136,8 +136,8 @@ lws_daemonize(const char *_lock_path) } } - n = strlen(_lock_path) + 1; - lock_path = lws_malloc(n, "daemonize lock"); + n = (int)strlen(_lock_path) + 1; + lock_path = lws_malloc((unsigned int)n, "daemonize lock"); if (!lock_path) { fprintf(stderr, "Out of mem in lws_daemonize\n"); return 1; diff --git a/lib/misc/dir.c b/lib/misc/dir.c index 5af02eebb..c0a4f7718 100644 --- a/lib/misc/dir.c +++ b/lib/misc/dir.c @@ -120,7 +120,7 @@ lws_dir(const char *dirpath, void *user, lws_dir_callback_function cb) char combo[COMBO_SIZEOF]; size_t l; - l = lws_snprintf(combo, COMBO_SIZEOF - 2, "%s", dirpath); + l = (size_t)(ssize_t)lws_snprintf(combo, COMBO_SIZEOF - 2, "%s", dirpath); combo[l++] = csep; combo[l] = '\0'; diff --git a/lib/misc/diskcache.c b/lib/misc/diskcache.c index a73d0a24d..bfc629aec 100644 --- a/lib/misc/diskcache.c +++ b/lib/misc/diskcache.c @@ -89,7 +89,7 @@ fe_modified_sort(lws_list_ptr a, lws_list_ptr b) { struct file_entry *p1 = lp_to_fe(a, sorted), *p2 = lp_to_fe(b, sorted); - return p2->modified - p1->modified; + return (int)((long)p2->modified - (long)p1->modified); } struct lws_diskcache_scan * @@ -118,27 +118,27 @@ lws_diskcache_destroy(struct lws_diskcache_scan **lds) } int -lws_diskcache_prepare(const char *cache_base_dir, int mode, int uid) +lws_diskcache_prepare(const char *cache_base_dir, int mode, uid_t uid) { char dir[256]; int n, m; - (void)mkdir(cache_base_dir, mode); - if (chown(cache_base_dir, uid, -1)) + (void)mkdir(cache_base_dir, (unsigned short)mode); + if (chown(cache_base_dir, uid, (gid_t)-1)) lwsl_err("%s: %s: unable to chown %d\n", __func__, cache_base_dir, uid); for (n = 0; n < 16; n++) { lws_snprintf(dir, sizeof(dir), "%s/%c", cache_base_dir, hex[n]); - (void)mkdir(dir, mode); - if (chown(dir, uid, -1)) + (void)mkdir(dir, (mode_t)mode); + if (chown(dir, uid, (uid_t)-1)) lwsl_err("%s: %s: unable to chown %d\n", __func__, dir, uid); for (m = 0; m < 16; m++) { lws_snprintf(dir, sizeof(dir), "%s/%c/%c", cache_base_dir, hex[n], hex[m]); - (void)mkdir(dir, mode); - if (chown(dir, uid, -1)) + (void)mkdir(dir, (mode_t)mode); + if (chown(dir, uid, (uid_t)-1)) lwsl_err("%s: %s: unable to chown %d\n", __func__, dir, uid); } @@ -187,7 +187,7 @@ lws_diskcache_query(struct lws_diskcache_scan *lds, int is_bot, if (!is_bot) lds->cache_tries++; - n = lws_snprintf(cache, cache_len, "%s/%c/%c/%s", lds->cache_dir_base, + n = lws_snprintf(cache, (size_t)cache_len, "%s/%c/%c/%s", lds->cache_dir_base, hash_hex[0], hash_hex[1], hash_hex); lwsl_info("%s: job cache %s\n", __func__, cache); @@ -221,7 +221,7 @@ lws_diskcache_query(struct lws_diskcache_scan *lds, int is_bot, /* let's create it first with a unique temp name */ - lws_snprintf(cache + n, cache_len - n, "~%d-%p", (int)getpid(), + lws_snprintf(cache + n, (size_t)cache_len - (unsigned int)n, "~%d-%p", (int)getpid(), extant_cache_len); *_fd = open(cache, O_RDWR | O_CREAT | O_TRUNC, 0600); @@ -271,7 +271,7 @@ lws_diskcache_secs_to_idle(struct lws_diskcache_scan *lds) int lws_diskcache_trim(struct lws_diskcache_scan *lds) { - size_t cache_size_limit = lds->cache_size_limit; + size_t cache_size_limit = (size_t)lds->cache_size_limit; char dirpath[132], filepath[132 + 32]; lws_list_ptr lp, op = NULL; int files_trimmed = 0; @@ -338,7 +338,7 @@ lws_diskcache_trim(struct lws_diskcache_scan *lds) continue; } - lds->agg_size += s.st_size; + lds->agg_size += (uint64_t)s.st_size; if (lds->batch_in_use == BATCH_COUNT) { /* @@ -365,7 +365,7 @@ lws_diskcache_trim(struct lws_diskcache_scan *lds) strncpy(p->name, de->d_name, sizeof(p->name) - 1); p->name[sizeof(p->name) - 1] = '\0'; p->modified = s.st_mtime; - p->size = s.st_size; + p->size = (size_t)s.st_size; lws_list_ptr_insert(&lds->head, &p->sorted, fe_modified_sort); } while (de); @@ -429,7 +429,7 @@ lws_diskcache_trim(struct lws_diskcache_scan *lds) } if (lds->agg_size && lds->agg_file_count) - lds->avg_size = lds->agg_size / lds->agg_file_count; + lds->avg_size = lds->agg_size / (uint64_t)lds->agg_file_count; /* * estimate how long we can go before scanning again... default we need @@ -444,7 +444,7 @@ lws_diskcache_trim(struct lws_diskcache_scan *lds) /* let's use 80% of the real average for margin */ if (lds->agg_size && lds->agg_file_count) - avg = ((lds->agg_size * 8) / lds->agg_file_count) / 10; + avg = ((lds->agg_size * 8) / (uint64_t)lds->agg_file_count) / 10; /* * if we collected BATCH_COUNT files of the average size, @@ -459,8 +459,8 @@ lws_diskcache_trim(struct lws_diskcache_scan *lds) projected = (lds->agg_size * 11) / 10; if (projected < cache_size_limit) /* no... */ - lds->secs_waiting = (256 / 2) * ((cache_size_limit - - projected) / capacity); + lds->secs_waiting = (int)((256 / 2) * ((cache_size_limit - + projected) / capacity)); /* * large waits imply we may not have enough info yet, so diff --git a/lib/misc/fsmount.c b/lib/misc/fsmount.c index c951a3e1b..bc9669a4b 100644 --- a/lib/misc/fsmount.c +++ b/lib/misc/fsmount.c @@ -99,16 +99,16 @@ lws_fsmount_mount(struct lws_fsmount *fsm) if (n != 9) opts[n++] = ':'; - n += lws_snprintf(&opts[n], sizeof(opts) - n, + n += lws_snprintf(&opts[n], (size_t)(sizeof(opts) - (unsigned int)n), "%s/%s/%s", fsm->layers_path, fsm->distro, fsm->layers[m]); } - n += lws_snprintf(&opts[n], sizeof(opts) - n, + n += lws_snprintf(&opts[n], (size_t)(sizeof(opts) - (unsigned int)n), ",upperdir=%s/overlays/%s/session", fsm->overlay_path, fsm->ovname); - n += lws_snprintf(&opts[n], sizeof(opts) - n, + n += lws_snprintf(&opts[n], (size_t)(sizeof(opts) - (unsigned int)n), ",workdir=%s/overlays/%s/work", fsm->overlay_path, fsm->ovname); diff --git a/lib/misc/fts/trie-fd.c b/lib/misc/fts/trie-fd.c index 5db2993f0..c67165b36 100644 --- a/lib/misc/fts/trie-fd.c +++ b/lib/misc/fts/trie-fd.c @@ -72,13 +72,13 @@ struct linetable { static uint32_t b32(unsigned char *b) { - return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; + return (uint32_t)((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]); } static uint16_t b16(unsigned char *b) { - return (b[0] << 8) | b[1]; + return (uint16_t)((b[0] << 8) | b[1]); } static int @@ -94,25 +94,25 @@ lws_fts_filepath(struct lws_fts_file *jtf, int filepath_index, char *result, if (filepath_index > jtf->filepaths) return 1; - if (lseek(jtf->fd, jtf->filepath_table + (4 * filepath_index), + if (lseek(jtf->fd, (off_t)(jtf->filepath_table + (4 * (unsigned int)filepath_index)), SEEK_SET) < 0) { lwsl_err("%s: unable to seek\n", __func__); return 1; } - ra = read(jtf->fd, buf, 4); + ra = (int)read(jtf->fd, buf, 4); if (ra < 0) return 1; - o = (unsigned int)b32(buf); + o = (off_t)b32(buf); if (lseek(jtf->fd, o, SEEK_SET) < 0) { lwsl_err("%s: unable to seek\n", __func__); return 1; } - ra = read(jtf->fd, buf, sizeof(buf)); + ra = (int)read(jtf->fd, buf, sizeof(buf)); if (ra < 0) return 1; @@ -170,7 +170,7 @@ lws_fts_adopt(struct lws_fts_file *jtf) goto bail; } - jtf->flen = ot; + jtf->flen = (jg2_file_offset)ot; if (jtf->flen != b32(&buf[8])) { lwsl_err("%s: file size doesn't match expected\n", __func__); @@ -179,7 +179,7 @@ lws_fts_adopt(struct lws_fts_file *jtf) } jtf->filepath_table = b32(&buf[12]); - jtf->filepaths = b32(&buf[16]); + jtf->filepaths = (int)b32(&buf[16]); return jtf->fd; @@ -224,13 +224,13 @@ lws_fts_close(struct lws_fts_file *jtf) #define grab(_pos, _size) { \ bp = 0; \ - if (lseek(jtf->fd, _pos, SEEK_SET) < 0) { \ + if (lseek(jtf->fd, (off_t)(_pos), SEEK_SET) < 0) { \ lwsl_err("%s: unable to seek\n", __func__); \ \ goto bail; \ } \ \ - ra = read(jtf->fd, buf, _size); \ + ra = (int)read(jtf->fd, buf, (size_t)(_size)); \ if (ra < 0) \ goto bail; \ } @@ -262,12 +262,12 @@ lws_fts_cache_chunktable(struct lws_fts_file *jtf, uint32_t ofs_linetable, lt->chunk_line_number_start = line; lt->chunk_line_number_count = b16(&buf[bp + 2]); - lt->vli_ofs_in_index = ofs_linetable + 8; + lt->vli_ofs_in_index = (off_t)(ofs_linetable + 8); lt->chunk_filepos_start = cfs; line += lt->chunk_line_number_count; - cfs += b32(&buf[bp + 4]); + cfs += (int32_t)b32(&buf[bp + 4]); ofs_linetable += b16(&buf[bp]); } while (b16(&buf[bp])); @@ -314,7 +314,7 @@ lws_fts_getfileoffset(struct lws_fts_file *jtf, struct linetable *ltstart, bp = 0; while (line) { bp += rq32(&buf[bp], &ll); - ofs += ll; + ofs += (int32_t)ll; line--; } @@ -347,7 +347,7 @@ ac_record(struct lws_fts_file *jtf, struct lwsac **results_head, for (n = 1; n <= sp; n++) m += s[n].ch[s[n].child - 1].name_length; - ac = lwsac_use(results_head, sizeof(*ac) + m + 1, 0); + ac = lwsac_use(results_head, sizeof(*ac) + (unsigned int)m + 1, 0); if (!ac) return -1; @@ -356,19 +356,19 @@ ac_record(struct lws_fts_file *jtf, struct lwsac **results_head, **ppac = ac; ac->next = NULL; *ppac = &ac->next; - ac->instances = instances; - ac->agg_instances = agg_instances; + ac->instances = (int)instances; + ac->agg_instances = (int)agg_instances; ac->ac_length = m; ac->has_children = !!children; ac->elided = 0; - memcpy(p, needle, pos); + memcpy(p, needle, (size_t)pos); p += pos; for (n = 1; n <= sp; n++) { int w = s[n].child - 1; - memcpy(p, s[n].ch[w].name, s[n].ch[w].name_length); + memcpy(p, s[n].ch[w].name, (size_t)s[n].ch[w].name_length); p += s[n].ch[w].name_length; } p = (char *)(ac + 1); @@ -380,8 +380,8 @@ ac_record(struct lws_fts_file *jtf, struct lwsac **results_head, * best results (children are sorted best-first) */ for (n = sp; n >= 0; n--) { - s[n].ch[s[n].child - 1].child_agg -= instances; - s[n].agg -= instances; + s[n].ch[s[n].child - 1].child_agg -= (int)instances; + s[n].agg -= (int)instances; } return 0; @@ -393,7 +393,7 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) uint32_t children, instances, co, sl, agg, slt, chunk, fileofs_tif_start, desc, agg_instances; int pos = 0, n, m, nl, bp, base = 0, ra, palm, budget, sp, ofd = -1; - unsigned long long tf = lws_now_usecs(); + unsigned long long tf = (unsigned long long)lws_now_usecs(); struct lws_fts_result_autocomplete **pac = NULL; char stasis, nac = 0, credible, needle[32]; struct lws_fts_result_filepath *fp; @@ -426,10 +426,10 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) palm = 0; for (n = 0; n < nl; n++) - needle[n] = tolower(ftsp->needle[n]); + needle[n] = (char)tolower(ftsp->needle[n]); needle[nl] = '\0'; - o = jtf->root; + o = (off_t)jtf->root; do { bp = 0; base = 0; @@ -458,7 +458,7 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) /* we leave with bp positioned at the instance list */ - o = fileofs_tif_start; + o = (off_t)fileofs_tif_start; grab(o, sizeof(buf)); break; } @@ -493,7 +493,7 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) * our needle string (but that leaves it as a * perfectly fine autocomplete candidate) */ - size_t g = nl - pos; + size_t g = (size_t)(nl - pos); /* * "credible" means at least one child matches @@ -512,7 +512,7 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) agg_instances -= agg; nac = 0; - bp += sl; + bp += (int)sl; slt = 0; pos = palm; goto ensure; @@ -531,7 +531,7 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) * not needed due to a match fail. */ - chunk = ra - bp; + chunk = (uint32_t)(ra - bp); if (chunk > slt) chunk = slt; @@ -543,21 +543,21 @@ lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp) * it doesn't match... so nothing can * autocomplete this... */ - bp += slt; + bp += (int)slt; slt = 0; nac = 1; goto ensure; } slt -= chunk; - pos += chunk; - bp += chunk; + pos += (int)chunk; + bp += (int)chunk; /* so far, it matches */ if (!slt) { /* we matched the whole thing */ - o = co; + o = (int32_t)co; if (!co) goto bail; n = (int)children; @@ -598,7 +598,7 @@ ensure: } } while(1); - result->duration_ms = (int)((lws_now_usecs() - tf) / 1000); + result->duration_ms = (int)(((uint64_t)lws_now_usecs() - tf) / 1000); if (!instances && !children) return result; @@ -626,16 +626,16 @@ ensure: ofd = -1; grab(o, sizeof(buf)); - ro = o; + ro = (uint32_t)o; bp += rq32(&buf[bp], &_o); - o = _o; + o = (off_t)_o; assert(!o || o > TRIE_FILE_HDR_SIZE); bp += rq32(&buf[bp], &fi); bp += rq32(&buf[bp], &tot); - if (lws_fts_filepath(jtf, fi, path, sizeof(path) - 1, + if (lws_fts_filepath(jtf, (int)fi, path, sizeof(path) - 1, &ofs_linetable, &lines)) { lwsl_err("can't get filepath index %d\n", fi); goto bail; @@ -656,27 +656,27 @@ ensure: } } - fplen = (int)strlen(path); - footprint = sizeof(*fp) + fplen + 1; + fplen = (uint32_t)strlen(path); + footprint = (int)(sizeof(*fp) + fplen + 1); if (ftsp->flags & LWSFTS_F_QUERY_FILE_LINES) { /* line number and offset in file */ - footprint += 2 * sizeof(uint32_t) * tot; + footprint += (int)(2 * sizeof(uint32_t) * tot); if (ftsp->flags & LWSFTS_F_QUERY_QUOTE_LINE) /* pointer to quote string */ - footprint += sizeof(void *) * tot; + footprint += (int)(sizeof(void *) * tot); } - fp = lwsac_use(&ftsp->results_head, footprint, 0); + fp = lwsac_use(&ftsp->results_head, (unsigned int)footprint, 0); if (!fp) { lwsac_free(<_head); goto bail; } - fp->filepath_length = fplen; - fp->lines_in_file = lines; - fp->matches = tot; - fp->matches_length = footprint - sizeof(*fp) - (fplen + 1); + fp->filepath_length = (int)fplen; + fp->lines_in_file = (int)lines; + fp->matches = (int)tot; + fp->matches_length = footprint - (int)sizeof(*fp) - (int)(fplen + 1); fp->next = result->filepath_head; result->filepath_head = fp; @@ -697,13 +697,13 @@ ensure: if ((ra - bp) < 8) { base += bp; - grab(ro + base, sizeof(buf)); + grab((int32_t)ro + base, sizeof(buf)); } bp += rq32(&buf[bp], &line); *u++ = line; - if (lws_fts_getfileoffset(jtf, ltst, line, &fo)) + if (lws_fts_getfileoffset(jtf, ltst, (int)line, &fo)) continue; *u++ = (uint32_t)fo; @@ -714,7 +714,7 @@ ensure: if (lseek(ofd, fo, SEEK_SET) < 0) continue; - m = read(ofd, lbuf, sizeof(lbuf) - 1); + m = (int)read(ofd, lbuf, sizeof(lbuf) - 1); if (m < 0) continue; lbuf[sizeof(lbuf) - 1] = '\0'; @@ -732,13 +732,13 @@ ensure: sizeof(ebuf) - 1, NULL); m = (int)strlen(ebuf); - p = lwsac_use(&ftsp->results_head, m + 1, 0); + p = lwsac_use(&ftsp->results_head, (unsigned int)m + 1, 0); if (!p) { lwsac_free(<_head); goto bail; } - memcpy(p, ebuf, m); + memcpy(p, ebuf, (unsigned int)m); p[m] = '\0'; v = (const char **)u; *v = (const char *)p; @@ -830,7 +830,7 @@ autocomp: s[sp].child = 1; s[sp].tifs = fileofs_tif_start; - s[sp].self = child_ofs; + s[sp].self = (jg2_file_offset)child_ofs; s[sp].ch[0].effpos = pos; if (pos == nl) @@ -852,8 +852,8 @@ autocomp: tch->effpos + tch->name_length >= nl && tch->inst && fileofs_tif_start) { n = ac_record(jtf, &ftsp->results_head, needle, pos, s, - sp, tch->inst, tch->child_agg, - tch->descendents, &pac); + sp, (uint32_t)tch->inst, (uint32_t)tch->child_agg, + (uint32_t)tch->descendents, &pac); if (n < 0) goto bail; if (!n) @@ -866,7 +866,7 @@ autocomp: sp++; memset(&s[sp], 0, sizeof(s[sp])); s[sp].tifs = fileofs_tif_start; - s[sp].self = child_ofs; + s[sp].self = (jg2_file_offset)child_ofs; for (n = 0; n < (int)children && s[sp].child_count < (int)LWS_ARRAY_SIZE(s[0].ch); n++) { @@ -886,16 +886,16 @@ autocomp: max = sizeof(ch->name) - 1; strncpy(ch->name, (char *)&buf[bp], max); - bp += slen; + bp += (int)slen; ch->name_length = (int)max; ch->name[sizeof(ch->name) - 1] = '\0'; - ch->inst = inst; + ch->inst = (int)inst; ch->effpos = s[sp - 1].ch[s[sp - 1].child - 1].effpos; - ch->child_agg = agg; - ch->descendents = desc; + ch->child_agg = (int)agg; + ch->descendents = (int)desc; /* * if we have more needle chars than we matched @@ -909,7 +909,7 @@ autocomp: m = ch->name_length; if (m > 0 && - strncmp(&needle[ch->effpos], ch->name, m)) + strncmp(&needle[ch->effpos], ch->name, (unsigned int)m)) continue; ch->effpos += m; @@ -951,7 +951,7 @@ autocomp: for (m = n; m < sp + 1; m++) s[m].done_children = 0; sp = n; - child_ofs = s[sp].ch[s[sp].child++].ofs; + child_ofs = (off_t)s[sp].ch[s[sp].child++].ofs; nobump = 1; } @@ -961,7 +961,7 @@ autocomp: if (nobump || sp < 0) continue; - child_ofs = s[sp].ch[s[sp].child++].ofs; + child_ofs = (off_t)s[sp].ch[s[sp].child++].ofs; } /* let's do a final sort into agg order */ diff --git a/lib/misc/fts/trie.c b/lib/misc/fts/trie.c index 792cca0ef..8b4317e5d 100644 --- a/lib/misc/fts/trie.c +++ b/lib/misc/fts/trie.c @@ -168,23 +168,23 @@ struct lws_fts { #define TRIE_LWSAC_BLOCK_SIZE (1024 * 1024) #define spill(margin, force) \ - if (bp && ((uint32_t)bp >= (sizeof(buf) - (margin)) || (force))) { \ - if (write(t->fd, buf, bp) != bp) { \ + if (bp && ((uint32_t)bp >= (sizeof(buf) - (size_t)(margin)) || (force))) { \ + if ((int)write(t->fd, buf, (size_t)bp) != bp) { \ lwsl_err("%s: write %d failed (%d)\n", __func__, \ bp, errno); \ return 1; \ } \ - t->c += bp; \ + t->c += (unsigned int)bp; \ bp = 0; \ } static int g32(unsigned char *b, uint32_t d) { - *b++ = (d >> 24) & 0xff; - *b++ = (d >> 16) & 0xff; - *b++ = (d >> 8) & 0xff; - *b = d & 0xff; + *b++ = (uint8_t)((d >> 24) & 0xff); + *b++ = (uint8_t)((d >> 16) & 0xff); + *b++ = (uint8_t)((d >> 8) & 0xff); + *b = (uint8_t)(d & 0xff); return 4; } @@ -192,8 +192,8 @@ g32(unsigned char *b, uint32_t d) static int g16(unsigned char *b, int d) { - *b++ = (d >> 8) & 0xff; - *b = d & 0xff; + *b++ = (uint8_t)((d >> 8) & 0xff); + *b = (uint8_t)(d & 0xff); return 2; } @@ -204,20 +204,20 @@ wq32(unsigned char *b, uint32_t d) unsigned char *ob = b; if (d > (1 << 28) - 1) - *b++ = ((d >> 28) | 0x80) & 0xff; + *b++ = (uint8_t)(((d >> 28) | 0x80) & 0xff); if (d > (1 << 21) - 1) - *b++ = ((d >> 21) | 0x80) & 0xff; + *b++ = (uint8_t)(((d >> 21) | 0x80) & 0xff); if (d > (1 << 14) - 1) - *b++ = ((d >> 14) | 0x80) & 0xff; + *b++ = (uint8_t)(((d >> 14) | 0x80) & 0xff); if (d > (1 << 7) - 1) - *b++ = ((d >> 7) | 0x80) & 0xff; + *b++ = (uint8_t)(((d >> 7) | 0x80) & 0xff); - *b++ = d & 0x7f; + *b++ = (uint8_t)(d & 0x7f); - return (int)(b - ob); + return lws_ptr_diff(b, ob); } @@ -403,9 +403,9 @@ finalize_per_input(struct lws_fts *t) bp += g16(&buf[bp], 0); bp += g16(&buf[bp], 0); bp += g32(&buf[bp], 0); - if (write(t->fd, buf, bp) != bp) + if ((int)write(t->fd, buf, (size_t)bp) != bp) return 1; - t->c += bp; + t->c += (unsigned int)bp; bp = 0; /* @@ -432,7 +432,7 @@ finalize_per_input(struct lws_fts *t) temp = tif->owner->ofs_last_inst_file; if (tif->total) - tif->owner->ofs_last_inst_file = t->c + bp; + tif->owner->ofs_last_inst_file = t->c + (unsigned int)bp; assert(!temp || (temp > TRIE_FILE_HDR_SIZE && temp < t->c)); @@ -444,13 +444,13 @@ finalize_per_input(struct lws_fts *t) /* remove any pointers into this disposable lac footprint */ tif->owner->inst_file_list = NULL; - memcpy(&buf[bp], &tif->vli, tif->count); + memcpy(&buf[bp], &tif->vli, (size_t)tif->count); bp += tif->count; i = tif->lines_list; while (i) { spill(i->count, 0); - memcpy(&buf[bp], &i->vli, i->count); + memcpy(&buf[bp], &i->vli, (size_t)i->count); bp += i->count; i = i->lines_next; @@ -543,7 +543,7 @@ int lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, size_t len) { - unsigned long long tf = lws_now_usecs(); + unsigned long long tf = (unsigned long long)lws_now_usecs(); unsigned char c, linetable[256], vlibuf[8]; struct lws_fts_entry *e, *e1, *dcl; struct lws_fts_instance_file *tif; @@ -556,7 +556,7 @@ lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, if ((int)file_index != t->last_file_index) { if (t->last_file_index >= 0) finalize_per_input(t); - t->last_file_index = file_index; + t->last_file_index = (int)file_index; t->line_number = 1; t->chars_in_line = 0; t->lines_in_unsealed_linetable = 0; @@ -567,7 +567,7 @@ lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, resume: chars = 0; - lbh = t->c; + lbh = (off_t)t->c; sline = t->line_number; bp += g16(&linetable[bp], 0); bp += g16(&linetable[bp], 0); @@ -589,14 +589,14 @@ resume: t->lines_in_unsealed_linetable++; t->line_number++; - bp += wq32(&linetable[bp], t->chars_in_line); + bp += wq32(&linetable[bp], (uint32_t)t->chars_in_line); if ((unsigned int)bp > sizeof(linetable) - 6) { - if (write(t->fd, linetable, bp) != bp) { + if ((int)write(t->fd, linetable, (unsigned int)bp) != bp) { lwsl_err("%s: linetable write failed\n", __func__); return 1; } - t->c += bp; + t->c += (unsigned int)bp; bp = 0; // assert(lseek(t->fd, 0, SEEK_END) == t->c); } @@ -634,7 +634,7 @@ resume: if (!m) goto seal; if (m == 2) - c += 'a' - 'A'; + c = (unsigned char)((char)c + 'a' - 'A'); if (t->aggregate) { @@ -826,12 +826,12 @@ seal: */ dcl = t->parser->child_list; - m = t->parser->child_count; + m = (int)t->parser->child_count; t->parser->child_list = NULL; t->parser->child_count = 0; - e = lws_fts_entry_child_add(t, + e = lws_fts_entry_child_add(t, (unsigned char) osuff[t->str_match_pos - 1], t->parser); if (!e) { lwsl_err("%s: lws_fts_entry_child_add fail1\n", @@ -840,7 +840,7 @@ seal: } e->child_list = dcl; - e->child_count = m; + e->child_count = (uint32_t)m; /* * any children we took over must point to us as the * parent now they appear on our child list @@ -942,7 +942,7 @@ seal: } /* add the first char at the beginning */ - *t->parser->suffix = t->parser->c; + *t->parser->suffix = (char)t->parser->c; /* and then add the agg buffer stuff */ memcpy(t->parser->suffix + 1, t->agg, t->agg_pos); t->parser->suffix_len = t->agg_pos + 1; @@ -988,14 +988,14 @@ seal: * more vli space and continues chaining those if needed. */ - n = wq32(vlibuf, t->line_number); + n = (unsigned int)wq32(vlibuf, (uint32_t)t->line_number); tif = t->parser->inst_file_list; if (!tif->lines_list) { /* we are still trying to use the file inst vli */ - if (LWS_ARRAY_SIZE(tif->vli) - tif->count >= n) { - tif->count += wq32(tif->vli + tif->count, - t->line_number); + if (LWS_ARRAY_SIZE(tif->vli) - (size_t)tif->count >= n) { + tif->count = (char)((char)tif->count + (char)wq32(tif->vli + tif->count, + (uint32_t)t->line_number)); goto after; } /* we are going to have to allocate */ @@ -1004,10 +1004,10 @@ seal: /* can we add to an existing line numbers struct? */ if (tif->lines_tail && LWS_ARRAY_SIZE(tif->lines_tail->vli) - - tif->lines_tail->count >= n) { - tif->lines_tail->count += wq32(tif->lines_tail->vli + + (unsigned char)tif->lines_tail->count >= n) { + tif->lines_tail->count = (char)((char)tif->lines_tail->count + (char)wq32(tif->lines_tail->vli + tif->lines_tail->count, - t->line_number); + (uint32_t)t->line_number)); goto after; } @@ -1028,7 +1028,7 @@ seal: if (!tif->lines_list) tif->lines_list = tl; - tl->count = wq32(tl->vli, t->line_number); + tl->count = (char)wq32(tl->vli, (uint32_t)t->line_number); after: tif->total++; #if 0 @@ -1050,9 +1050,9 @@ after: /* seal off the line length table block */ if (bp) { - if (write(t->fd, linetable, bp) != bp) + if ((int)write(t->fd, linetable, (size_t)bp) != bp) return 1; - t->c += bp; + t->c += (unsigned int)bp; bp = 0; } @@ -1062,17 +1062,17 @@ after: return 1; } - g16(linetable, t->c - lbh); - g16(linetable + 2, t->line_number - sline); - g32(linetable + 4, chars); - if (write(t->fd, linetable, 8) != 8) { + g16(linetable, (uint16_t)(t->c - (jg2_file_offset)lbh)); + g16(linetable + 2, (uint16_t)(t->line_number - sline)); + g32(linetable + 4, (uint32_t)chars); + if ((int)write(t->fd, linetable, 8) != 8) { lwsl_err("%s: write linetable header failed\n", __func__); return 1; } assert(lseek(t->fd, 0, SEEK_END) == (off_t)t->c); - if (lseek(t->fd, t->c, SEEK_SET) < 0) { + if (lseek(t->fd, (off_t)t->c, SEEK_SET) < 0) { lwsl_err("%s: end seek failed\n", __func__); return 1; } @@ -1086,7 +1086,7 @@ after: /* dump the collected per-input instance and line data, and free it */ - t->agg_trie_creation_us += lws_now_usecs() - tf; + t->agg_trie_creation_us += (uint64_t)((uint64_t)lws_now_usecs() - tf); return 0; } @@ -1097,7 +1097,7 @@ int lws_fts_serialize(struct lws_fts *t) { struct lws_fts_filepath *fp = t->filepath_list, *ofp; - unsigned long long tf = lws_now_usecs(); + unsigned long long tf = (unsigned long long)lws_now_usecs(); struct lws_fts_entry *e, *e1, *s[256]; unsigned char buf[8192], stasis; int n, bp, sp = 0, do_parent; @@ -1163,14 +1163,14 @@ lws_fts_serialize(struct lws_fts *t) bp = 0; while (fp) { - fp->ofs = t->c + bp; + fp->ofs = t->c + (unsigned int)bp; n = (int)strlen(fp->filepath); spill(15 + n, 0); bp += wq32(&buf[bp], fp->line_table_ofs); - bp += wq32(&buf[bp], fp->total_lines); - bp += wq32(&buf[bp], n); - memcpy(&buf[bp], fp->filepath, n); + bp += wq32(&buf[bp], (uint32_t)fp->total_lines); + bp += wq32(&buf[bp], (uint32_t)n); + memcpy(&buf[bp], fp->filepath, (unsigned int)n); bp += n; fp->prev = ofp; @@ -1185,12 +1185,12 @@ lws_fts_serialize(struct lws_fts *t) if (lseek(t->fd, 0xc, SEEK_SET) < 0) goto bail_seek; - g32(buf, t->c + bp); - g32(buf + 4, t->next_file_index); - if (write(t->fd, buf, 8) != 8) + g32(buf, t->c + (unsigned int)bp); + g32(buf + 4, (uint32_t)t->next_file_index); + if ((int)write(t->fd, buf, 8) != 8) goto bail; - if (lseek(t->fd, t->c + bp, SEEK_SET) < 0) + if (lseek(t->fd, (off_t)(t->c + (unsigned int)bp), SEEK_SET) < 0) goto bail_seek; /* dump the filepath map, starting from index 0, which is at the tail */ @@ -1235,7 +1235,7 @@ lws_fts_serialize(struct lws_fts *t) /* leaf nodes with no children */ e = s[sp]; - e->ofs = t->c + bp; + e->ofs = t->c + (unsigned int)bp; /* write the trie entry header */ @@ -1289,7 +1289,7 @@ lws_fts_serialize(struct lws_fts *t) if (e1->suffix) { /* string */ bp += wq32(&buf[bp], e1->suffix_len); memmove(&buf[bp], e1->suffix, e1->suffix_len); - bp += e1->suffix_len; + bp += (int)e1->suffix_len; } else { /* char */ bp += wq32(&buf[bp], 1); buf[bp++] = e1->c; @@ -1357,7 +1357,7 @@ lws_fts_serialize(struct lws_fts *t) (int)(t->agg_trie_creation_us / 1000), (int)(lwsac_total_alloc(t->lwsac_head) / 1024), (int)(t->worst_lwsac_input_size / 1024), - (int)((lws_now_usecs() - tf) / 1000), + (int)(((uint64_t)lws_now_usecs() - tf) / 1000), (int)(t->c / 1024)); return 0; diff --git a/lib/misc/lejp.c b/lib/misc/lejp.c index 707af8827..ee84734fc 100644 --- a/lib/misc/lejp.c +++ b/lib/misc/lejp.c @@ -159,7 +159,7 @@ lejp_check_path_match(struct lejp_ctx *ctx) ctx->wildcount = 0; p = ctx->path; - q = *((char **)(((char *)ctx->pst[ctx->pst_sp].paths) + (n * s))); + q = *((char **)(((char *)ctx->pst[ctx->pst_sp].paths) + ((unsigned int)n * s))); while (*p && *q) { if (*q != '*') { @@ -169,7 +169,7 @@ lejp_check_path_match(struct lejp_ctx *ctx) q++; continue; } - ctx->wild[ctx->wildcount++] = lws_ptr_diff(p, ctx->path); + ctx->wild[ctx->wildcount++] = (uint16_t)lws_ptr_diff_size_t(p, ctx->path); q++; /* * if * has something after it, match to . @@ -185,7 +185,7 @@ lejp_check_path_match(struct lejp_ctx *ctx) if (*p || *q) continue; - ctx->path_match = n + 1; + ctx->path_match = (uint8_t)(n + 1); ctx->path_match_len = ctx->pst[ctx->pst_sp].ppos; return; } @@ -245,13 +245,13 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) while (len--) { c = *json++; - s = ctx->st[ctx->sp].s; + s = (unsigned char)ctx->st[ctx->sp].s; /* skip whitespace unless we should care */ if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '#') { if (c == '\n') { ctx->line++; - ctx->st[ctx->sp].s &= ~LEJP_FLAG_WS_COMMENTLINE; + ctx->st[ctx->sp].s &= (char)~LEJP_FLAG_WS_COMMENTLINE; } if (!(s & LEJP_FLAG_WS_KEEP)) { if (c == '#') @@ -349,7 +349,7 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) if (c != esc_char[n]) continue; /* found it */ - c = esc_tran[n]; + c = (unsigned char)esc_tran[n]; ctx->st[ctx->sp].s = LEJP_MP_STRING; goto emit_string_char; } @@ -361,15 +361,15 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) case LEJP_MP_STRING_ESC_U2: case LEJP_MP_STRING_ESC_U3: case LEJP_MP_STRING_ESC_U4: - ctx->uni <<= 4; + ctx->uni = (uint16_t)(ctx->uni << 4); if (c >= '0' && c <= '9') - ctx->uni |= c - '0'; + ctx->uni |= (uint16_t)(c - '0'); else if (c >= 'a' && c <= 'f') - ctx->uni |= c - 'a' + 10; + ctx->uni |= (uint16_t)(c - 'a' + 10); else if (c >= 'A' && c <= 'F') - ctx->uni |= c - 'A' + 10; + ctx->uni |= (uint16_t)(c - 'A' + 10); else { ret = LEJP_REJECT_ILLEGAL_HEX; goto reject; @@ -383,7 +383,7 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) * 0x08-0xff (0x0800 - 0xffff) * emit 3-byte UTF-8 */ - c = 0xe0 | ((ctx->uni >> 4) & 0xf); + c = (unsigned char)(0xe0 | ((ctx->uni >> 4) & 0xf)); goto emit_string_char; case LEJP_MP_STRING_ESC_U3: @@ -393,7 +393,7 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) * middle 3-byte seq * send ....XXXXXX.. */ - c = 0x80 | ((ctx->uni >> 2) & 0x3f); + c = (unsigned char)(0x80 | ((ctx->uni >> 2) & 0x3f)); goto emit_string_char; } if (ctx->uni < 0x008) @@ -402,13 +402,13 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) * 0x008 - 0x7f (0x0080 - 0x07ff) * start 2-byte seq */ - c = 0xc0 | (ctx->uni >> 2); + c = (unsigned char)(0xc0 | (ctx->uni >> 2)); goto emit_string_char; case LEJP_MP_STRING_ESC_U4: if (ctx->uni >= 0x0080) /* end of 2 or 3-byte seq */ - c = 0x80 | (ctx->uni & 0x3f); + c = (unsigned char)(0x80 | (ctx->uni & 0x3f)); else /* literal */ c = (unsigned char)ctx->uni; @@ -493,9 +493,9 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) } /* drop the path [n] bit */ if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = + ctx->pst[ctx->pst_sp].ppos = (unsigned char) ctx->st[ctx->sp - 1].p; - ctx->ipos = ctx->st[ctx->sp - 1].i; + ctx->ipos = (unsigned char)ctx->st[ctx->sp - 1].i; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && @@ -647,7 +647,7 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) ctx->path_match = 0; break; } - ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p; + ctx->pst[ctx->pst_sp].ppos = (unsigned char)ctx->st[ctx->sp - 1].p; ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) @@ -679,9 +679,9 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) /* drop the path [n] bit */ if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = + ctx->pst[ctx->pst_sp].ppos = (unsigned char) ctx->st[ctx->sp - 1].p; - ctx->ipos = ctx->st[ctx->sp - 1].i; + ctx->ipos = (unsigned char)ctx->st[ctx->sp - 1].i; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && @@ -708,7 +708,7 @@ lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) n = LEJPCB_OBJECT_END; completed: lejp_check_path_match(ctx); - if (ctx->pst[ctx->pst_sp].callback(ctx, n) || + if (ctx->pst[ctx->pst_sp].callback(ctx, (char)n) || ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_COMPLETE)) goto reject_callback; @@ -721,8 +721,8 @@ completed: pop_level: ctx->sp--; if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp].p; - ctx->ipos = ctx->st[ctx->sp].i; + ctx->pst[ctx->pst_sp].ppos = (unsigned char)ctx->st[ctx->sp].p; + ctx->ipos = (unsigned char)ctx->st[ctx->sp].i; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && @@ -748,7 +748,7 @@ array_end: ctx->i[ctx->ipos - 1]++; ctx->st[ctx->sp].s = LEJP_MP_VALUE; if (ctx->sp) - ctx->pst[ctx->pst_sp].ppos = + ctx->pst[ctx->pst_sp].ppos = (unsigned char) ctx->st[ctx->sp - 1].p; ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; break; @@ -768,7 +768,7 @@ array_end: emit_string_char: if (!ctx->sp || ctx->st[ctx->sp - 1].s != LEJP_MP_DELIM) { /* assemble the string value into chunks */ - ctx->buf[ctx->npos++] = c; + ctx->buf[ctx->npos++] = (char)c; if (ctx->npos == sizeof(ctx->buf) - 1) { if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_STR_CHUNK)) @@ -778,7 +778,7 @@ emit_string_char: continue; } /* name part of name:value pair */ - ctx->path[ctx->pst[ctx->pst_sp].ppos++] = c; + ctx->path[ctx->pst[ctx->pst_sp].ppos++] = (char)c; continue; add_stack_level: @@ -788,14 +788,14 @@ add_stack_level: ctx->st[ctx->sp].s != LEJP_MP_ARRAY_END) ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '.'; - ctx->st[ctx->sp].p = ctx->pst[ctx->pst_sp].ppos; - ctx->st[ctx->sp].i = ctx->ipos; + ctx->st[ctx->sp].p = (char)ctx->pst[ctx->pst_sp].ppos; + ctx->st[ctx->sp].i = (char)ctx->ipos; if (++ctx->sp == LWS_ARRAY_SIZE(ctx->st)) { ret = LEJP_REJECT_STACK_OVERFLOW; goto reject; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; - ctx->st[ctx->sp].s = c; + ctx->st[ctx->sp].s = (char)c; ctx->st[ctx->sp].b = 0; continue; @@ -804,7 +804,7 @@ append_npos: ret = LEJP_REJECT_NUM_TOO_LONG; goto reject; } - ctx->buf[ctx->npos++] = c; + ctx->buf[ctx->npos++] = (char)c; continue; redo_character: diff --git a/lib/misc/lws-ring.c b/lib/misc/lws-ring.c index e30183592..3c6a21541 100644 --- a/lib/misc/lws-ring.c +++ b/lib/misc/lws-ring.c @@ -81,19 +81,19 @@ lws_ring_get_count_free_elements(struct lws_ring *ring) * |*****ht*********| */ if (ring->head == ring->oldest_tail) - f = ring->buflen - ring->element_len; + f = (int)(ring->buflen - ring->element_len); else if (ring->head < ring->oldest_tail) - f = (ring->oldest_tail - ring->head) - - ring->element_len; + f = (int)((ring->oldest_tail - ring->head) - + ring->element_len); else - f = (ring->buflen - ring->head) + ring->oldest_tail - - ring->element_len; + f = (int)((ring->buflen - ring->head) + ring->oldest_tail - + ring->element_len); if (f < 2) return 0; - return f / ring->element_len; + return (unsigned int)f / ring->element_len; } size_t @@ -115,11 +115,11 @@ lws_ring_get_count_waiting_elements(struct lws_ring *ring, uint32_t *tail) f = 0; else if (ring->head > *tail) - f = (ring->head - *tail); + f = (int)(ring->head - *tail); else - f = (ring->buflen - *tail) + ring->head; + f = (int)((ring->buflen - *tail) + ring->head); - return f / ring->element_len; + return (unsigned int)f / ring->element_len; } int @@ -134,7 +134,7 @@ lws_ring_next_linear_insert_range(struct lws_ring *ring, void **start, if (!n) return 1; - if (ring->head + n > ring->buflen) { + if (ring->head + (unsigned int)n > ring->buflen) { *start = (void *)(((uint8_t *)ring->buf) + ring->head); *bytes = ring->buflen - ring->head; @@ -142,7 +142,7 @@ lws_ring_next_linear_insert_range(struct lws_ring *ring, void **start, } *start = (void *)(((uint8_t *)ring->buf) + ring->head); - *bytes = n; + *bytes = (unsigned int)n; return 0; } @@ -157,7 +157,8 @@ size_t lws_ring_insert(struct lws_ring *ring, const void *src, size_t max_count) { const uint8_t *osrc = src; - int m, n; + size_t m; + int n; /* n is how many bytes the whole fifo can take */ n = (int)(lws_ring_get_count_free_elements(ring) * ring->element_len); @@ -170,7 +171,7 @@ lws_ring_insert(struct lws_ring *ring, const void *src, size_t max_count) * n is legal to insert, but as an optimization we can cut the * insert into one or two memcpys, depending on if it wraps */ - if (ring->head + n > ring->buflen) { + if (ring->head + (unsigned int)n > ring->buflen) { /* * He does wrap. The first memcpy should take us up to @@ -185,13 +186,13 @@ lws_ring_insert(struct lws_ring *ring, const void *src, size_t max_count) /* adapt the second memcpy for what we already did */ src = ((uint8_t *)src) + m; - n -= m; + n = n - (int)m; } - memcpy(((uint8_t *)ring->buf) + ring->head, src, n); - ring->head = (ring->head + n) % ring->buflen; + memcpy(((uint8_t *)ring->buf) + ring->head, src, (size_t)n); + ring->head = (ring->head + (unsigned int)n) % ring->buflen; - return (((uint8_t *)src + n) - osrc) / ring->element_len; + return (unsigned long)(((uint8_t *)src + (unsigned int)n) - osrc) / ring->element_len; } size_t @@ -217,21 +218,21 @@ lws_ring_consume(struct lws_ring *ring, uint32_t *tail, void *dest, n = (int)(max_count * ring->element_len); if (!dest) { - *tail = ((*tail) + n) % ring->buflen; + *tail = ((*tail) + (unsigned int)n) % ring->buflen; if (!orig_tail) /* single tail */ lws_ring_update_oldest_tail(ring, *tail); - return n / ring->element_len; + return (unsigned int)n / ring->element_len; } - if (*tail + n > ring->buflen) { + if (*tail + (unsigned int)n > ring->buflen) { /* * He does wrap. The first memcpy should take us up to * the end of the buffer */ - m = ring->buflen - *tail; - memcpy(dest, ((uint8_t *)ring->buf) + *tail, m); + m = (int32_t)(ring->buflen - *tail); + memcpy(dest, ((uint8_t *)ring->buf) + *tail, (size_t)m); /* we know it will wrap exactly back to zero */ *tail = 0; @@ -241,13 +242,13 @@ lws_ring_consume(struct lws_ring *ring, uint32_t *tail, void *dest, n -= m; } - memcpy(dest, ((uint8_t *)ring->buf) + *tail, n); + memcpy(dest, ((uint8_t *)ring->buf) + *tail, (size_t)n); - *tail = ((*tail) + n) % ring->buflen; + *tail = ((*tail) + (unsigned int)n) % ring->buflen; if (!orig_tail) /* single tail */ lws_ring_update_oldest_tail(ring, *tail); - return (((uint8_t *)dest + n) - odest) / ring->element_len; + return (unsigned int)(((uint8_t *)dest + n) - odest) / (unsigned int)ring->element_len; } const void * diff --git a/lib/misc/lws-struct-lejp.c b/lib/misc/lws-struct-lejp.c index a4864726c..7f3f30461 100644 --- a/lib/misc/lws-struct-lejp.c +++ b/lib/misc/lws-struct-lejp.c @@ -339,7 +339,7 @@ lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason) if (map->aux == sizeof(signed char)) { signed char *pc; pc = (signed char *)(u + map->ofs); - *pc = atoi(ctx->buf); + *pc = (signed char)atoi(ctx->buf); break; } if (map->aux == sizeof(int)) { @@ -363,23 +363,23 @@ lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason) if (map->aux == sizeof(unsigned char)) { unsigned char *pc; pc = (unsigned char *)(u + map->ofs); - *pc = atoi(ctx->buf); + *pc = (unsigned char)(unsigned int)atoi(ctx->buf); break; } if (map->aux == sizeof(unsigned int)) { unsigned int *pi; pi = (unsigned int *)(u + map->ofs); - *pi = atoi(ctx->buf); + *pi = (unsigned int)atoi(ctx->buf); break; } if (map->aux == sizeof(unsigned long)) { unsigned long *pl; pl = (unsigned long *)(u + map->ofs); - *pl = atol(ctx->buf); + *pl = (unsigned long)atol(ctx->buf); } else { unsigned long long *pll; pll = (unsigned long long *)(u + map->ofs); - *pll = atoll(ctx->buf); + *pll = (unsigned long long)atoll(ctx->buf); } break; @@ -398,7 +398,7 @@ lws_struct_default_lejp_cb(struct lejp_ctx *ctx, char reason) } else { uint64_t *p64; p64 = (uint64_t *)(u + map->ofs); - *p64 = li; + *p64 = (uint64_t)li; } break; @@ -423,7 +423,7 @@ chunk_copy: lejp_collation_t *coll = (lejp_collation_t *)p; if (lim) { - b = coll->len; + b = (unsigned int)coll->len; if (b > lim) b = lim; memcpy(s, coll->buf, b); @@ -593,7 +593,7 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, n = lws_snprintf((char *)buf, len, "\"%s\":", map->colname); buf += n; - len -= n; + len = len - (unsigned int)n; if (js->flags & LSSERJ_FLAG_PRETTY) { *buf++ = ' '; len--; @@ -618,10 +618,10 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, q = dbuf; if (map->type == LSMT_BOOLEAN) { - budget = lws_snprintf(dbuf, sizeof(dbuf), + budget = (unsigned int)lws_snprintf(dbuf, sizeof(dbuf), "%s", uli ? "true" : "false"); } else - budget = lws_snprintf(dbuf, sizeof(dbuf), + budget = (unsigned int)lws_snprintf(dbuf, sizeof(dbuf), "%llu", uli); break; @@ -639,7 +639,7 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, } } q = dbuf; - budget = lws_snprintf(dbuf, sizeof(dbuf), "%lld", li); + budget = (unsigned int)lws_snprintf(dbuf, sizeof(dbuf), "%lld", li); break; case LSMT_STRING_CHAR_ARRAY: @@ -669,7 +669,7 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, n = j->idt; j = &js->st[++js->sp]; - j->idt = n + 2; + j->idt = (char)(n + 2); j->map = map->child_map; j->map_entries = map->child_map_size; j->size = map->aux; @@ -694,7 +694,7 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, n = j->idt; j = &js->st[++js->sp]; - j->idt = n + 2; + j->idt = (char)(n + 2); j->map = map->child_map; j->map_entries = map->child_map_size; j->size = map->aux; @@ -714,11 +714,11 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, j = &js->st[++js->sp]; lws_struct_pretty(js, &buf, &len); if (!(js->flags & LSSERJ_FLAG_OMIT_SCHEMA)) { - budget = lws_snprintf(dbuf, 15, "\"schema\":"); + budget = (unsigned int)lws_snprintf(dbuf, 15, "\"schema\":"); if (js->flags & LSSERJ_FLAG_PRETTY) dbuf[budget++] = ' '; - budget += lws_snprintf(dbuf + budget, + budget += (unsigned int)lws_snprintf(dbuf + budget, sizeof(dbuf) - budget, "\"%s\"", map->colname); } @@ -766,8 +766,8 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, m = strlen((const char *)buf); buf += m; len -= m; - js->remaining = budget - used; - js->offset = used; + js->remaining = budget - (unsigned int)used; + js->offset = (unsigned int)used; if (!js->remaining) js->offset = 0; diff --git a/lib/misc/lws-struct-sqlite.c b/lib/misc/lws-struct-sqlite.c index 155688060..fbe8cf4ad 100644 --- a/lib/misc/lws-struct-sqlite.c +++ b/lib/misc/lws-struct-sqlite.c @@ -38,7 +38,7 @@ lws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn) char *u = lwsac_use_zero(&a->ac, a->dest_len, a->ac_block_size); lws_dll2_owner_t *o = (lws_dll2_owner_t *)a->cb_arg; const lws_struct_map_t *map = a->map_st[0]; - int n, mems = a->map_entries_st[0]; + int n, mems = (int)(ssize_t)a->map_entries_st[0]; long long li; size_t lim; char **pp; @@ -62,13 +62,13 @@ lws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn) if (map->aux == sizeof(signed char)) { signed char *pc; pc = (signed char *)(u + map->ofs); - *pc = atoi(cv[n]); + *pc = (signed char)atoi(cv[n]); break; } if (map->aux == sizeof(short)) { short *ps; ps = (short *)(u + map->ofs); - *ps = atoi(cv[n]); + *ps = (short)atoi(cv[n]); break; } if (map->aux == sizeof(int)) { @@ -94,31 +94,31 @@ lws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn) if (map->aux == sizeof(unsigned char)) { unsigned char *pc; pc = (unsigned char *)(u + map->ofs); - *pc = atoi(cv[n]); + *pc = (unsigned char)(unsigned int)atoi(cv[n]); break; } if (map->aux == sizeof(unsigned short)) { unsigned short *ps; ps = (unsigned short *)(u + map->ofs); - *ps = atoi(cv[n]); + *ps = (unsigned short)atoi(cv[n]); break; } if (map->aux == sizeof(unsigned int)) { unsigned int *pi; pi = (unsigned int *)(u + map->ofs); - *pi = atoi(cv[n]); + *pi = (unsigned int)atoi(cv[n]); break; } if (map->aux == sizeof(unsigned long)) { unsigned long *pl; pl = (unsigned long *)(u + map->ofs); - *pl = atol(cv[n]); + *pl = (unsigned long)atol(cv[n]); break; } { unsigned long long *pll; pll = (unsigned long long *)(u + map->ofs); - *pll = atoll(cv[n]); + *pll = (unsigned long long)atoll(cv[n]); } break; @@ -140,7 +140,7 @@ lws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn) } else { uint64_t *p64; p64 = (uint64_t *)(u + map->ofs); - *p64 = li; + *p64 = (uint64_t)li; } break; @@ -205,7 +205,7 @@ lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, m = 0; for (n = 0; n < (int)schema->child_map_size; n++) - m += lws_snprintf(&results[m], sizeof(results) - n - 1, + m += lws_snprintf(&results[m], sizeof(results) - (unsigned int)n - 1, "%s%c", schema->child_map[n].colname, n + 1 == (int)schema->child_map_size ? ' ' : ','); @@ -241,7 +241,7 @@ _lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, uint32_t idx, void *st) { const lws_struct_map_t *map = schema->child_map; - int n, m, pk = 0, nentries = schema->child_map_size, nef = 0, did; + int n, m, pk = 0, nentries = (int)(ssize_t)schema->child_map_size, nef = 0, did; size_t sql_est = 46 + strlen(schema->colname) + 1; /* "insert into (_lws_idx, ) values (00000001,);" ... * plus the table name */ @@ -301,13 +301,13 @@ _lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, break; case LSMT_STRING_CHAR_ARRAY: - sql_est += lws_sql_purify_len((const char *)st + + sql_est += (unsigned int)lws_sql_purify_len((const char *)st + map[n].ofs) + 2; break; case LSMT_STRING_PTR: p = *((const char * const *)&stb[map[n].ofs]); - sql_est += (p ? lws_sql_purify_len(p) : 0) + 2; + sql_est += (unsigned int)((p ? lws_sql_purify_len(p) : 0) + 2); break; case LSMT_BLOB_PTR: @@ -345,12 +345,12 @@ _lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, continue; did++; - m += lws_snprintf(sql + m, sql_est - m, + m += lws_snprintf(sql + m, sql_est - (unsigned int)m, did == nef ? "%s" : "%s, ", map[n].colname); } - m += lws_snprintf(sql + m, sql_est - m, ") values(%u, ", idx); + m += lws_snprintf(sql + m, sql_est - (unsigned int)m, ") values(%u, ", idx); pk = 0; did = 0; @@ -374,26 +374,26 @@ _lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, (q << 3)); if (map[n].type == LSMT_SIGNED) - m += lws_snprintf(sql + m, sql_est - m, "%lld", + m += lws_snprintf(sql + m, sql_est - (unsigned int)m, "%lld", (long long)(int64_t)uu64); else - m += lws_snprintf(sql + m, sql_est - m, "%llu", + m += lws_snprintf(sql + m, sql_est - (unsigned int)m, "%llu", (unsigned long long)uu64); break; case LSMT_STRING_CHAR_ARRAY: sql[m++] = '\''; lws_sql_purify(sql + m, (const char *)&stb[map[n].ofs], - sql_est - m - 4); - m += strlen(sql + m); + sql_est - (size_t)(ssize_t)m - 4); + m += (int)(ssize_t)strlen(sql + m); sql[m++] = '\''; break; case LSMT_STRING_PTR: p = *((const char * const *)&stb[map[n].ofs]); sql[m++] = '\''; if (p) { - lws_sql_purify(sql + m, p, sql_est - m - 4); - m += strlen(sql + m); + lws_sql_purify(sql + m, p, sql_est - (unsigned int)m - 4); + m += (int)(ssize_t)strlen(sql + m); } sql[m++] = '\''; break; @@ -409,14 +409,14 @@ _lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, did++; if (did != nef) { - if (sql_est - m < 6) + if (sql_est - (unsigned int)m < 6) return -1; sql[m++] = ','; sql[m++] = ' '; } } - lws_snprintf(sql + m, sql_est - m, ");"); + lws_snprintf(sql + m, sql_est - (unsigned int)m, ");"); n = sqlite3_exec(pdb, sql, NULL, NULL, NULL); if (n != SQLITE_OK) { @@ -450,11 +450,11 @@ int lws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema) { const lws_struct_map_t *map = schema->child_map; - int map_size = schema->child_map_size, subsequent = 0; + int map_size = (int)(ssize_t)schema->child_map_size, subsequent = 0; char s[2048], *p = s, *end = &s[sizeof(s) - 1], *pri = " primary key autoincrement", *use; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "create table if not exists %s (_lws_idx integer, ", schema->colname); @@ -470,26 +470,26 @@ lws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema) subsequent = 1; if (map->type == LSMT_BLOB_PTR) { - p += lws_snprintf(p, end - p, "%s blob", map->colname); + p += lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "%s blob", map->colname); } else { if (map->type < LSMT_STRING_CHAR_ARRAY) { use = ""; if (map->colname[0] != '_') /* _lws_idx is not primary key */ use = pri; - p += lws_snprintf(p, end - p, "%s integer%s", + p += lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "%s integer%s", map->colname, use); if (map->colname[0] != '_') pri = ""; } else - p += lws_snprintf(p, end - p, "%s varchar", + p += lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), "%s varchar", map->colname); } map++; } - p += lws_snprintf(p, end - p, ");"); + p += lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), ");"); if (sqlite3_exec(pdb, s, NULL, NULL, NULL) != SQLITE_OK) { lwsl_err("%s: %s: fail\n", __func__, sqlite3_errmsg(pdb)); @@ -505,7 +505,8 @@ lws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path, char create_if_missing, sqlite3 **pdb) { #if !defined(WIN32) - int uid = 0, gid = 0; + uid_t uid = 0; + gid_t gid = 0; #endif if (sqlite3_open_v2(sqlite3_path, pdb, diff --git a/lib/misc/lwsac/cached-file.c b/lib/misc/lwsac/cached-file.c index d5573ee65..9f3b723b7 100644 --- a/lib/misc/lwsac/cached-file.c +++ b/lib/misc/lwsac/cached-file.c @@ -177,7 +177,7 @@ lwsac_cached_file(const char *filepath, lwsac_cached_file_t *cache, size_t *len) * it... reload in a new lac and then detach the old lac. */ - all = sizeof(*info) + s.st_size + 2; + all = sizeof(*info) + (unsigned long)s.st_size + 2; info = lwsac_use(&lac, all, all); if (!info) @@ -188,10 +188,10 @@ lwsac_cached_file(const char *filepath, lwsac_cached_file_t *cache, size_t *len) a = (unsigned char *)(info + 1); - *len = s.st_size; + *len = (unsigned long)s.st_size; a[s.st_size] = '\0'; - rd = read(fd, a, s.st_size); + rd = read(fd, a, (unsigned long)s.st_size); if (rd != s.st_size) { lwsl_err("%s: cannot read %s (%d)\n", __func__, filepath, (int)rd); diff --git a/lib/misc/lwsac/lwsac.c b/lib/misc/lwsac/lwsac.c index cde97ef3c..faa82f067 100644 --- a/lib/misc/lwsac/lwsac.c +++ b/lib/misc/lwsac/lwsac.c @@ -70,7 +70,7 @@ lwsac_get_next(struct lwsac *lac) } int -lwsac_extend(struct lwsac *head, int amount) +lwsac_extend(struct lwsac *head, size_t amount) { struct lwsac_head *lachead; struct lwsac *bf; diff --git a/lib/misc/peer-limits.c b/lib/misc/peer-limits.c index 32ea50dc4..1f3a71561 100644 --- a/lib/misc/peer-limits.c +++ b/lib/misc/peer-limits.c @@ -89,7 +89,7 @@ lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd) q8 = q; for (n = 0; n < (int)rlen; n++) - hash = (((hash << 4) | (hash >> 28)) * n) ^ q8[n]; + hash = (uint32_t)((((hash << 4) | (hash >> 28)) * (uint32_t)n) ^ q8[n]); hash = hash % context->pl_hash_elements; diff --git a/lib/misc/sha-1.c b/lib/misc/sha-1.c index 109bfdb8d..22989e4e8 100644 --- a/lib/misc/sha-1.c +++ b/lib/misc/sha-1.c @@ -211,14 +211,14 @@ sha1_pad(struct sha1_ctxt *ctxt) padlen = 64 - padstart; if (padlen < 8) { memset(&ctxt->m.b8[padstart], 0, padlen); - COUNT += (unsigned char)padlen; + COUNT = (unsigned char)(COUNT + padlen); COUNT %= 64; sha1_step(ctxt); padstart = COUNT % 64; /* should be 0 */ padlen = 64 - padstart; /* should be 64 */ } memset(&ctxt->m.b8[padstart], 0, padlen - 8); - COUNT += ((unsigned char)padlen - 8); + COUNT = (unsigned char)(COUNT + (padlen - 8)); COUNT %= 64; #if BYTE_ORDER == BIG_ENDIAN PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]); @@ -245,7 +245,7 @@ sha1_loop(struct sha1_ctxt *ctxt, const unsigned char *input, size_t len) copysiz = (gaplen < len - off) ? gaplen : len - off; memcpy(&ctxt->m.b8[gapstart], &input[off], copysiz); - COUNT += (unsigned char)copysiz; + COUNT = (unsigned char)(COUNT + copysiz); COUNT %= 64; ctxt->c.b64[0] += copysiz * 8; if (COUNT % 64 == 0) diff --git a/lib/misc/threadpool/threadpool.c b/lib/misc/threadpool/threadpool.c index 1109373f7..dd310b82e 100644 --- a/lib/misc/threadpool/threadpool.c +++ b/lib/misc/threadpool/threadpool.c @@ -129,7 +129,7 @@ __lws_threadpool_task_dump(struct lws_threadpool_task *task, char *buf, int len) int syncms = 0, runms = 0; if (!task->acquired) { - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "task: %s, QUEUED queued: %dms", task->name, ms_delta(now, task->created)); @@ -143,7 +143,7 @@ __lws_threadpool_task_dump(struct lws_threadpool_task *task, char *buf, int len) syncms = (int)task->acc_syncing; if (!task->done) { - buf += lws_snprintf(buf, end - buf, + buf += lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "task: %s, ONGOING state %d (%dms) alive: %dms " "(queued %dms, acquired: %dms, " "run: %d%%, sync: %d%%)", task->name, task->status, @@ -157,7 +157,7 @@ __lws_threadpool_task_dump(struct lws_threadpool_task *task, char *buf, int len) return; } - lws_snprintf(buf, end - buf, + lws_snprintf(buf, lws_ptr_diff_size_t(end, buf), "task: %s, DONE state %d lived: %dms " "(queued %dms, on thread: %dms, " "ran: %d%%, synced: %d%%)", task->name, task->status, @@ -586,7 +586,7 @@ lws_threadpool_worker(void *d) } then = lws_now_usecs(); - n = task->args.task(task->args.user, task->status); + n = (int)task->args.task(task->args.user, task->status); lwsl_debug(" %d, status %d\n", n, task->status); us_accrue(&task->acc_running, then); if (n & LWS_TP_RETURN_FLAG_OUTLIVE) @@ -688,12 +688,12 @@ lws_threadpool_create(struct lws_context *context, va_list ap; int n; - tp = lws_malloc(sizeof(*tp) + (sizeof(struct lws_pool) * args->threads), + tp = lws_malloc(sizeof(*tp) + (sizeof(struct lws_pool) * (unsigned int)args->threads), "threadpool alloc"); if (!tp) return NULL; - memset(tp, 0, sizeof(*tp) + (sizeof(struct lws_pool) * args->threads)); + memset(tp, 0, sizeof(*tp) + (sizeof(struct lws_pool) * (unsigned int)args->threads)); tp->pool_list = (struct lws_pool *)(tp + 1); tp->max_queue_depth = args->max_queue_depth; diff --git a/lib/plat/freertos/freertos-file.c b/lib/plat/freertos/freertos-file.c index e08d17499..033d2587f 100644 --- a/lib/plat/freertos/freertos-file.c +++ b/lib/plat/freertos/freertos-file.c @@ -154,7 +154,7 @@ lws_find_string_in_file(const char *filename, const char *string, int stringlen) #if !defined(LWS_AMAZON_RTOS) int -lws_plat_write_file(const char *filename, void *buf, int len) +lws_plat_write_file(const char *filename, void *buf, size_t len) { nvs_handle nvh; int n; @@ -179,7 +179,7 @@ lws_plat_write_file(const char *filename, void *buf, int len) int lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len) + size_t len) { const char *name = vhost->tls.alloc_cert_path; @@ -190,7 +190,7 @@ lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, } int -lws_plat_read_file(const char *filename, void *buf, int len) +lws_plat_read_file(const char *filename, void *buf, size_t len) { nvs_handle nvh; size_t s = 0; @@ -204,7 +204,7 @@ lws_plat_read_file(const char *filename, void *buf, int len) ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); if (nvs_get_blob(nvh, filename, NULL, &s) != ESP_OK) goto bail; - if (s > (size_t)len) + if (s > len) goto bail; n = nvs_get_blob(nvh, filename, buf, &s); diff --git a/lib/plat/freertos/freertos-sockets.c b/lib/plat/freertos/freertos-sockets.c index 4b8c73c0d..f5d975b07 100644 --- a/lib/plat/freertos/freertos-sockets.c +++ b/lib/plat/freertos/freertos-sockets.c @@ -215,7 +215,7 @@ lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, } const char * -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +lws_plat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { return inet_ntop(af, src, dst, cnt); } @@ -235,8 +235,8 @@ lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) } int -lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, - int n, int fd, const char *iface) +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len, + size_t n, int fd, const char *iface) { lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); diff --git a/lib/plat/optee/lws-plat-optee.c b/lib/plat/optee/lws-plat-optee.c index e36b76865..cc46d76f2 100644 --- a/lib/plat/optee/lws-plat-optee.c +++ b/lib/plat/optee/lws-plat-optee.c @@ -219,7 +219,7 @@ lws_plat_init(struct lws_context *context, } int -lws_plat_write_file(const char *filename, void *buf, int len) +lws_plat_write_file(const char *filename, void *buf, size_t len) { return 1; } diff --git a/lib/plat/optee/network.c b/lib/plat/optee/network.c index 90f37f13f..b0867b77e 100644 --- a/lib/plat/optee/network.c +++ b/lib/plat/optee/network.c @@ -203,7 +203,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) int lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len) + size_t len) { return 1; } @@ -243,7 +243,7 @@ lws_plat_change_pollfd(struct lws_context *context, } const char * -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +lws_plat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { //return inet_ntop(af, src, dst, cnt); return "lws_plat_inet_ntop"; diff --git a/lib/plat/unix/private-lib-plat-unix.h b/lib/plat/unix/private-lib-plat-unix.h index 6d0ab8490..b6e4ee8aa 100644 --- a/lib/plat/unix/private-lib-plat-unix.h +++ b/lib/plat/unix/private-lib-plat-unix.h @@ -197,8 +197,8 @@ delete_from_fd(const struct lws_context *context, int fd); #endif int -lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, - int n, int fd, const char *iface); +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len, + size_t n, int fd, const char *iface); int lws_plat_if_up(const char *ifname, int fd, int up); diff --git a/lib/plat/unix/unix-caps.c b/lib/plat/unix/unix-caps.c index 8962b9537..68e4f199e 100644 --- a/lib/plat/unix/unix-caps.c +++ b/lib/plat/unix/unix-caps.c @@ -54,13 +54,13 @@ lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid char *colon = strchr(u_colon_g, ':'), u[33]; struct passwd *p; struct group *g; - int ulen; + size_t ulen; if (!colon) return 1; - ulen = lws_ptr_diff(colon, u_colon_g); - if (ulen < 2 || ulen > (int)sizeof(u) - 1) + ulen = (size_t)(unsigned int)lws_ptr_diff(colon, u_colon_g); + if (ulen < 2 || ulen > sizeof(u) - 1) return 1; memcpy(u, u_colon_g, ulen); @@ -133,7 +133,7 @@ lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop) /* if he gave us the gid or we have it from the groupname, set it */ - if (context->gid && context->gid != -1) { + if (context->gid && context->gid != (gid_t)-1l) { g = getgrgid(context->gid); if (!g) { @@ -158,7 +158,7 @@ lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop) /* if he gave us the uid or we have it from the username, set it */ - if (context->uid && context->uid != -1) { + if (context->uid && context->uid != (uid_t)-1l) { p = getpwuid(context->uid); if (!p) { @@ -172,7 +172,11 @@ lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop) context->count_caps); #endif - if (initgroups(p->pw_name, context->gid)) + if (initgroups(p->pw_name, +#if defined(__APPLE__) + (int) +#endif + context->gid)) return 1; if (setuid(context->uid)) { diff --git a/lib/plat/unix/unix-file.c b/lib/plat/unix/unix-file.c index 1a8bd41ce..c71c0d1e5 100644 --- a/lib/plat/unix/unix-file.c +++ b/lib/plat/unix/unix-file.c @@ -44,9 +44,10 @@ int lws_plat_apply_FD_CLOEXEC(int n) } int -lws_plat_write_file(const char *filename, void *buf, int len) +lws_plat_write_file(const char *filename, void *buf, size_t len) { - int m, fd; + ssize_t m; + int fd; fd = lws_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); @@ -56,20 +57,25 @@ lws_plat_write_file(const char *filename, void *buf, int len) m = write(fd, buf, len); close(fd); - return m != len; + if (m < 0) + return 1; + + return (size_t)m != len; } int -lws_plat_read_file(const char *filename, void *buf, int len) +lws_plat_read_file(const char *filename, void *buf, size_t len) { - int n, fd = lws_open(filename, O_RDONLY); + int fd = lws_open(filename, O_RDONLY); + ssize_t n; + if (fd == -1) return -1; n = read(fd, buf, len); close(fd); - return n; + return (int)n; } lws_fop_fd_t @@ -94,7 +100,7 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename, fop_fd->flags = *flags; fop_fd->fd = ret; fop_fd->filesystem_priv = NULL; /* we don't use it */ - fop_fd->len = stat_buf.st_size; + fop_fd->len = (lws_filepos_t)stat_buf.st_size; fop_fd->pos = 0; return fop_fd; @@ -122,15 +128,15 @@ _lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset) if (offset > 0 && offset > (lws_fileofs_t)fop_fd->len - (lws_fileofs_t)fop_fd->pos) - offset = fop_fd->len - fop_fd->pos; + offset = (lws_fileofs_t)(fop_fd->len - fop_fd->pos); if ((lws_fileofs_t)fop_fd->pos + offset < 0) - offset = -fop_fd->pos; + offset = (lws_fileofs_t)(-fop_fd->pos); - r = lseek(fop_fd->fd, offset, SEEK_CUR); + r = lseek(fop_fd->fd, (off_t)offset, SEEK_CUR); if (r >= 0) - fop_fd->pos = r; + fop_fd->pos = (lws_filepos_t)r; else lwsl_err("error seeking from cur %ld, offset %ld\n", (long)fop_fd->pos, (long)offset); @@ -142,17 +148,18 @@ int _lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len) { - long n; + ssize_t n; - n = read((int)fop_fd->fd, buf, len); - if (n == -1) { + n = read((int)fop_fd->fd, buf, (size_t)len); + if (n == -1l) { *amount = 0; return -1; } - fop_fd->pos += n; - lwsl_debug("%s: read %ld of req %ld, pos %ld, len %ld\n", __func__, n, - (long)len, (long)fop_fd->pos, (long)fop_fd->len); - *amount = n; + fop_fd->pos += (size_t)n; + lwsl_debug("%s: read %ld of req %ld, pos %ld, len %ld\n", __func__, + (long)n, (long)len, (long)fop_fd->pos, + (long)fop_fd->len); + *amount = (size_t)n; return 0; } @@ -161,16 +168,16 @@ int _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len) { - long n; + ssize_t n; - n = write((int)fop_fd->fd, buf, len); + n = write((int)fop_fd->fd, buf, (size_t)len); if (n == -1) { *amount = 0; return -1; } - fop_fd->pos += n; - *amount = n; + fop_fd->pos += (size_t)n; + *amount = (size_t)n; return 0; } diff --git a/lib/plat/unix/unix-init.c b/lib/plat/unix/unix-init.c index f82143f57..ea90dcadb 100644 --- a/lib/plat/unix/unix-init.c +++ b/lib/plat/unix/unix-init.c @@ -92,8 +92,10 @@ protocol_plugin_cb(struct lws_plugin *pin, void *each_user) const lws_plugin_protocol_t *plpr = (const lws_plugin_protocol_t *)pin->hdr; - context->plugin_protocol_count += plpr->count_protocols; - context->plugin_extension_count += plpr->count_extensions; + context->plugin_protocol_count = (short)(context->plugin_protocol_count + + plpr->count_protocols); + context->plugin_extension_count = (short)(context->plugin_extension_count + + plpr->count_extensions); return 0; } diff --git a/lib/plat/unix/unix-misc.c b/lib/plat/unix/unix-misc.c index 7c6679fa5..8dcaaa94c 100644 --- a/lib/plat/unix/unix-misc.c +++ b/lib/plat/unix/unix-misc.c @@ -36,7 +36,7 @@ void lws_msleep(unsigned int ms) { - usleep(ms * LWS_US_PER_MS); + usleep((unsigned int)(ms * LWS_US_PER_MS)); } lws_usec_t @@ -95,18 +95,18 @@ void lwsl_emit_syslog(int level, const char *line) int lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len) + size_t len) { - int n; + ssize_t n; n = write(fd, buf, len); - if (fsync(fd)) + if (n < 0 || fsync(fd)) return 1; if (lseek(fd, 0, SEEK_SET) < 0) return 1; - return n != len; + return (size_t)n != len; } diff --git a/lib/plat/unix/unix-pipe.c b/lib/plat/unix/unix-pipe.c index 6b917cde5..b4470975a 100644 --- a/lib/plat/unix/unix-pipe.c +++ b/lib/plat/unix/unix-pipe.c @@ -57,7 +57,7 @@ lws_plat_pipe_signal(struct lws_context *ctx, int tsi) char buf = 0; int n; - n = write(pt->dummy_pipe_fds[1], &buf, 1); + n = (int)write(pt->dummy_pipe_fds[1], &buf, 1); return n != 1; #endif diff --git a/lib/plat/unix/unix-resolv.c b/lib/plat/unix/unix-resolv.c index f58776348..177ecade1 100644 --- a/lib/plat/unix/unix-resolv.c +++ b/lib/plat/unix/unix-resolv.c @@ -30,8 +30,9 @@ lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) lws_async_dns_server_check_t s = LADNS_CONF_SERVER_CHANGED; lws_sockaddr46 sa46t; lws_tokenize_t ts; - int fd, n, ns = 0; char ads[48], *r; + int fd, ns = 0; + ssize_t n; r = (char *)context->pt[0].serv_buf; @@ -53,7 +54,7 @@ lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) LWS_TOKENIZE_F_MINUS_NONTERM | LWS_TOKENIZE_F_HASH_COMMENT); do { - ts.e = lws_tokenize(&ts); + ts.e = (int8_t)lws_tokenize(&ts); if (ts.e != LWS_TOKZE_TOKEN) { ns = 0; continue; diff --git a/lib/plat/unix/unix-service.c b/lib/plat/unix/unix-service.c index 7bb22ed65..8428bf86c 100644 --- a/lib/plat/unix/unix-service.c +++ b/lib/plat/unix/unix-service.c @@ -131,7 +131,7 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) vpt->inside_poll = 1; lws_memory_barrier(); - n = poll(pt->fds, pt->fds_count, timeout_us /* ms now */ ); + n = poll(pt->fds, pt->fds_count, (int)timeout_us /* ms now */ ); vpt->inside_poll = 0; lws_memory_barrier(); diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c index 05a6d2a5f..fc0963ddf 100644 --- a/lib/plat/unix/unix-sockets.c +++ b/lib/plat/unix/unix-sockets.c @@ -160,7 +160,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) if (!unix_skt && vhost->bind_iface && vhost->iface) { lwsl_info("binding listen skt to %s using SO_BINDTODEVICE\n", vhost->iface); if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, vhost->iface, - strlen(vhost->iface)) < 0) { + (socklen_t)strlen(vhost->iface)) < 0) { lwsl_warn("Failed to bind to device %s\n", vhost->iface); return 1; } @@ -276,7 +276,7 @@ lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, const char * -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +lws_plat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { return inet_ntop(af, src, dst, cnt); } @@ -310,8 +310,8 @@ lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) } int -lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, - int n, int fd, const char *iface) +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len, + size_t n, int fd, const char *iface) { #if defined(__linux__) struct sockaddr_ll sll; @@ -320,8 +320,8 @@ lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, memcpy(p, canned, canned_len); - p[2] = n >> 8; - p[3] = n; + p[2] = (uint8_t)(n >> 8); + p[3] = (uint8_t)(n); while (p16 < (uint16_t *)(p + 20)) ucs += ntohs(*p16++); @@ -329,19 +329,19 @@ lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, ucs += ucs >> 16; ucs ^= 0xffff; - p[10] = ucs >> 8; - p[11] = ucs; - p[24] = (n - 20) >> 8; - p[25] = (n - 20); + p[10] = (uint8_t)(ucs >> 8); + p[11] = (uint8_t)(ucs); + p[24] = (uint8_t)((n - 20) >> 8); + p[25] = (uint8_t)((n - 20)); memset(&sll, 0, sizeof(sll)); sll.sll_family = AF_PACKET; sll.sll_protocol = htons(0x800); sll.sll_halen = 6; - sll.sll_ifindex = if_nametoindex(iface); + sll.sll_ifindex = (int)if_nametoindex(iface); memset(sll.sll_addr, 0xff, 6); - return sendto(fd, p, n, 0, (struct sockaddr *)&sll, sizeof(sll)); + return (int)sendto(fd, p, n, 0, (struct sockaddr *)&sll, sizeof(sll)); #else lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); @@ -474,7 +474,7 @@ lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len) if (fd < 0) return MBEDTLS_ERR_NET_INVALID_CONTEXT; - ret = write(fd, buf, len); + ret = (int)write(fd, buf, len); if (ret >= 0) return ret; diff --git a/lib/plat/unix/unix-spawn.c b/lib/plat/unix/unix-spawn.c index cf4d2009d..c7300ac44 100644 --- a/lib/plat/unix/unix-spawn.c +++ b/lib/plat/unix/unix-spawn.c @@ -154,7 +154,7 @@ lws_spawn_reap(struct lws_spawn_piped *lsp) /* check if exited, do not reap yet */ memset(&lsp->si, 0, sizeof(lsp->si)); - n = waitid(P_PID, lsp->child_pid, &lsp->si, WEXITED | WNOHANG | WNOWAIT); + n = waitid(P_PID, (id_t)lsp->child_pid, &lsp->si, WEXITED | WNOHANG | WNOWAIT); if (n < 0) { lwsl_info("%s: child %d still running\n", __func__, lsp->child_pid); return 0; @@ -205,14 +205,14 @@ lws_spawn_reap(struct lws_spawn_piped *lsp) /* * Cpu accounting in us */ - lsp->accounting[0] = ((uint64_t)tms.tms_cstime * 1000000) / hz; - lsp->accounting[1] = ((uint64_t)tms.tms_cutime * 1000000) / hz; - lsp->accounting[2] = ((uint64_t)tms.tms_stime * 1000000) / hz; - lsp->accounting[3] = ((uint64_t)tms.tms_utime * 1000000) / hz; + lsp->accounting[0] = (lws_usec_t)((uint64_t)tms.tms_cstime * 1000000) / hz; + lsp->accounting[1] = (lws_usec_t)((uint64_t)tms.tms_cutime * 1000000) / hz; + lsp->accounting[2] = (lws_usec_t)((uint64_t)tms.tms_stime * 1000000) / hz; + lsp->accounting[3] = (lws_usec_t)((uint64_t)tms.tms_utime * 1000000) / hz; } temp = *lsp; - n = waitid(P_PID, lsp->child_pid, &temp.si, WEXITED | WNOHANG); + n = waitid(P_PID, (id_t)lsp->child_pid, &temp.si, WEXITED | WNOHANG); temp.si.si_status &= 0xff; /* we use b8 + for flags */ lwsl_info("%s: waitd says %d, process exit %d\n", __func__, n, temp.si.si_status); diff --git a/lib/plat/windows/windows-file.c b/lib/plat/windows/windows-file.c index 3b9c1462a..5e2625ad9 100644 --- a/lib/plat/windows/windows-file.c +++ b/lib/plat/windows/windows-file.c @@ -134,19 +134,19 @@ _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount, int lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len) + size_t len) { int n; - n = write(fd, buf, len); + n = (int)write(fd, buf, (unsigned int)len); lseek(fd, 0, SEEK_SET); - return n != len; + return (size_t)n != len; } int -lws_plat_write_file(const char *filename, void *buf, int len) +lws_plat_write_file(const char *filename, void *buf, size_t len) { int m, fd; @@ -155,20 +155,20 @@ lws_plat_write_file(const char *filename, void *buf, int len) if (fd == -1) return -1; - m = write(fd, buf, len); + m = (int)write(fd, buf, (unsigned int)len); close(fd); - return m != len; + return (size_t)m != len; } int -lws_plat_read_file(const char *filename, void *buf, int len) +lws_plat_read_file(const char *filename, void *buf, size_t len) { int n, fd = lws_open(filename, O_RDONLY); if (fd == -1) return -1; - n = read(fd, buf, len); + n = (int)read(fd, buf, (unsigned int)len); close(fd); return n; diff --git a/lib/plat/windows/windows-sockets.c b/lib/plat/windows/windows-sockets.c index 8196bdace..6ff11a513 100644 --- a/lib/plat/windows/windows-sockets.c +++ b/lib/plat/windows/windows-sockets.c @@ -228,7 +228,7 @@ lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, } const char * -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +lws_plat_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { WCHAR *buffer; size_t bufferlen = (size_t)cnt; @@ -343,8 +343,8 @@ lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) } int -lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, - int n, int fd, const char *iface) +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len, + size_t n, int fd, const char *iface) { lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); diff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c index 5d2271463..0adf2c95d 100644 --- a/lib/roles/cgi/cgi-server.c +++ b/lib/roles/cgi/cgi-server.c @@ -65,7 +65,7 @@ urlencode(const char *in, int inlen, char *out, int outlen) if (out >= end - 4) return -1; - return out - start; + return lws_ptr_diff(out, start); } static void @@ -145,7 +145,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, cgi->cgi_list = pt->http.cgi_list; pt->http.cgi_list = cgi; - sum += lws_snprintf(sum, sumend - sum, "%s ", exec_array[0]); + sum += lws_snprintf(sum, lws_ptr_diff_size_t(sumend, sum), "%s ", exec_array[0]); if (0) { char *pct = lws_hdr_simple_ptr(wsi, @@ -161,7 +161,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (lws_is_ssl(wsi)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTPS=ON"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTPS=ON"); p++; } @@ -205,17 +205,17 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (m >= 0) { env_array[n++] = p; if (m < (int)LWS_ARRAY_SIZE(meths) - 1) { - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "REQUEST_METHOD=%s", meth_names[m]); - sum += lws_snprintf(sum, sumend - sum, "%s ", + sum += lws_snprintf(sum, lws_ptr_diff_size_t(sumend, sum), "%s ", meth_names[m]); #if defined(LWS_ROLE_H2) } else { - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "REQUEST_METHOD=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD)); - sum += lws_snprintf(sum, sumend - sum, "%s ", + sum += lws_snprintf(sum, lws_ptr_diff_size_t(sumend, sum), "%s ", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD)); #endif @@ -224,11 +224,11 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, } if (uritok >= 0) - sum += lws_snprintf(sum, sumend - sum, "%s ", - lws_hdr_simple_ptr(wsi, uritok)); + sum += lws_snprintf(sum, lws_ptr_diff_size_t(sumend, sum), "%s ", + lws_hdr_simple_ptr(wsi, (enum lws_token_indexes)uritok)); env_array[n++] = p; - p += lws_snprintf(p, end - p, "QUERY_STRING="); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "QUERY_STRING="); /* dump the individual URI Arg parameters */ m = 0; while (script_uri_path_len >= 0) { @@ -241,7 +241,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, *p++ = *t++; if (*t == '=') *p++ = *t++; - i = urlencode(t, i- (t - tok), p, end - p); + i = urlencode(t, i - lws_ptr_diff(t, tok), p, lws_ptr_diff(end, p)); if (i > 0) { p += i; *p++ = '&'; @@ -255,7 +255,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (uritok >= 0) { strcpy(cgi_path, "REQUEST_URI="); c = lws_hdr_copy(wsi, cgi_path + 12, - sizeof(cgi_path) - 12, uritok); + sizeof(cgi_path) - 12, (enum lws_token_indexes)uritok); if (c < 0) goto bail; @@ -263,11 +263,11 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, env_array[n++] = cgi_path; } - sum += lws_snprintf(sum, sumend - sum, "%s", env_array[n - 1]); + sum += lws_snprintf(sum, lws_ptr_diff_size_t(sumend, sum), "%s", env_array[n - 1]); if (script_uri_path_len >= 0) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "PATH_INFO=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "PATH_INFO=%s", cgi_path + 12 + script_uri_path_len); p++; } @@ -276,7 +276,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_REFERER=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_REFERER=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_REFERER)); p++; } @@ -284,15 +284,15 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_HOST=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_HOST=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)); p++; } if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_COOKIE="); - m = lws_hdr_copy(wsi, p, end - p, WSI_TOKEN_HTTP_COOKIE); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_COOKIE="); + m = lws_hdr_copy(wsi, p, lws_ptr_diff(end, p), WSI_TOKEN_HTTP_COOKIE); if (m > 0) p += lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE); *p++ = '\0'; @@ -301,7 +301,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_USER_AGENT=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_USER_AGENT=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_USER_AGENT)); p++; } @@ -309,21 +309,21 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_CONTENT_ENCODING=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_CONTENT_ENCODING=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)); p++; } if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_ACCEPT=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_ACCEPT=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_ACCEPT)); p++; } if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "HTTP_ACCEPT_ENCODING=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "HTTP_ACCEPT_ENCODING=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_ACCEPT_ENCODING)); p++; } @@ -331,37 +331,37 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, uritok == WSI_TOKEN_POST_URI) { if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "CONTENT_TYPE=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "CONTENT_TYPE=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)); p++; } if (!wsi->http.cgi->gzip_inflate && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "CONTENT_LENGTH=%s", + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "CONTENT_LENGTH=%s", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)); p++; } if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) - wsi->http.cgi->post_in_expected = + wsi->http.cgi->post_in_expected = (lws_filepos_t) atoll(lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)); } env_array[n++] = p; - p += lws_snprintf(p, end - p, "PATH=/bin:/usr/bin:/usr/local/bin:/var/www/cgi-bin"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "PATH=/bin:/usr/bin:/usr/local/bin:/var/www/cgi-bin"); p++; env_array[n++] = p; - p += lws_snprintf(p, end - p, "SCRIPT_PATH=%s", exec_array[0]); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "SCRIPT_PATH=%s", exec_array[0]); p++; while (mp_cgienv) { env_array[n++] = p; - p += lws_snprintf(p, end - p, "%s=%s", mp_cgienv->name, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%s=%s", mp_cgienv->name, mp_cgienv->value); if (!strcmp(mp_cgienv->name, "GIT_PROJECT_ROOT")) { wsi->http.cgi->implied_chunked = 1; @@ -374,7 +374,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, } env_array[n++] = p; - p += lws_snprintf(p, end - p, "SERVER_SOFTWARE=lws"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "SERVER_SOFTWARE=lws"); p++; env_array[n] = NULL; @@ -419,7 +419,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, /* inform cgi owner of the child PID */ n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_CGI_PROCESS_ATTACH, - wsi->user_space, NULL, cgi->lsp->child_pid); + wsi->user_space, NULL, (unsigned int)cgi->lsp->child_pid); (void)n; return 0; @@ -472,7 +472,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) lwsl_debug("LHCS_RESPONSE: issuing response %d\n", wsi->http.cgi->response_code); if (lws_add_http_header_status(wsi, - wsi->http.cgi->response_code, + (unsigned int)wsi->http.cgi->response_code, &p, end)) return 1; if (!wsi->http.cgi->explicitly_chunked && @@ -487,7 +487,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) (unsigned char *)"close", 5, &p, end)) return 1; - n = lws_write(wsi, start, p - start, + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS | LWS_WRITE_NO_FIN); /* @@ -522,8 +522,8 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) return -1; if (*p != ':') { if (*p >= 'A' && *p <= 'Z') - *name++ = (*p++) + - ('a' - 'A'); + *name++ = (unsigned char)((*p++) + + ('a' - 'A')); else *name++ = *p++; } else { @@ -561,7 +561,7 @@ lws_cgi_write_split_stdout_headers(struct lws *wsi) buf, value); if ( lws_add_http_header_by_name(wsi, buf, - (unsigned char *)value, name - value, + (unsigned char *)value, lws_ptr_diff(name, value), (unsigned char **)&wsi->http.cgi->headers_pos, (unsigned char *)wsi->http.cgi->headers_end)) return 1; @@ -592,8 +592,8 @@ post_hpack_recode: case LHCS_DUMP_HEADERS: - n = wsi->http.cgi->headers_pos - - wsi->http.cgi->headers_dumped; + n = (int)(wsi->http.cgi->headers_pos - + wsi->http.cgi->headers_dumped); if (n > 512) n = 512; @@ -608,7 +608,7 @@ post_hpack_recode: m = lws_write(wsi, (unsigned char *)wsi->http.cgi->headers_dumped, - n, cmd); + (unsigned int)n, (enum lws_write_protocol)cmd); if (m < 0) { lwsl_debug("%s: write says %d\n", __func__, m); return -1; @@ -645,7 +645,7 @@ post_hpack_recode: n = 2048; if (wsi->mux_substream) n = 4096; - wsi->http.cgi->headers_buf = lws_malloc(n + LWS_PRE, + wsi->http.cgi->headers_buf = lws_malloc((unsigned int)n + LWS_PRE, "cgi hdr buf"); if (!wsi->http.cgi->headers_buf) { lwsl_err("OOM\n"); @@ -669,7 +669,7 @@ post_hpack_recode: n = lws_get_socket_fd(wsi->http.cgi->lsp->stdwsi[LWS_STDOUT]); if (n < 0) return -1; - n = read(n, &c, 1); + n = (int)read(n, &c, 1); if (n < 0) { if (errno != EAGAIN) { lwsl_debug("%s: read says %d\n", __func__, n); @@ -708,11 +708,11 @@ post_hpack_recode: switch (n) { case SIGNIFICANT_HDR_CONTENT_LENGTH: wsi->http.cgi->content_length = - atoll(wsi->http.cgi->l); + (lws_filepos_t)atoll(wsi->http.cgi->l); break; case SIGNIFICANT_HDR_STATUS: wsi->http.cgi->response_code = - atol(wsi->http.cgi->l); + atoi(wsi->http.cgi->l); lwsl_debug("Status set to %d\n", wsi->http.cgi->response_code); break; @@ -735,7 +735,7 @@ post_hpack_recode: wsi->hdr_state = LCHS_SINGLE_0A; *wsi->http.cgi->headers_pos++ = '\x0d'; } - *wsi->http.cgi->headers_pos++ = c; + *wsi->http.cgi->headers_pos++ = (unsigned char)c; if (c == '\x0d') wsi->hdr_state = LCHS_LF1; @@ -756,7 +756,7 @@ post_hpack_recode: } break; case LCHS_LF1: - *wsi->http.cgi->headers_pos++ = c; + *wsi->http.cgi->headers_pos++ = (unsigned char)c; if (c == '\x0a') { wsi->hdr_state = LCHS_CR2; break; @@ -796,7 +796,7 @@ post_hpack_recode: /* we got \r\n\r[^\n]... unreasonable */ return -1; /* we got \x0anext header, it's reasonable */ - *wsi->http.cgi->headers_pos++ = c; + *wsi->http.cgi->headers_pos++ = (unsigned char)c; wsi->hdr_state = LCHS_HEADER; for (n = 0; n < SIGNIFICANT_HDR_COUNT; n++) wsi->http.cgi->match[n] = 0; @@ -820,7 +820,7 @@ agin: n = lws_get_socket_fd(wsi->http.cgi->lsp->stdwsi[LWS_STDOUT]); if (n < 0) return -1; - n = read(n, start, sizeof(buf) - LWS_PRE); + n = (int)read(n, start, sizeof(buf) - LWS_PRE); if (n < 0 && errno != EAGAIN) { lwsl_debug("%s: stdout read says %d\n", __func__, n); @@ -833,8 +833,8 @@ agin: char chdr[LWS_HTTP_CHUNK_HDR_SIZE]; m = lws_snprintf(chdr, LWS_HTTP_CHUNK_HDR_SIZE - 3, "%X\x0d\x0a", n); - memmove(start + m, start, n); - memcpy(start, chdr, m); + memmove(start + m, start, (unsigned int)n); + memcpy(start, chdr, (unsigned int)m); memcpy(start + m + n, "\x0d\x0a", 2); n += m + 2; } @@ -854,17 +854,17 @@ agin: #endif cmd = LWS_WRITE_HTTP; - if (wsi->http.cgi->content_length_seen + n == + if (wsi->http.cgi->content_length_seen + (unsigned int)n == wsi->http.cgi->content_length) cmd = LWS_WRITE_HTTP_FINAL; - m = lws_write(wsi, (unsigned char *)start, n, cmd); + m = lws_write(wsi, (unsigned char *)start, (unsigned int)n, (enum lws_write_protocol)cmd); //lwsl_notice("write %d\n", m); if (m < 0) { lwsl_debug("%s: stdout write says %d\n", __func__, m); return -1; } - wsi->http.cgi->content_length_seen += n; + wsi->http.cgi->content_length_seen += (unsigned int)n; } else { if (!wsi->mux_substream && m) { @@ -919,7 +919,7 @@ lws_cgi_kill(struct lws *wsi) n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_CGI_TERMINATED, wsi->user_space, (void *)&args, - pid); + (unsigned int)pid); if (n && !m) lws_close_free_wsi(wsi, 0, "lws_cgi_kill"); } diff --git a/lib/roles/cgi/ops-cgi.c b/lib/roles/cgi/ops-cgi.c index a5d63b6af..131fc863a 100644 --- a/lib/roles/cgi/ops-cgi.c +++ b/lib/roles/cgi/ops-cgi.c @@ -69,7 +69,7 @@ rops_handle_POLLIN_cgi(struct lws_context_per_thread *pt, struct lws *wsi, args.ch = wsi->lsp_channel; args.stdwsi = &wsi->parent->http.cgi->lsp->stdwsi[0]; - args.hdr_state = wsi->hdr_state; + args.hdr_state = (enum lws_cgi_hdr_state)wsi->hdr_state; lwsl_debug("CGI LWS_STDOUT %p wsistate 0x%x\n", wsi->parent, wsi->wsistate); diff --git a/lib/roles/dbus/dbus.c b/lib/roles/dbus/dbus.c index d43fc216e..2832facb6 100644 --- a/lib/roles/dbus/dbus.c +++ b/lib/roles/dbus/dbus.c @@ -181,7 +181,7 @@ lws_dbus_add_watch(DBusWatch *w, void *data) lwsl_info("%s: %p, fd %d, data %p, fl %d\n", __func__, w, dbus_watch_get_unix_fd(w), data, lws_flags); - __lws_change_pollfd(wsi, 0, lws_flags); + __lws_change_pollfd(wsi, 0, (int)lws_flags); lws_pt_unlock(pt); lws_context_unlock(pt->context); @@ -251,7 +251,7 @@ lws_dbus_remove_watch(DBusWatch *w, void *data) __func__, w, dbus_watch_get_unix_fd(w), data, lws_flags); - __lws_change_pollfd(wsi, lws_flags, 0); + __lws_change_pollfd(wsi, (int)lws_flags, 0); bail: lws_pt_unlock(pt); diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c index 01437c42c..157a89d37 100644 --- a/lib/roles/h1/ops-h1.c +++ b/lib/roles/h1/ops-h1.c @@ -96,7 +96,7 @@ lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len) * Figure out how much was read, so that we can proceed * appropriately: */ - len -= (buf - last_char); + len -= (unsigned int)lws_ptr_diff(buf, last_char); if (!wsi->hdr_parsing_completed) /* More header content on the way */ @@ -150,10 +150,10 @@ http_postbody: args.ch = LWS_STDIN; args.stdwsi = &wsi->http.cgi->lsp->stdwsi[0]; args.data = buf; - args.len = body_chunk_len; + args.len = (int)(unsigned int)body_chunk_len; /* returns how much used */ - n = user_callback_handle_rxflow( + n = (unsigned int)user_callback_handle_rxflow( wsi->a.protocol->callback, wsi, LWS_CALLBACK_CGI_STDIN_DATA, wsi->user_space, @@ -199,7 +199,7 @@ http_postbody: if (wsi->http.rx_content_remain) { lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); break; } /* he sent all the content in time */ @@ -211,7 +211,7 @@ postbody_completion: */ if (wsi->http.cgi) lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); else #endif lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); @@ -235,7 +235,7 @@ postbody_completion: lwsl_info("HTTP_BODY_COMPLETION: %s (%s)\n", lws_wsi_tag(wsi), wsi->a.protocol->name); - n = wsi->a.protocol->callback(wsi, + n = (unsigned int)wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY_COMPLETION, wsi->user_space, NULL, 0); if (n) { @@ -438,10 +438,10 @@ lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) */ #if defined(LWS_ROLE_H2) if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY) - n = lws_read_h2(wsi, ebuf.token, ebuf.len); + n = lws_read_h2(wsi, ebuf.token, (unsigned int)ebuf.len); else #endif - n = lws_read_h1(wsi, ebuf.token, ebuf.len); + n = lws_read_h1(wsi, ebuf.token, (unsigned int)ebuf.len); if (n < 0) /* we closed wsi */ return LWS_HPI_RET_WSI_ALREADY_DIED; @@ -782,7 +782,7 @@ rops_handle_POLLOUT_h1(struct lws *wsi) #endif lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); } } #endif @@ -824,7 +824,7 @@ rops_write_role_protocol_h1(struct lws *wsi, unsigned char *buf, size_t len, (int)o, (int)*wp, wsi->http.comp_ctx.may_have_more); if (!o) - return olen; + return (int)olen; if (wsi->http.comp_ctx.chunking) { char c[LWS_HTTP_CHUNK_HDR_MAX_SIZE + 2]; @@ -835,8 +835,8 @@ rops_write_role_protocol_h1(struct lws *wsi, unsigned char *buf, size_t len, n = lws_snprintf(c, sizeof(c), "%X\x0d\x0a", (int)o); lwsl_info("%s: chunk (%d) %s", __func__, (int)o, c); out -= n; - o += n; - memcpy(out, c, n); + o += (unsigned int)n; + memcpy(out, c, (unsigned int)n); out[o++] = '\x0d'; out[o++] = '\x0a'; @@ -974,7 +974,7 @@ rops_adoption_bind_h1(struct lws *wsi, int type, const char *vh_prot_name) /* the transport is accepted... give him time to negotiate */ lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); return 1; /* bound */ } diff --git a/lib/roles/h2/hpack.c b/lib/roles/h2/hpack.c index eff8a2745..21847076d 100644 --- a/lib/roles/h2/hpack.c +++ b/lib/roles/h2/hpack.c @@ -280,10 +280,10 @@ static int lws_frag_append(struct lws *wsi, unsigned char c) { struct allocated_headers *ah = wsi->http.ah; - ah->data[ah->pos++] = c; + ah->data[ah->pos++] = (char)c; ah->frags[ah->nfrag].len++; - return (int)ah->pos >= wsi->a.context->max_http_header_data; + return (unsigned int)ah->pos >= wsi->a.context->max_http_header_data; } static int lws_frag_end(struct lws *wsi) @@ -328,13 +328,13 @@ static void lws_dump_header(struct lws *wsi, int hdr) (void)p; - len = lws_hdr_copy(wsi, s, sizeof(s) - 1, hdr); + len = lws_hdr_copy(wsi, s, sizeof(s) - 1, (enum lws_token_indexes)hdr); if (len < 0) strcpy(s, "(too big to show)"); else s[len] = '\0'; #if defined(_DEBUG) - p = lws_token_to_string(hdr); + p = lws_token_to_string((enum lws_token_indexes)hdr); lwsl_header(" hdr tok %d (%s) = '%s' (len %d)\n", hdr, p ? (char *)p : (char *)"null", s, len); #endif @@ -464,8 +464,8 @@ static void lws_dynamic_free(struct hpack_dynamic_table *dyn, int idx) { lwsl_header("freeing %d for reuse\n", idx); - dyn->virtual_payload_usage -= dyn->entries[idx].value_len + - dyn->entries[idx].hdr_len; + dyn->virtual_payload_usage = (uint32_t)((unsigned int)dyn->virtual_payload_usage - (unsigned int)(dyn->entries[idx].value_len + + dyn->entries[idx].hdr_len)); lws_free_set_NULL(dyn->entries[idx].value); dyn->entries[idx].value = NULL; dyn->entries[idx].value_len = 0; @@ -490,7 +490,7 @@ lws_dynamic_free(struct hpack_dynamic_table *dyn, int idx) static int lws_dynamic_token_insert(struct lws *wsi, int hdr_len, - int lws_hdr_index, char *arg, int len) + int lws_hdr_index, char *arg, size_t len) { struct hpack_dynamic_table *dyn; int new_index; @@ -524,7 +524,7 @@ lws_dynamic_token_insert(struct lws *wsi, int hdr_len, while (dyn->virtual_payload_usage && dyn->used_entries && - dyn->virtual_payload_usage + hdr_len + len > + dyn->virtual_payload_usage + (unsigned int)hdr_len + len > dyn->virtual_payload_max + 1024) { int n = lws_safe_modulo(dyn->pos - dyn->used_entries, dyn->num_entries); @@ -548,21 +548,22 @@ lws_dynamic_token_insert(struct lws *wsi, int hdr_len, memcpy(dyn->entries[new_index].value, arg, len); dyn->entries[new_index].value[len] = '\0'; - dyn->entries[new_index].value_len = len; + dyn->entries[new_index].value_len = (uint16_t)len; } else dyn->entries[new_index].value = NULL; - dyn->entries[new_index].lws_hdr_idx = lws_hdr_index; - dyn->entries[new_index].hdr_len = hdr_len; + dyn->entries[new_index].lws_hdr_idx = (uint16_t)lws_hdr_index; + dyn->entries[new_index].hdr_len = (uint16_t)hdr_len; - dyn->virtual_payload_usage += hdr_len + len; + dyn->virtual_payload_usage = (uint32_t)(dyn->virtual_payload_usage + + (unsigned int)hdr_len + len); lwsl_info("%s: index %ld: lws_hdr_index 0x%x, hdr len %d, '%s' len %d\n", __func__, (long)LWS_ARRAY_SIZE(static_token), lws_hdr_index, hdr_len, dyn->entries[new_index].value ? - dyn->entries[new_index].value : "null", len); + dyn->entries[new_index].value : "null", (int)len); - dyn->pos = lws_safe_modulo(dyn->pos + 1, dyn->num_entries); + dyn->pos = (uint16_t)lws_safe_modulo(dyn->pos + 1, dyn->num_entries); lws_h2_dynamic_table_dump(wsi); @@ -620,10 +621,10 @@ lws_hpack_dynamic_size(struct lws *wsi, int size) goto bail; } - size = nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]; + size = (int)nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]; } - dyn->virtual_payload_max = size; + dyn->virtual_payload_max = (uint32_t)size; size = size / 8; min = size; @@ -638,7 +639,7 @@ lws_hpack_dynamic_size(struct lws *wsi, int size) // lwsl_notice("dte requested size %d\n", size); - dte = lws_zalloc(sizeof(*dte) * (size + 1), "dynamic table entries"); + dte = lws_zalloc(sizeof(*dte) * (unsigned int)(size + 1), "dynamic table entries"); if (!dte) goto bail; @@ -666,10 +667,10 @@ lws_hpack_dynamic_size(struct lws *wsi, int size) } dyn->entries = dte; - dyn->num_entries = size; - dyn->used_entries = min; + dyn->num_entries = (uint16_t)size; + dyn->used_entries = (uint16_t)min; if (size) - dyn->pos = lws_safe_modulo(min, size); + dyn->pos = (uint16_t)lws_safe_modulo(min, size); else dyn->pos = 0; @@ -730,7 +731,7 @@ lws_hpack_use_idx_hdr(struct lws *wsi, int idx, int known_token) tok); } else lwsl_header("writing indexed hdr %d (tok %d '%s')\n", idx, tok, - lws_token_to_string(tok)); + lws_token_to_string((enum lws_token_indexes)tok)); if (tok == LWS_HPACK_IGNORE_ENTRY) return 0; @@ -746,7 +747,7 @@ lws_hpack_use_idx_hdr(struct lws *wsi, int idx, int known_token) if (p) while (*p && len--) - if (lws_frag_append(wsi, *p++)) + if (lws_frag_append(wsi, (unsigned char)*p++)) return 1; if (lws_frag_end(wsi)) @@ -878,7 +879,7 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) return 1; } - m = lws_token_from_index(wsi, h2n->hdr_idx, + m = lws_token_from_index(wsi, (int)h2n->hdr_idx, NULL, NULL, NULL); if (lws_hpack_handle_pseudo_rules(nwsi, wsi, m)) return 1; @@ -983,16 +984,16 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) break; } h2n->last_action_dyntable_resize = 1; - if (lws_hpack_dynamic_size(wsi, h2n->hpack_len)) + if (lws_hpack_dynamic_size(wsi, (int)h2n->hpack_len)) return 1; break; } break; case HPKS_IDX_EXT: - h2n->hpack_len = h2n->hpack_len | - ((c & 0x7f) << h2n->ext_count); - h2n->ext_count += 7; + h2n->hpack_len = (uint32_t)((unsigned int)h2n->hpack_len | + (unsigned int)((c & 0x7f) << h2n->ext_count)); + h2n->ext_count = (uint8_t)(h2n->ext_count + 7); if (c & 0x80) /* extended int not complete yet */ break; @@ -1002,8 +1003,8 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) switch (h2n->hpack_type) { case HPKT_INDEXED_HDR_7: - if (lws_hpack_use_idx_hdr(wsi, h2n->hpack_len, - h2n->hdr_idx)) { + if (lws_hpack_use_idx_hdr(wsi, (int)h2n->hpack_len, + (int)h2n->hdr_idx)) { lwsl_notice("%s: hd7 use fail\n", __func__); return 1; } @@ -1012,7 +1013,7 @@ int lws_hpack_interpret(struct lws *wsi, unsigned char c) case HPKT_SIZE_5: h2n->last_action_dyntable_resize = 1; - if (lws_hpack_dynamic_size(wsi, h2n->hpack_len)) + if (lws_hpack_dynamic_size(wsi, (int)h2n->hpack_len)) return 1; h2n->hpack = HPKS_TYPE; break; @@ -1064,11 +1065,11 @@ pre_data: n = ah->parser_state; if (n == 255) { n = -1; - h2n->hdr_idx = -1; + h2n->hdr_idx = (uint32_t)-1; } else h2n->hdr_idx = 1; } else { - n = lws_token_from_index(wsi, h2n->hdr_idx, NULL, + n = lws_token_from_index(wsi, (int)h2n->hdr_idx, NULL, NULL, NULL); lwsl_header(" lws_tok_from_idx(%u) says %d\n", (unsigned int)h2n->hdr_idx, n); @@ -1100,9 +1101,9 @@ pre_data: break; case HPKS_HLEN_EXT: - h2n->hpack_len = h2n->hpack_len | - ((c & 0x7f) << h2n->ext_count); - h2n->ext_count += 7; + h2n->hpack_len = (uint32_t)((unsigned int)h2n->hpack_len | + (unsigned int)((c & 0x7f) << h2n->ext_count)); + h2n->ext_count = (uint8_t)(h2n->ext_count + 7); if (c & 0x80) /* extended integer not complete yet */ break; @@ -1117,9 +1118,9 @@ pre_data: if (h2n->huff) { char b = (c >> 7) & 1; prev = h2n->hpack_pos; - h2n->hpack_pos = huftable_decode( - h2n->hpack_pos, b); - c <<= 1; + h2n->hpack_pos = (uint16_t)huftable_decode( + (int)h2n->hpack_pos, b); + c = (unsigned char)(c << 1); if (h2n->hpack_pos == 0xffff) { lwsl_notice("Huffman err\n"); return 1; @@ -1130,7 +1131,7 @@ pre_data: h2n->huff_pad++; continue; } - c1 = h2n->hpack_pos & 0x7fff; + c1 = (uint8_t)(h2n->hpack_pos & 0x7fff); h2n->hpack_pos = 0; h2n->huff_pad = 0; h2n->zero_huff_padding = 0; @@ -1191,7 +1192,7 @@ pre_data: h2n->hpack_hdr_len++; if (h2n->is_first_header_char) { h2n->is_first_header_char = 0; - h2n->first_hdr_char = c1; + h2n->first_hdr_char = (char)c1; } lwsl_header("parser: %c\n", c1); /* uppercase header names illegal */ @@ -1249,7 +1250,7 @@ fin: #endif ah->parser_state == WSI_TOKEN_SKIPPING) { h2n->unknown_header = 1; - ah->parser_state = -1; + ah->parser_state = 0xff; wsi->seen_nonpseudoheader = 1; } } @@ -1276,7 +1277,7 @@ fin: /* NEW indexed hdr with value */ case HPKT_INDEXED_HDR_6_VALUE_INCR: /* header length is determined by known index */ - m = lws_token_from_index(wsi, h2n->hdr_idx, NULL, NULL, + m = lws_token_from_index(wsi, (int)h2n->hdr_idx, NULL, NULL, &h2n->hpack_hdr_len); if (m < 0) /* @@ -1316,7 +1317,7 @@ add_it: */ ah->frags[ah->nfrag].flags |= 1; - if (lws_dynamic_token_insert(wsi, h2n->hpack_hdr_len, m, + if (lws_dynamic_token_insert(wsi, (int)h2n->hpack_hdr_len, m, &ah->data[ah->frags[ah->nfrag].offset], ah->frags[ah->nfrag].len)) { lwsl_notice("%s: tok_insert fail\n", __func__); @@ -1340,7 +1341,7 @@ add_it: if (m == 255) m = -1; } else - m = lws_token_from_index(wsi, h2n->hdr_idx, + m = lws_token_from_index(wsi, (int)h2n->hdr_idx, NULL, NULL, NULL); } @@ -1360,13 +1361,13 @@ add_it: -static int +static unsigned int lws_h2_num_start(int starting_bits, unsigned long num) { - unsigned int mask = (1 << starting_bits) - 1; + unsigned int mask = (unsigned int)((1 << starting_bits) - 1); if (num < mask) - return (int)num; + return (unsigned int)num; return mask; } @@ -1375,7 +1376,7 @@ static int lws_h2_num(int starting_bits, unsigned long num, unsigned char **p, unsigned char *end) { - unsigned int mask = (1 << starting_bits) - 1; + unsigned int mask = (unsigned int)((1 << starting_bits) - 1); if (num < mask) return 0; @@ -1383,9 +1384,9 @@ lws_h2_num(int starting_bits, unsigned long num, num -= mask; do { if (num > 127) - *((*p)++) = 0x80 | (num & 0x7f); + *((*p)++) = (uint8_t)(0x80 | (num & 0x7f)); else - *((*p)++) = 0x00 | (num & 0x7f); + *((*p)++) = (uint8_t)(0x00 | (num & 0x7f)); if (*p >= end) return 1; num >>= 7; @@ -1416,7 +1417,7 @@ int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name, len--; if (wsi->mux_substream && !strncmp((const char *)name, - "transfer-encoding", len)) { + "transfer-encoding", (unsigned int)len)) { lwsl_header("rejecting %s\n", name); return 0; @@ -1427,21 +1428,21 @@ int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name, *((*p)++) = 0; /* literal hdr, literal name, */ - *((*p)++) = 0 | lws_h2_num_start(7, len); /* non-HUF */ - if (lws_h2_num(7, len, p, end)) + *((*p)++) = 0 | (uint8_t)lws_h2_num_start(7, (unsigned long)len); /* non-HUF */ + if (lws_h2_num(7, (unsigned long)len, p, end)) return 1; /* upper-case header names are verboten in h2, but OK on h1, so * they're not illegal per se. Silently convert them for h2... */ while(len--) - *((*p)++) = tolower((int)*name++); + *((*p)++) = (uint8_t)tolower((int)*name++); - *((*p)++) = 0 | lws_h2_num_start(7, length); /* non-HUF */ - if (lws_h2_num(7, length, p, end)) + *((*p)++) = 0 | (uint8_t)lws_h2_num_start(7, (unsigned long)length); /* non-HUF */ + if (lws_h2_num(7, (unsigned long)length, p, end)) return 1; - memcpy(*p, value, length); + memcpy(*p, value, (unsigned int)length); *p += length; return 0; diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 0364d8494..df7fd7412 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -151,7 +151,7 @@ lws_h2_state(struct lws *wsi, enum lws_h2_states s) } int -lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump) +lws_h2_update_peer_txcredit(struct lws *wsi, unsigned int sid, int bump) { struct lws *nwsi = lws_get_network_wsi(wsi); struct lws_h2_protocol_send *pps; @@ -161,7 +161,7 @@ lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump) if (!bump) return 0; - if (sid == -1) + if (sid == (unsigned int)-1) sid = wsi->mux.my_sid; lwsl_info("%s: sid %d: bump %d -> %d\n", __func__, sid, bump, @@ -171,8 +171,8 @@ lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump) if (!pps) return 1; - pps->u.update_window.sid = sid; - pps->u.update_window.credit = bump; + pps->u.update_window.sid = (unsigned int)sid; + pps->u.update_window.credit = (unsigned int)bump; wsi->txc.peer_tx_cr_est += bump; lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); @@ -184,7 +184,7 @@ lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump) return 1; pps->u.update_window.sid = 0; - pps->u.update_window.credit = bump; + pps->u.update_window.credit = (unsigned int)bump; nwsi->txc.peer_tx_cr_est += bump; lws_wsi_txc_describe(&nwsi->txc, __func__, nwsi->mux.my_sid); @@ -202,7 +202,7 @@ lws_h2_get_peer_txcredit_estimate(struct lws *wsi) } static int -lws_h2_update_peer_txcredit_thresh(struct lws *wsi, int sid, int threshold, int bump) +lws_h2_update_peer_txcredit_thresh(struct lws *wsi, unsigned int sid, int threshold, int bump) { if (wsi->txc.peer_tx_cr_est > threshold) return 0; @@ -256,9 +256,9 @@ lws_wsi_server_new(struct lws_vhost *vh, struct lws *parent_wsi, wsi->mux_substream = 1; wsi->seen_nonpseudoheader = 0; - wsi->txc.tx_cr = nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->txc.tx_cr = (int32_t)nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; wsi->txc.peer_tx_cr_est = - nwsi->h2.h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; + (int32_t)nwsi->h2.h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsi_set_state(wsi, LRS_ESTABLISHED); lwsi_set_role(wsi, lwsi_role(parent_wsi)); @@ -336,8 +336,8 @@ lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi) lws_wsi_mux_insert(wsi, parent_wsi, wsi->mux.my_sid); - wsi->txc.tx_cr = nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; - wsi->txc.peer_tx_cr_est = + wsi->txc.tx_cr = (int32_t)nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->txc.peer_tx_cr_est = (int32_t) nwsi->h2.h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); @@ -483,10 +483,10 @@ lws_h2_settings(struct lws *wsi, struct http2_settings *settings, return 1; while (len >= LWS_H2_SETTINGS_LEN) { - a = (buf[0] << 8) | buf[1]; + a = (unsigned int)((buf[0] << 8) | buf[1]); if (!a || a >= H2SET_COUNT) goto skip; - b = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5]; + b = (unsigned int)(buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5]); switch (a) { case H2SET_HEADER_TABLE_SIZE: @@ -538,9 +538,9 @@ lws_h2_settings(struct lws *wsi, struct http2_settings *settings, lwsl_info("%s: adi child tc cr %d +%d -> %d", __func__, (int)w->txc.tx_cr, b - (unsigned int)settings->s[a], - (int)w->txc.tx_cr + b - - (unsigned int)settings->s[a]); - w->txc.tx_cr += b - settings->s[a]; + (int)(w->txc.tx_cr + (int)b - + (int)settings->s[a])); + w->txc.tx_cr += (int)b - (int)settings->s[a]; if (w->txc.tx_cr > 0 && w->txc.tx_cr <= (int32_t)(b - settings->s[a])) @@ -639,15 +639,15 @@ int lws_h2_frame_write(struct lws *wsi, int type, int flags, //if (wsi->h2_stream_carries_ws) // lwsl_hexdump_level(LLL_NOTICE, buf, len); - *p++ = len >> 16; - *p++ = len >> 8; - *p++ = len; - *p++ = type; - *p++ = flags; - *p++ = sid >> 24; - *p++ = sid >> 16; - *p++ = sid >> 8; - *p++ = sid; + *p++ = (uint8_t)(len >> 16); + *p++ = (uint8_t)(len >> 8); + *p++ = (uint8_t)len; + *p++ = (uint8_t)type; + *p++ = (uint8_t)flags; + *p++ = (uint8_t)(sid >> 24); + *p++ = (uint8_t)(sid >> 16); + *p++ = (uint8_t)(sid >> 8); + *p++ = (uint8_t)sid; lwsl_debug("%s: %s (eff %s). typ %d, fl 0x%x, sid=%d, len=%d, " "txcr=%d, nwsi->txcr=%d\n", __func__, lws_wsi_tag(wsi), @@ -656,10 +656,11 @@ int lws_h2_frame_write(struct lws *wsi, int type, int flags, if (type == LWS_H2_FRAME_TYPE_DATA) { if (wsi->txc.tx_cr < (int)len) + lwsl_info("%s: %s: sending payload len %d" " but tx_cr only %d!\n", __func__, lws_wsi_tag(wsi), len, (int)wsi->txc.tx_cr); - lws_h2_tx_cr_consume(wsi, len); + lws_h2_tx_cr_consume(wsi, (int)len); } n = lws_issue_raw(nwsi, &buf[-LWS_H2_FRAME_HEADER_LENGTH], @@ -675,12 +676,12 @@ int lws_h2_frame_write(struct lws *wsi, int type, int flags, static void lws_h2_set_bin(struct lws *wsi, int n, unsigned char *buf) { - *buf++ = n >> 8; - *buf++ = n; - *buf++ = wsi->h2.h2n->our_set.s[n] >> 24; - *buf++ = wsi->h2.h2n->our_set.s[n] >> 16; - *buf++ = wsi->h2.h2n->our_set.s[n] >> 8; - *buf = wsi->h2.h2n->our_set.s[n]; + *buf++ = (uint8_t)(n >> 8); + *buf++ = (uint8_t)n; + *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 24); + *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 16); + *buf++ = (uint8_t)(wsi->h2.h2n->our_set.s[n] >> 8); + *buf = (uint8_t)wsi->h2.h2n->our_set.s[n]; } /* we get called on the network connection */ @@ -726,10 +727,10 @@ int lws_h2_do_pps_send(struct lws *wsi) wsi->h2.h2n->our_set.s[n]); lws_h2_set_bin(wsi, n, &set[LWS_PRE + m]); - m += sizeof(h2n->one_setting); + m += (int)sizeof(h2n->one_setting); } n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, - flags, LWS_H2_STREAM_ID_MASTER, m, + flags, LWS_H2_STREAM_ID_MASTER, (unsigned int)m, &set[LWS_PRE]); if (n != m) { lwsl_info("send %d %d\n", n, m); @@ -739,12 +740,12 @@ int lws_h2_do_pps_send(struct lws *wsi) case LWS_H2_PPS_SETTINGS_INITIAL_UPDATE_WINDOW: q = &set[LWS_PRE]; - *q++ = H2SET_INITIAL_WINDOW_SIZE >> 8; - *q++ = H2SET_INITIAL_WINDOW_SIZE; - *q++ = pps->u.update_window.credit >> 24; - *q++ = pps->u.update_window.credit >> 16; - *q++ = pps->u.update_window.credit >> 8; - *q = pps->u.update_window.credit; + *q++ = (uint8_t)(H2SET_INITIAL_WINDOW_SIZE >> 8); + *q++ = (uint8_t)(H2SET_INITIAL_WINDOW_SIZE); + *q++ = (uint8_t)(pps->u.update_window.credit >> 24); + *q++ = (uint8_t)(pps->u.update_window.credit >> 16); + *q++ = (uint8_t)(pps->u.update_window.credit >> 8); + *q = (uint8_t)(pps->u.update_window.credit); lwsl_debug("%s: resetting initial window to %d\n", __func__, (int)pps->u.update_window.credit); @@ -795,7 +796,7 @@ int lws_h2_do_pps_send(struct lws *wsi) lwsl_info("%s: inherited headers %p\n", __func__, h2n->swsi->http.ah); - h2n->swsi->txc.tx_cr = + h2n->swsi->txc.tx_cr = (int32_t) h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsl_info("initial tx credit on %s: %d\n", lws_wsi_tag(h2n->swsi), @@ -840,14 +841,14 @@ int lws_h2_do_pps_send(struct lws *wsi) case LWS_H2_PPS_GOAWAY: lwsl_info("LWS_H2_PPS_GOAWAY\n"); - *p++ = pps->u.ga.highest_sid >> 24; - *p++ = pps->u.ga.highest_sid >> 16; - *p++ = pps->u.ga.highest_sid >> 8; - *p++ = pps->u.ga.highest_sid; - *p++ = pps->u.ga.err >> 24; - *p++ = pps->u.ga.err >> 16; - *p++ = pps->u.ga.err >> 8; - *p++ = pps->u.ga.err; + *p++ = (uint8_t)(pps->u.ga.highest_sid >> 24); + *p++ = (uint8_t)(pps->u.ga.highest_sid >> 16); + *p++ = (uint8_t)(pps->u.ga.highest_sid >> 8); + *p++ = (uint8_t)(pps->u.ga.highest_sid); + *p++ = (uint8_t)(pps->u.ga.err >> 24); + *p++ = (uint8_t)(pps->u.ga.err >> 16); + *p++ = (uint8_t)(pps->u.ga.err >> 8); + *p++ = (uint8_t)(pps->u.ga.err); q = (unsigned char *)pps->u.ga.str; n = 0; while (*q && n++ < (int)sizeof(pps->u.ga.str)) @@ -855,7 +856,7 @@ int lws_h2_do_pps_send(struct lws *wsi) h2n->we_told_goaway = 1; n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_GOAWAY, 0, LWS_H2_STREAM_ID_MASTER, - lws_ptr_diff(p, &set[LWS_PRE]), + (unsigned int)lws_ptr_diff(p, &set[LWS_PRE]), &set[LWS_PRE]); if (n != 4) { lwsl_info("send %d %d\n", n, m); @@ -865,10 +866,10 @@ int lws_h2_do_pps_send(struct lws *wsi) case LWS_H2_PPS_RST_STREAM: lwsl_info("LWS_H2_PPS_RST_STREAM\n"); - *p++ = pps->u.rs.err >> 24; - *p++ = pps->u.rs.err >> 16; - *p++ = pps->u.rs.err >> 8; - *p++ = pps->u.rs.err; + *p++ = (uint8_t)(pps->u.rs.err >> 24); + *p++ = (uint8_t)(pps->u.rs.err >> 16); + *p++ = (uint8_t)(pps->u.rs.err >> 8); + *p++ = (uint8_t)(pps->u.rs.err); n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_RST_STREAM, 0, pps->u.rs.sid, 4, &set[LWS_PRE]); if (n != 4) { @@ -889,10 +890,10 @@ int lws_h2_do_pps_send(struct lws *wsi) lwsl_info("Issuing LWS_H2_PPS_UPDATE_WINDOW: sid %d: add %d\n", (int)pps->u.update_window.sid, (int)pps->u.update_window.credit); - *p++ = (pps->u.update_window.credit >> 24) & 0x7f; /* 31b */ - *p++ = pps->u.update_window.credit >> 16; - *p++ = pps->u.update_window.credit >> 8; - *p++ = pps->u.update_window.credit; + *p++ = (uint8_t)((pps->u.update_window.credit >> 24) & 0x7f); /* 31b */ + *p++ = (uint8_t)(pps->u.update_window.credit >> 16); + *p++ = (uint8_t)(pps->u.update_window.credit >> 8); + *p++ = (uint8_t)(pps->u.update_window.credit); n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_WINDOW_UPDATE, 0, pps->u.update_window.sid, 4, &set[LWS_PRE]); @@ -1038,7 +1039,7 @@ lws_h2_parse_frame_header(struct lws *wsi) n = H2_ERR_STREAM_CLOSED; else n = H2_ERR_PROTOCOL_ERROR; - lws_h2_goaway(wsi, n, "invalid rx for state"); + lws_h2_goaway(wsi, (unsigned int)n, "invalid rx for state"); return 0; } @@ -1054,7 +1055,7 @@ lws_h2_parse_frame_header(struct lws *wsi) n = H2_ERR_COMPRESSION_ERROR; else n = H2_ERR_PROTOCOL_ERROR; - lws_h2_goaway(wsi, n, "Continuation hdrs State"); + lws_h2_goaway(wsi, (unsigned int)n, "Continuation hdrs State"); return 0; } @@ -1478,7 +1479,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) lwsl_info("%s: MIGRATING nwsi %s -> swsi %s\n", __func__, lws_wsi_tag(wsi), lws_wsi_tag(h2n->swsi)); - h2n->swsi->txc.tx_cr = + h2n->swsi->txc.tx_cr = (int32_t) h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsl_info("%s: initial tx credit on %s: %d\n", __func__, lws_wsi_tag(h2n->swsi), @@ -1487,7 +1488,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) /* set our initial window size */ if (!wsi->h2.initialized) { - wsi->txc.tx_cr = + wsi->txc.tx_cr = (int32_t) h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsl_info("%s: initial tx credit for us to " @@ -1578,7 +1579,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) if (!simp) /* coverity */ return 1; - h2n->swsi->http.rx_content_length = atoll(simp); + h2n->swsi->http.rx_content_length = (unsigned long long)atoll(simp); h2n->swsi->http.rx_content_remain = h2n->swsi->http.rx_content_length; lwsl_info("setting rx_content_length %lld\n", @@ -1591,20 +1592,20 @@ lws_h2_parse_end_of_frame(struct lws *wsi) const unsigned char *c; do { - c = lws_token_to_string(n); + c = lws_token_to_string((enum lws_token_indexes)n); if (!c) { n++; continue; } - len = lws_hdr_total_length(h2n->swsi, n); + len = lws_hdr_total_length(h2n->swsi, (enum lws_token_indexes)n); if (!len || len > (int)sizeof(buf) - 1) { n++; continue; } if (lws_hdr_copy(h2n->swsi, buf, sizeof buf, - n) < 0) { + (enum lws_token_indexes)n) < 0) { lwsl_info(" %s !oversize!\n", (char *)c); } else { @@ -1664,7 +1665,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) if (n != 8 || !lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_TE) || strncmp(lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_TE), - "trailers", n)) { + "trailers", (unsigned int)n)) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "Illegal transfer-encoding"); break; @@ -1798,7 +1799,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW && (uint64_t)eff_wsi->txc.tx_cr + (uint64_t)h2n->hpack_e_dep > (uint64_t)0x7fffffff) - h2n->hpack_e_dep = 0x7fffffff - eff_wsi->txc.tx_cr; + h2n->hpack_e_dep = (uint32_t)(0x7fffffff - eff_wsi->txc.tx_cr); if ((uint64_t)eff_wsi->txc.tx_cr + (uint64_t)h2n->hpack_e_dep > (uint64_t)0x7fffffff) { @@ -1818,7 +1819,7 @@ lws_h2_parse_end_of_frame(struct lws *wsi) break; } n = eff_wsi->txc.tx_cr; - eff_wsi->txc.tx_cr += h2n->hpack_e_dep; + eff_wsi->txc.tx_cr += (int32_t)h2n->hpack_e_dep; lws_wsi_txc_report_manual_txcr_in(eff_wsi, (int32_t)h2n->hpack_e_dep); @@ -1993,7 +1994,7 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, switch(h2n->type) { case LWS_H2_FRAME_TYPE_SETTINGS: - n = (h2n->count - 1 - h2n->preamble) % + n = (int)(h2n->count - 1u - h2n->preamble) % LWS_H2_SETTINGS_LEN; h2n->one_setting[n] = c; if (n != LWS_H2_SETTINGS_LEN - 1) @@ -2037,7 +2038,7 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, if (h2n->inside - 9 < sizeof(h2n->goaway_str) - 1) h2n->goaway_str[ - h2n->inside - 9] = c; + h2n->inside - 9] = (char)c; h2n->goaway_str[ sizeof(h2n->goaway_str) - 1] = '\0'; break; @@ -2096,7 +2097,9 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, n = (int)lws_ptr_diff_size_t(iend, in) + 1; if (n > (int)(h2n->length - h2n->count + 1)) { - n = h2n->length - h2n->count + 1; + if (h2n->count > h2n->length) + goto close_swsi_and_return; + n = (int)(h2n->length - h2n->count) + 1; lwsl_debug("---- restricting len to %d " "\n", n); } @@ -2117,7 +2120,7 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, h2n->swsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, h2n->swsi->user_space, - in - 1, n); + in - 1, (unsigned int)n); } in += n - 1; @@ -2136,7 +2139,7 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, if (lwsi_state(h2n->swsi) == LRS_DEFERRING_ACTION) { m = lws_buflist_append_segment( - &h2n->swsi->buflist, in - 1, n); + &h2n->swsi->buflist, in - 1, (unsigned int)n); if (m < 0) return -1; if (m) { @@ -2164,7 +2167,7 @@ lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t _inlen, * more waiting leave it for next time around */ - n = lws_read_h1(h2n->swsi, in - 1, n); + n = lws_read_h1(h2n->swsi, in - 1, (unsigned int)n); // lwsl_notice("%s: lws_read_h1 %d\n", __func__, n); h2n->swsi->outer_will_close = 0; /* @@ -2350,7 +2353,7 @@ try_frame_start: } } - *inused = in - oldin; + *inused = (lws_filepos_t)lws_ptr_diff_size_t(in, oldin); return 0; @@ -2362,12 +2365,12 @@ close_swsi_and_return: h2n->count = 0; // already_closed_swsi: - *inused = in - oldin; + *inused = (lws_filepos_t)lws_ptr_diff_size_t(in, oldin); return 2; fail: - *inused = in - oldin; + *inused = (lws_filepos_t)lws_ptr_diff_size_t(in, oldin); return 1; } @@ -2390,7 +2393,7 @@ lws_h2_client_handshake(struct lws *wsi) * receives an unexpected stream identifier MUST respond with a * connection error (Section 5.4.1) of type PROTOCOL_ERROR. */ - int sid = nwsi->h2.h2n->highest_sid_opened + 2; + unsigned int sid = nwsi->h2.h2n->highest_sid_opened + 2; lwsl_debug("%s\n", __func__); @@ -2475,7 +2478,7 @@ lws_h2_client_handshake(struct lws *wsi) if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, - wsi->user_space, &p, (end - p) - 12)) + wsi->user_space, &p, lws_ptr_diff_size_t(end, p) - 12)) goto fail_length; if (lws_finalize_http_header(wsi, &p, end)) @@ -2496,9 +2499,9 @@ lws_h2_client_handshake(struct lws *wsi) // lwsl_hexdump_notice(start, p - start); - n = lws_write(wsi, start, p - start, m); + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)m); - if (n != (p - start)) { + if (n != lws_ptr_diff(p, start)) { lwsl_err("_write returned %d from %ld\n", n, (long)(p - start)); return -1; @@ -2542,7 +2545,8 @@ lws_h2_ws_handshake(struct lws *wsi) *end = &buf[sizeof(buf) - 1]; const struct lws_http_mount *hit; const char * uri_ptr; - int n, m; + size_t m; + int n; if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) return -1; @@ -2616,11 +2620,11 @@ lws_h2_ws_handshake(struct lws *wsi) if (lws_finalize_http_header(wsi, &p, end)) return -1; - m = lws_ptr_diff(p, start); + m = lws_ptr_diff_size_t(p, start); // lwsl_hexdump_notice(start, m); n = lws_write(wsi, start, m, LWS_WRITE_HTTP_HEADERS); - if (n != m) { - lwsl_err("_write returned %d from %d\n", n, m); + if (n != (int)m) { + lwsl_err("_write returned %d from %d\n", n, (int)m); return -1; } @@ -2674,7 +2678,7 @@ lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len) * we were accepting input but now we stopped doing so */ if (lws_is_flowcontrolled(wsi)) { - lws_rxflow_cache(wsi, buf, 0, (int)len); + lws_rxflow_cache(wsi, buf, 0, (size_t)len); buf += len; break; } diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index 42ed9f5cd..6e2a81f84 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -265,9 +265,9 @@ drain: n = 0; if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY && lwsi_state(wsi) != LRS_DISCARD_BODY) - n = lws_read_h2(wsi, ebuf.token, ebuf.len); + n = lws_read_h2(wsi, ebuf.token, (unsigned int)ebuf.len); else - n = lws_read_h1(wsi, ebuf.token, ebuf.len); + n = lws_read_h1(wsi, ebuf.token, (unsigned int)ebuf.len); if (n < 0) { /* we closed wsi */ @@ -285,11 +285,11 @@ drain: lws_dll2_remove(&wsi->dll_buflist); } } else - if (n && n != ebuf.len) { + if (n && n < ebuf.len && ebuf.len > 0) { // lwsl_notice("%s: h2 append seg %d\n", __func__, ebuf.len - n); m = lws_buflist_append_segment(&wsi->buflist, ebuf.token + n, - ebuf.len - n); + (unsigned int)(ebuf.len - n)); if (m < 0) return LWS_HPI_RET_PLEASE_CLOSE_ME; if (m) { @@ -323,7 +323,7 @@ drain: } #endif - pending = lws_ssl_pending(wsi); + pending = (unsigned int)lws_ssl_pending(wsi); if (pending) { // lwsl_info("going around\n"); goto read; @@ -430,7 +430,7 @@ rops_write_role_protocol_h2(struct lws *wsi, unsigned char *buf, size_t len, base = (*wp) & 0x1f; if (!len) - return olen; + return (int)olen; } #endif @@ -481,7 +481,7 @@ rops_write_role_protocol_h2(struct lws *wsi, unsigned char *buf, size_t len, wsi->h2.send_END_STREAM = 1; } - n = lws_h2_frame_write(wsi, n, flags, wsi->mux.my_sid, (int)len, buf); + n = lws_h2_frame_write(wsi, n, flags, wsi->mux.my_sid, (unsigned int)len, buf); if (n < 0) return n; @@ -584,7 +584,7 @@ rops_tx_credit_h2(struct lws *wsi, char peer_to_us, int add) * We want to tell the peer they can write an additional * "add" bytes to us */ - return lws_h2_update_peer_txcredit(wsi, -1, add); + return lws_h2_update_peer_txcredit(wsi, (unsigned int)-1, add); } /* @@ -684,7 +684,7 @@ rops_close_kill_connection_h2(struct lws *wsi, enum lws_close_status reason) lwsl_info(" parent %s: closing children: list:\n", lws_wsi_tag(wsi)); lws_wsi_mux_dump_children(wsi); } - lws_wsi_mux_close_children(wsi, reason); + lws_wsi_mux_close_children(wsi, (int)reason); } if (wsi->upgraded_to_http2) { @@ -1088,7 +1088,7 @@ rops_perform_user_POLLOUT_h2(struct lws *wsi) LWS_WRITE_H2_STREAM_END; n = lws_write(w, &w->ws->ping_payload_buf[LWS_PRE], - w->ws->ping_payload_len, write_type); + w->ws->ping_payload_len, (enum lws_write_protocol)write_type); if (n < 0) return -1; @@ -1205,7 +1205,7 @@ rops_alpn_negotiated_h2(struct lws *wsi, const char *alpn) /* HTTP2 union */ lws_hpack_dynamic_size(wsi, - wsi->h2.h2n->our_set.s[H2SET_HEADER_TABLE_SIZE]); + (int)wsi->h2.h2n->our_set.s[H2SET_HEADER_TABLE_SIZE]); wsi->txc.tx_cr = 65535; lwsl_info("%s: %s: configured for h2\n", __func__, lws_wsi_tag(wsi)); @@ -1218,7 +1218,7 @@ rops_issue_keepalive_h2(struct lws *wsi, int isvalid) { struct lws *nwsi = lws_get_network_wsi(wsi); struct lws_h2_protocol_send *pps; - uint64_t us = lws_now_usecs(); + uint64_t us = (uint64_t)lws_now_usecs(); if (isvalid) { _lws_validity_confirmed_role(nwsi); diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index b315de7d6..ea2cda220 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -104,7 +104,7 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) goto bail3; } - n = recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); + n = (int)recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); if (n < 0) { if (LWS_ERRNO == LWS_EAGAIN) { lwsl_debug("Proxy read EAGAIN... retrying\n"); @@ -207,8 +207,8 @@ start_ws_handshake: if (context->detailed_latency_cb) { wsi->detlat.type = LDLT_TLS_NEG_CLIENT; wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); } @@ -238,7 +238,7 @@ start_ws_handshake: // lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, - context->timeout_secs); + (int)context->timeout_secs); break; } @@ -274,7 +274,7 @@ hs2: #if defined(LWS_WITH_DETAILED_LATENCY) wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); #endif - n = lws_ssl_capable_write(wsi, (unsigned char *)sb, (int)(p - sb)); + n = lws_ssl_capable_write(wsi, (unsigned char *)sb, lws_ptr_diff_size_t(p, sb)); switch (n) { case LWS_SSL_CAPABLE_ERROR: lwsl_debug("ERROR writing to client socket\n"); @@ -291,7 +291,7 @@ hs2: lwsi_set_state(wsi, LRS_ISSUE_HTTP_BODY); lws_set_timeout(wsi, PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD, - context->timeout_secs); + (int)context->timeout_secs); if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) lws_callback_on_writable(wsi); @@ -319,7 +319,7 @@ hs2: } lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); lws_callback_on_writable(wsi); @@ -348,7 +348,7 @@ client_http_body_sent: #endif lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - context->timeout_secs); + (int)context->timeout_secs); break; case LRS_WAITING_SERVER_REPLY: @@ -528,7 +528,7 @@ lws_http_transaction_completed_client(struct lws *wsi) wsi->http.ah->unk_pos = 0; lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); /* If we're (re)starting on headers, need other implied init */ wsi->http.ah->ues = URIES_IDLE; @@ -651,7 +651,7 @@ lws_client_interpret_server_handshake(struct lws *wsi) #endif n = atoi(p); if (ah) - ah->http_response = n; + ah->http_response = (unsigned int)n; if (!wsi->client_no_follow_redirect && #if defined(LWS_WITH_HTTP_PROXY) @@ -668,7 +668,7 @@ lws_client_interpret_server_handshake(struct lws *wsi) if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_HTTP_REDIRECT, - wsi->user_space, p, n)) { + wsi->user_space, p, (unsigned int)n)) { cce = "HS: user code rejected redirect"; goto bail3; } @@ -737,7 +737,7 @@ lws_client_interpret_server_handshake(struct lws *wsi) q = strrchr(new_path, '/'); if (q) lws_strncpy(q + 1, p, sizeof(new_path) - - (q - new_path) - 1); + (unsigned int)(q - new_path) - 1); else path = p; } @@ -860,7 +860,7 @@ lws_client_interpret_server_handshake(struct lws *wsi) if (!simp) goto bail2; - wsi->http.rx_content_length = atoll(simp); + wsi->http.rx_content_length = (lws_filepos_t)atoll(simp); lwsl_info("%s: incoming content length %llu\n", __func__, (unsigned long long) wsi->http.rx_content_length); @@ -982,7 +982,7 @@ bail2: wsi->a.protocol->name : "unknown", cce); /* closing will free up his parsing allocations */ - lws_close_free_wsi(wsi, close_reason, "c hs interp"); + lws_close_free_wsi(wsi, (enum lws_close_status)close_reason, "c hs interp"); return 1; } @@ -1031,7 +1031,7 @@ lws_client_http_multipart(struct lws *wsi, const char *name, assert(wsi->http.multipart); if (!name) { - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "\xd\xa--%s--\xd\xa", wsi->http.multipart_boundary); @@ -1039,22 +1039,22 @@ lws_client_http_multipart(struct lws *wsi, const char *name, } if (wsi->client_subsequent_mime_part) - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa"); + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "\xd\xa"); wsi->client_subsequent_mime_part = 1; - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "--%s\xd\xa" + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "--%s\xd\xa" "Content-Disposition: form-data; " "name=\"%s\"", wsi->http.multipart_boundary, name); if (filename) - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "; filename=\"%s\"", filename); if (content_type) - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa" + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "\xd\xa" "Content-Type: %s", content_type); - *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa\xd\xa"); + *p += lws_snprintf((char *)(*p), lws_ptr_diff_size_t(end, *p), "\xd\xa\xd\xa"); return *p == end; } @@ -1182,7 +1182,7 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt) if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, wsi->user_space, &p, - (pkt + wsi->a.context->pt_serv_buf_size) - p - 12)) + (unsigned int)((pkt + wsi->a.context->pt_serv_buf_size) - p - 12))) return NULL; if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) { @@ -1215,7 +1215,7 @@ lws_http_basic_auth_gen(const char *user, const char *pw, char *buf, size_t len) memcpy(buf, "Basic ", 6); - n = lws_snprintf(b, sizeof(b), "%s:%s", user, pw); + n = (unsigned int)lws_snprintf(b, sizeof(b), "%s:%s", user, pw); if (n >= sizeof(b) - 2) return 2; @@ -1332,7 +1332,7 @@ spin_chunks: case ELCP_POST_CR: if ((*buf)[0] != '\x0d') { lwsl_err("%s: chunking failure C\n", __func__); - lwsl_hexdump_err(*buf, *len); + lwsl_hexdump_err(*buf, (unsigned int)*len); return -1; } @@ -1354,7 +1354,7 @@ spin_chunks: case ELCP_TRAILER_CR: if ((*buf)[0] != '\x0d') { lwsl_err("%s: chunking failure F\n", __func__); - lwsl_hexdump_err(*buf, *len); + lwsl_hexdump_err(*buf, (unsigned int)*len); return -1; } @@ -1365,7 +1365,7 @@ spin_chunks: case ELCP_TRAILER_LF: if ((*buf)[0] != '\x0a') { lwsl_err("%s: chunking failure F\n", __func__); - lwsl_hexdump_err(*buf, *len); + lwsl_hexdump_err(*buf, (unsigned int)*len); return -1; } @@ -1414,7 +1414,7 @@ spin_chunks: q = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, - wsi->user_space, *buf, n); + wsi->user_space, *buf, (unsigned int)n); if (q) { lwsl_info("%s: RECEIVE_CLIENT_HTTP_READ returned %d\n", __func__, q); @@ -1448,7 +1448,7 @@ spin_chunks: /* if we know the content length, decrement the content remaining */ if (wsi->http.rx_content_length > 0) - wsi->http.rx_content_remain -= n; + wsi->http.rx_content_remain -= (unsigned int)n; // lwsl_notice("rx_content_remain %lld, rx_content_length %lld, giv %d\n", // wsi->http.rx_content_remain, wsi->http.rx_content_length, @@ -1525,10 +1525,10 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, */ for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) - size += lws_hdr_total_length(wsi, hnames2[n]) + (size_t)1; + size += (unsigned int)lws_hdr_total_length(wsi, hnames2[n]) + 1u; if (size < (size_t)lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + 1) - size = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + (size_t)1; + size = (unsigned int)lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + 1u; /* * The incoming address and host can be from inside the existing ah @@ -1613,7 +1613,7 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, #if defined(LWS_WITH_TLS) if (!ssl) - wsi->tls.use_ssl &= ~LCCSCF_USE_SSL; + wsi->tls.use_ssl &= (unsigned int)~LCCSCF_USE_SSL; else wsi->tls.use_ssl |= LCCSCF_USE_SSL; #else @@ -1638,7 +1638,7 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, if (wsi->a.protocol) lws_bind_protocol(wsi, wsi->a.protocol, "client_reset"); wsi->pending_timeout = NO_PENDING_TIMEOUT; - wsi->c_port = port; + wsi->c_port = (uint16_t)port; wsi->hdr_parsing_completed = 0; if (lws_header_table_attach(wsi, 0)) { @@ -1668,7 +1668,7 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) { if (lws_hdr_simple_create(wsi, hnames2[n], p)) goto bail; - p += lws_hdr_total_length(wsi, hnames2[n]) + (size_t)1; + p += lws_hdr_total_length(wsi, hnames2[n]) + 1; } stash[0] = '/'; diff --git a/lib/roles/http/compression/brotli/brotli.c b/lib/roles/http/compression/brotli/brotli.c index c95f5e029..36d776686 100644 --- a/lib/roles/http/compression/brotli/brotli.c +++ b/lib/roles/http/compression/brotli/brotli.c @@ -27,7 +27,7 @@ static int lcs_init_compression_brotli(lws_comp_ctx_t *ctx, int decomp) { - ctx->is_decompression = decomp; + ctx->is_decompression = (unsigned char)!!decomp; if (!decomp) { ctx->u.br_en = BrotliEncoderCreateInstance(NULL, NULL, NULL); diff --git a/lib/roles/http/compression/deflate/deflate.c b/lib/roles/http/compression/deflate/deflate.c index d09340619..8e9a1ca77 100644 --- a/lib/roles/http/compression/deflate/deflate.c +++ b/lib/roles/http/compression/deflate/deflate.c @@ -29,7 +29,7 @@ lcs_init_compression_deflate(lws_comp_ctx_t *ctx, int decomp) { int n; - ctx->is_decompression = decomp; + ctx->is_decompression = !!decomp; ctx->u.deflate = lws_malloc(sizeof(*ctx->u.deflate), __func__); if (!ctx->u.deflate) @@ -63,10 +63,10 @@ lcs_process_deflate(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, int n; ctx->u.deflate->next_in = (void *)in; - ctx->u.deflate->avail_in = *ilen_iused; + ctx->u.deflate->avail_in = (unsigned int)*ilen_iused; ctx->u.deflate->next_out = out; - ctx->u.deflate->avail_out = *olen_oused; + ctx->u.deflate->avail_out = (unsigned int)*olen_oused; if (!ctx->is_decompression) n = deflate(ctx->u.deflate, Z_SYNC_FLUSH); diff --git a/lib/roles/http/compression/stream.c b/lib/roles/http/compression/stream.c index 824bca712..fcc40d3c6 100644 --- a/lib/roles/http/compression/stream.c +++ b/lib/roles/http/compression/stream.c @@ -52,7 +52,7 @@ lws_http_compression_validate(struct lws *wsi) for (n = 0; n < LWS_ARRAY_SIZE(lcs_available); n++) if (strstr(a, lcs_available[n]->encoding_name)) - wsi->http.comp_accept_mask |= 1 << n; + wsi->http.comp_accept_mask |= (uint8_t)(1 << n); return 0; } @@ -91,11 +91,11 @@ lws_http_compression_apply(struct lws *wsi, const char *name, wsi->http.comp_ctx.may_have_more = 0; wsi->http.comp_ctx.final_on_input_side = 0; wsi->http.comp_ctx.chunking = 0; - wsi->http.comp_ctx.is_decompression = decomp; + wsi->http.comp_ctx.is_decompression = !!decomp; if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING, (unsigned char *)lcs_available[n]->encoding_name, - strlen(lcs_available[n]->encoding_name), p, end)) + (int)strlen(lcs_available[n]->encoding_name), p, end)) return -1; lwsl_info("%s: %s: applied %s content-encoding\n", __func__, @@ -151,7 +151,7 @@ lws_http_compression_transform(struct lws *wsi, unsigned char *buf, * to a non-final for now. */ ctx->final_on_input_side = 1; - *wp = LWS_WRITE_HTTP | ((*wp) & ~0x1f); + *wp = (unsigned int)(LWS_WRITE_HTTP | ((*wp) & ~0x1fu)); } if (ctx->buflist_comp) { @@ -190,7 +190,8 @@ lws_http_compression_transform(struct lws *wsi, unsigned char *buf, } if (!ctx->may_have_more && ctx->final_on_input_side) - *wp = LWS_WRITE_HTTP_FINAL | ((*wp) & ~0x1f); + + *wp = (unsigned int)(LWS_WRITE_HTTP_FINAL | ((*wp) & ~0x1fu)); lwsl_debug("%s: %s: more %d, ilen_iused %d\n", __func__, lws_wsi_tag(wsi), ctx->may_have_more, (int)ilen_iused); diff --git a/lib/roles/http/date.c b/lib/roles/http/date.c index 2a2050ad1..5928d8cac 100644 --- a/lib/roles/http/date.c +++ b/lib/roles/http/date.c @@ -142,7 +142,7 @@ lws_http_date_parse_unix(const char *b, size_t len, time_t *t) int lws_http_check_retry_after(struct lws *wsi, lws_usec_t *us_interval_in_out) { - size_t len = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_RETRY_AFTER); + size_t len = (unsigned int)lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_RETRY_AFTER); char *p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_RETRY_AFTER); lws_usec_t u; time_t t, td; @@ -173,7 +173,7 @@ lws_http_check_retry_after(struct lws *wsi, lws_usec_t *us_interval_in_out) */ time(&td); - len = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_DATE); + len = (unsigned int)lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_DATE); if (len) { p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_DATE); /* if this fails, it leaves td as client time */ diff --git a/lib/roles/http/header.c b/lib/roles/http/header.c index 1d55abcc3..72d3d6693 100644 --- a/lib/roles/http/header.c +++ b/lib/roles/http/header.c @@ -73,7 +73,7 @@ lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name, if (*p + length + 3 >= end) return 1; - memcpy(*p, value, length); + memcpy(*p, value, (unsigned int)length); *p += length; *((*p)++) = '\x0d'; *((*p)++) = '\x0a'; @@ -114,7 +114,7 @@ lws_finalize_write_http_header(struct lws *wsi, unsigned char *start, #if defined(LWS_WITH_DETAILED_LATENCY) wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); #endif - if (lws_write(wsi, start, len, LWS_WRITE_HTTP_HEADERS) != len) + if (lws_write(wsi, start, (unsigned int)len, LWS_WRITE_HTTP_HEADERS) != len) return 1; return 0; @@ -232,7 +232,7 @@ lws_add_http_common_headers(struct lws *wsi, unsigned int code, (int)strlen(ka[t]), p, end)) return 1; - wsi->http.conn_type = types[t]; + wsi->http.conn_type = (enum http_conn_type)types[t]; } } @@ -303,7 +303,7 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code, int n; #ifdef LWS_WITH_ACCESS_LOG - wsi->http.access_log.response = code; + wsi->http.access_log.response = (int)code; #endif #ifdef LWS_WITH_HTTP2 @@ -471,7 +471,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code, #if defined(LWS_WITH_DETAILED_LATENCY) wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); #endif - m = lws_write(wsi, start, lws_ptr_diff(p, start), + m = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS); if (m != lws_ptr_diff(p, start)) return 1; @@ -480,10 +480,10 @@ lws_return_http_status(struct lws *wsi, unsigned int code, * ... but stash the body and send it as a priority next * handle_POLLOUT */ - wsi->http.tx_content_length = len; - wsi->http.tx_content_remain = len; + wsi->http.tx_content_length = (unsigned int)len; + wsi->http.tx_content_remain = (unsigned int)len; - wsi->h2.pending_status_body = lws_malloc(len + LWS_PRE + 1, + wsi->h2.pending_status_body = lws_malloc((unsigned int)len + LWS_PRE + 1, "pending status body"); if (!wsi->h2.pending_status_body) return -1; @@ -501,8 +501,8 @@ lws_return_http_status(struct lws *wsi, unsigned int code, */ n = lws_ptr_diff(p, start) + len; - memcpy(p, body, len); - m = lws_write(wsi, start, n, LWS_WRITE_HTTP); + memcpy(p, body, (unsigned int)len); + m = lws_write(wsi, start, (unsigned int)n, LWS_WRITE_HTTP); if (m != n) return 1; } @@ -516,7 +516,7 @@ lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len, { unsigned char *start = *p; - if (lws_add_http_header_status(wsi, code, p, end)) + if (lws_add_http_header_status(wsi, (unsigned int)code, p, end)) return -1; if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_LOCATION, loc, len, @@ -538,8 +538,8 @@ lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len, if (lws_finalize_http_header(wsi, p, end)) return -1; - return lws_write(wsi, start, *p - start, LWS_WRITE_HTTP_HEADERS | - LWS_WRITE_H2_STREAM_END); + return lws_write(wsi, start, lws_ptr_diff_size_t(*p, start), + LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); } #endif @@ -614,19 +614,19 @@ lws_sul_http_ah_lifecheck(lws_sorted_usec_list_t *sul) buf[0] = '\0'; m = 0; do { - c = lws_token_to_string(m); + c = lws_token_to_string((enum lws_token_indexes)m); if (!c) break; if (!(*c)) break; - len = lws_hdr_total_length(wsi, m); + len = lws_hdr_total_length(wsi, (enum lws_token_indexes)m); if (!len || len > (int)sizeof(buf) - 1) { m++; continue; } - if (lws_hdr_copy(wsi, buf, sizeof buf, m) > 0) { + if (lws_hdr_copy(wsi, buf, sizeof buf, (enum lws_token_indexes)m) > 0) { buf[sizeof(buf) - 1] = '\0'; lwsl_notice(" %s = %s\n", diff --git a/lib/roles/http/parsers.c b/lib/roles/http/parsers.c index ecf2f373a..8a074010c 100644 --- a/lib/roles/http/parsers.c +++ b/lib/roles/http/parsers.c @@ -234,7 +234,7 @@ lws_header_table_attach(struct lws *wsi, int autoservice) goto reset; } - n = pt->http.ah_count_in_use == context->max_http_header_pool; + n = pt->http.ah_count_in_use == (int)context->max_http_header_pool; #if defined(LWS_WITH_PEER_LIMITS) if (!n) { n = lws_peer_confirm_ah_attach_ok(context, wsi->peer); @@ -594,7 +594,7 @@ lws_hdr_custom_length(struct lws *wsi, const char *name, int nlen) return -1; if (nlen == lws_ser_ru16be( (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) && - !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) + !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], (unsigned int)nlen)) return lws_ser_ru16be( (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]); @@ -622,12 +622,12 @@ lws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name, return -1; if (nlen == lws_ser_ru16be( (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) && - !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) { + !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], (unsigned int)nlen)) { n = lws_ser_ru16be( (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]); if (n + 1 > len) return -1; - strncpy(dst, &wsi->http.ah->data[ll + UHO_NAME + nlen], n); + strncpy(dst, &wsi->http.ah->data[ll + UHO_NAME + (unsigned int)nlen], (unsigned int)n); dst[n] = '\0'; return n; @@ -663,7 +663,7 @@ lws_pos_in_bounds(struct lws *wsi) (unsigned int)wsi->a.context->max_http_header_data) return 0; - if ((int)wsi->http.ah->pos >= wsi->a.context->max_http_header_data - 1) { + if ((int)wsi->http.ah->pos >= (int)wsi->a.context->max_http_header_data - 1) { lwsl_err("Ran out of header data space\n"); return 1; } @@ -732,7 +732,7 @@ issue_char(struct lws *wsi, unsigned char c) */ if (!wsi->http.ah->current_token_limit || frag_len < wsi->http.ah->current_token_limit) { - wsi->http.ah->data[wsi->http.ah->pos++] = c; + wsi->http.ah->data[wsi->http.ah->pos++] = (char)c; if (c) wsi->http.ah->frags[wsi->http.ah->nfrag].len++; return 0; @@ -773,21 +773,21 @@ lws_parse_urldecode(struct lws *wsi, uint8_t *_c) } break; case URIES_SEEN_PERCENT: - if (char_to_hex(c) < 0) + if (char_to_hex((char)c) < 0) /* illegal post-% char */ goto forbid; - ah->esc_stash = c; + ah->esc_stash = (char)c; ah->ues = URIES_SEEN_PERCENT_H1; goto swallow; case URIES_SEEN_PERCENT_H1: - if (char_to_hex(c) < 0) + if (char_to_hex((char)c) < 0) /* illegal post-% char */ goto forbid; - *_c = (char_to_hex(ah->esc_stash) << 4) | - char_to_hex(c); + *_c = (uint8_t)(unsigned int)((char_to_hex(ah->esc_stash) << 4) | + char_to_hex((char)c)); c = *_c; enc = 1; ah->ues = URIES_IDLE; @@ -812,7 +812,7 @@ lws_parse_urldecode(struct lws *wsi, uint8_t *_c) if (issue_char(wsi, '\0') < 0) return -1; /* link to next fragment */ - ah->frags[ah->nfrag].nfrag = ah->nfrag + 1; + ah->frags[ah->nfrag].nfrag = (uint8_t)(ah->nfrag + 1); ah->nfrag++; if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags)) goto excessive; @@ -981,7 +981,7 @@ lws_parse(struct lws *wsi, unsigned char *buf, int *len) break; if (c == '\n') { lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos + 2], - ah->pos - ah->unk_value_pos); + (uint16_t)(ah->pos - ah->unk_value_pos)); ah->parser_state = WSI_TOKEN_NAME_PART; ah->unk_pos = 0; ah->lextable_pos = 0; @@ -995,7 +995,7 @@ lws_parse(struct lws *wsi, unsigned char *buf, int *len) if (lws_pos_in_bounds(wsi)) return LPR_FAIL; - ah->data[ah->pos++] = c; + ah->data[ah->pos++] = (char)c; } pos = ah->lextable_pos; break; @@ -1073,7 +1073,8 @@ check_eol: if (c == '\x0a') { /* broken peer */ ah->parser_state = WSI_TOKEN_NAME_PART; - ah->unk_pos = ah->lextable_pos = 0; + ah->unk_pos = 0; + ah->lextable_pos = 0; } else ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; @@ -1081,7 +1082,7 @@ check_eol: lwsl_parser("*\n"); } - n = issue_char(wsi, c); + n = (unsigned int)issue_char(wsi, c); if ((int)n < 0) return LPR_FAIL; if (n > 0) @@ -1107,7 +1108,7 @@ swallow: goto set_parsing_complete; if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c = (unsigned char)(c + 'a' - 'A'); /* * ...in case it's an unknown header, speculatively * store it as the name comes in. If we recognize it as @@ -1134,7 +1135,7 @@ swallow: if (lws_pos_in_bounds(wsi)) return LPR_FAIL; - ah->data[ah->pos++] = c; + ah->data[ah->pos++] = (char)c; pos = ah->lextable_pos; #if defined(LWS_WITH_CUSTOM_HEADERS) @@ -1161,7 +1162,7 @@ swallow: ah->unk_ll_tail = ah->unk_pos; #if defined(_DEBUG) - uhlen = ah->pos - (ah->unk_pos + UHO_NAME); + uhlen = (int)(ah->pos - (ah->unk_pos + UHO_NAME)); lws_strnncpy(dotstar, &ah->data[ah->unk_pos + UHO_NAME], uhlen, sizeof(dotstar)); @@ -1174,7 +1175,7 @@ swallow: /* set the unknown header name part length */ lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos], - (ah->pos - ah->unk_pos) - UHO_NAME); + (uint16_t)((ah->pos - ah->unk_pos) - UHO_NAME)); ah->unk_value_pos = ah->pos; @@ -1202,7 +1203,7 @@ nope: if (lextable_h1[pos] == FAIL_CHAR) goto nope; - ah->lextable_pos = pos; + ah->lextable_pos = (int16_t)pos; break; } @@ -1222,14 +1223,14 @@ nope: ah->unk_pos = 0; } - ah->lextable_pos = pos; + ah->lextable_pos = (int16_t)pos; break; } if (lextable_h1[pos] == c) { /* goto */ - ah->lextable_pos = pos + + ah->lextable_pos = (int16_t)(pos + (lextable_h1[pos + 1]) + - (lextable_h1[pos + 2] << 8); + (lextable_h1[pos + 2] << 8)); break; } @@ -1343,7 +1344,7 @@ nope: n = WSI_TOKEN_ORIGIN; #endif - ah->parser_state = (enum lws_token_indexes) + ah->parser_state = (uint8_t) (WSI_TOKEN_GET_URI + n); ah->ups = URIPS_IDLE; @@ -1405,7 +1406,8 @@ excessive: if (c == '\x0a') { /* broken peer */ ah->parser_state = WSI_TOKEN_NAME_PART; - ah->unk_pos = ah->lextable_pos = 0; + ah->unk_pos = 0; + ah->lextable_pos = 0; } if (c == '\x0d') @@ -1418,7 +1420,8 @@ excessive: goto forbid; if (c == '\x0a') { ah->parser_state = WSI_TOKEN_NAME_PART; - ah->unk_pos = ah->lextable_pos = 0; + ah->unk_pos = 0; + ah->lextable_pos = 0; } else ah->parser_state = WSI_TOKEN_SKIPPING; break; @@ -1441,7 +1444,7 @@ set_parsing_complete: #if defined(LWS_ROLE_WS) const char *pv = lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION); if (pv) - wsi->rx_frame_type = atoi(pv); + wsi->rx_frame_type = (char)atoi(pv); lwsl_parser("v%02d hdrs done\n", wsi->rx_frame_type); #endif @@ -1479,7 +1482,7 @@ lws_http_cookie_get(struct lws *wsi, const char *name, char *buf, p += bl; n -= bl; while (n-- > bl) { - if (*p == '=' && !memcmp(p - bl, name, bl)) { + if (*p == '=' && !memcmp(p - bl, name, (unsigned int)bl)) { p++; while (*p != ';' && n-- && max) { *buf++ = *p++; @@ -1489,7 +1492,7 @@ lws_http_cookie_get(struct lws *wsi, const char *name, char *buf, return 2; *buf = '\0'; - *max_len = lws_ptr_diff(buf, bo); + *max_len = lws_ptr_diff_size_t(buf, bo); return 0; } diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index 9a29ae955..9623d6f2b 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -60,7 +60,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met if (wsi->access_log_pending) lws_access_log(wsi); - wsi->http.access_log.header_log = lws_malloc(l, "access log"); + wsi->http.access_log.header_log = lws_malloc((unsigned int)l, "access log"); if (!wsi->http.access_log.header_log) return; @@ -84,7 +84,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met if (m > (int)sizeof(uri) - 1) m = sizeof(uri) - 1; - strncpy(uri, uri_ptr, m); + strncpy(uri, uri_ptr, (unsigned int)m); uri[m] = '\0'; nwsi = lws_get_network_wsi(wsi); @@ -94,7 +94,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met else strncpy(ta, "unknown", sizeof(ta)); - lws_snprintf(wsi->http.access_log.header_log, l, + lws_snprintf(wsi->http.access_log.header_log, (size_t)l, "%s - - [%s] \"%s %s %s\"", ta, da, me, uri, hver[wsi->http.request_version]); @@ -103,7 +103,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT); if (l) { wsi->http.access_log.user_agent = - lws_malloc(l + 5, "access log"); + lws_malloc((unsigned int)l + 5, "access log"); if (!wsi->http.access_log.user_agent) { lwsl_err("OOM getting user agent\n"); lws_free_set_NULL(wsi->http.access_log.header_log); @@ -119,7 +119,7 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int met } l = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER); if (l) { - wsi->http.access_log.referrer = lws_malloc(l + 5, "referrer"); + wsi->http.access_log.referrer = lws_malloc((unsigned int)l + 5, "referrer"); if (!wsi->http.access_log.referrer) { lwsl_err("OOM getting referrer\n"); lws_free_set_NULL(wsi->http.access_log.user_agent); @@ -172,15 +172,15 @@ lws_access_log(struct lws *wsi) wsi->http.access_log.header_log, wsi->http.access_log.response, wsi->http.access_log.sent, p1); - if (strlen(p) > sizeof(ass) - 6 - l) { - p[sizeof(ass) - 6 - l] = '\0'; + if (strlen(p) > sizeof(ass) - 6 - (unsigned int)l) { + p[sizeof(ass) - 6 - (unsigned int)l] = '\0'; l--; } - l += lws_snprintf(ass + l, sizeof(ass) - 1 - l, "\" \"%s\"\n", p); + l += lws_snprintf(ass + (unsigned int)l, sizeof(ass) - 1 - (unsigned int)l, "\" \"%s\"\n", p); ass[sizeof(ass) - 1] = '\0'; - if (write(wsi->a.vhost->log_fd, ass, l) != l) + if ((int)write(wsi->a.vhost->log_fd, ass, (size_t)l) != l) lwsl_err("Failed to write log\n"); if (wsi->http.access_log.header_log) { diff --git a/lib/roles/http/server/fops-zip.c b/lib/roles/http/server/fops-zip.c index 015563b05..832dcfc1d 100644 --- a/lib/roles/http/server/fops-zip.c +++ b/lib/roles/http/server/fops-zip.c @@ -234,7 +234,7 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len) return LWS_FZ_ERR_NAME_TOO_LONG; if (priv->zip_fop_fd->fops->LWS_FOP_READ(priv->zip_fop_fd, - &amount, buf, len)) + &amount, buf, (unsigned int)len)) return LWS_FZ_ERR_NAME_READ; if ((int)amount != len) return LWS_FZ_ERR_NAME_READ; @@ -267,7 +267,7 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len) return LWS_FZ_ERR_CONTENT_SANITY; if (lws_vfs_file_seek_set(priv->zip_fop_fd, - priv->content_start) < 0) + (lws_fileofs_t)priv->content_start) < 0) return LWS_FZ_ERR_CONTENT_SEEK; /* we are aligned at the start of the content */ @@ -278,11 +278,11 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len) next: if (i && lws_vfs_file_seek_set(priv->zip_fop_fd, - priv->content_start + - ZC_DIRECTORY_LENGTH + + (lws_fileofs_t)priv->content_start + + (ZC_DIRECTORY_LENGTH + priv->hdr.filename_len + priv->hdr.extra + - priv->hdr.file_com_len) < 0) + priv->hdr.file_com_len)) < 0) return LWS_FZ_ERR_SCAN_SEEK; } @@ -306,7 +306,7 @@ lws_fops_zip_reset_inflate(lws_fops_zip_t priv) return LWS_FZ_ERR_ZLIB_INIT; } - if (lws_vfs_file_seek_set(priv->zip_fop_fd, priv->content_start) < 0) + if (lws_vfs_file_seek_set(priv->zip_fop_fd, (lws_fileofs_t)priv->content_start) < 0) return LWS_FZ_ERR_CONTENT_SEEK; priv->exp_uncomp_pos = 0; @@ -338,7 +338,7 @@ lws_fops_zip_open(const struct lws_plat_file_ops *fops, const char *vfs_path, m = sizeof(rp) - 1; if ((vpath - vfs_path - 1) < m) m = lws_ptr_diff(vpath, vfs_path) - 1; - lws_strncpy(rp, vfs_path, m + 1); + lws_strncpy(rp, vfs_path, (unsigned int)m + 1); /* open the zip file itself using the incoming fops, not fops_zip */ @@ -488,9 +488,9 @@ lws_fops_zip_close(lws_fop_fd_t *fd) static lws_fileofs_t lws_fops_zip_seek_cur(lws_fop_fd_t fd, lws_fileofs_t offset_from_cur_pos) { - fd->pos += offset_from_cur_pos; + fd->pos = (lws_filepos_t)((lws_fileofs_t)fd->pos + offset_from_cur_pos); - return fd->pos; + return (lws_fileofs_t)fd->pos; } static int diff --git a/lib/roles/http/server/lejp-conf.c b/lib/roles/http/server/lejp-conf.c index 6db7afc1f..6970c19b5 100644 --- a/lib/roles/http/server/lejp-conf.c +++ b/lib/roles/http/server/lejp-conf.c @@ -297,10 +297,10 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason) switch (ctx->path_match - 1) { case LEJPGP_UID: - a->info->uid = atoi(ctx->buf); + a->info->uid = (unsigned int)atoi(ctx->buf); return 0; case LEJPGP_GID: - a->info->gid = atoi(ctx->buf); + a->info->gid = (unsigned int)atoi(ctx->buf); return 0; case LEJPGP_USERNAME: a->info->username = a->p; @@ -309,7 +309,7 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason) a->info->groupname = a->p; break; case LEJPGP_COUNT_THREADS: - a->info->count_threads = atoi(ctx->buf); + a->info->count_threads = (unsigned int)atoi(ctx->buf); return 0; case LWJPGP_INIT_SSL: if (arg_to_bool(ctx->buf)) @@ -332,7 +332,7 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason) return 0; case LWJPGP_TIMEOUT_SECS: - a->info->timeout_secs = atoi(ctx->buf); + a->info->timeout_secs = (unsigned int)atoi(ctx->buf); return 0; #if defined(LWS_WITH_TLS) @@ -343,11 +343,11 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason) #if defined(LWS_WITH_PEER_LIMITS) case LWJPGP_IP_LIMIT_AH: - a->info->ip_limit_ah = atoi(ctx->buf); + a->info->ip_limit_ah = (uint16_t)atoi(ctx->buf); return 0; case LWJPGP_IP_LIMIT_WSI: - a->info->ip_limit_wsi = atoi(ctx->buf); + a->info->ip_limit_wsi = (uint16_t)atoi(ctx->buf); return 0; #endif @@ -360,7 +360,7 @@ lejp_globals_cb(struct lejp_ctx *ctx, char reason) } dostring: - a->p += lws_snprintf(a->p, a->end - a->p, "%s", ctx->buf); + a->p += lws_snprintf(a->p, lws_ptr_diff_size_t(a->end, a->p), "%s", ctx->buf); *(a->p)++ = '\0'; return 0; @@ -594,7 +594,7 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) if (!strncmp(a->m.origin, mount_protocols[n], strlen(mount_protocols[n]))) { lwsl_info("----%s\n", a->m.origin); - m->origin_protocol = n; + m->origin_protocol = (uint8_t)(unsigned int)n; m->origin = a->m.origin + strlen(mount_protocols[n]); break; @@ -629,18 +629,18 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) break; case LEJPVP_UNIXSKT: if (arg_to_bool(ctx->buf)) - a->info->options |= LWS_SERVER_OPTION_UNIX_SOCK; + a->info->options |= (uint64_t)LWS_SERVER_OPTION_UNIX_SOCK; else - a->info->options &= ~(LWS_SERVER_OPTION_UNIX_SOCK); + a->info->options &= (uint64_t)~(LWS_SERVER_OPTION_UNIX_SOCK); return 0; case LEJPVP_UNIXSKT_PERMS: a->info->unix_socket_perms = a->p; break; case LEJPVP_STS: if (arg_to_bool(ctx->buf)) - a->info->options |= LWS_SERVER_OPTION_STS; + a->info->options |= (uint64_t)LWS_SERVER_OPTION_STS; else - a->info->options &= ~(LWS_SERVER_OPTION_STS); + a->info->options &= (uint64_t)~(LWS_SERVER_OPTION_STS); return 0; #if defined(LWS_WITH_TLS) case LEJPVP_HOST_SSL_KEY: @@ -671,19 +671,19 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) a->m.def = a->p; break; case LEJPVP_DEFAULT_AUTH_MASK: - a->m.auth_mask = atoi(ctx->buf); + a->m.auth_mask = (unsigned int)atoi(ctx->buf); return 0; case LEJPVP_MOUNT_CACHE_MAX_AGE: a->m.cache_max_age = atoi(ctx->buf); return 0; case LEJPVP_MOUNT_CACHE_REUSE: - a->m.cache_reusable = arg_to_bool(ctx->buf); + a->m.cache_reusable = !!arg_to_bool(ctx->buf); return 0; case LEJPVP_MOUNT_CACHE_REVALIDATE: - a->m.cache_revalidate = arg_to_bool(ctx->buf); + a->m.cache_revalidate = !!arg_to_bool(ctx->buf); return 0; case LEJPVP_MOUNT_CACHE_INTERMEDIARIES: - a->m.cache_intermediaries = arg_to_bool(ctx->buf);; + a->m.cache_intermediaries = !!arg_to_bool(ctx->buf);; return 0; case LEJPVP_MOUNT_BASIC_AUTH: #if defined(LWS_WITH_HTTP_BASIC_AUTH) @@ -783,7 +783,7 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) break; case LEJPVP_ENABLE_CLIENT_SSL: - a->enable_client_ssl = arg_to_bool(ctx->buf); + a->enable_client_ssl = !!arg_to_bool(ctx->buf); return 0; #if defined(LWS_WITH_TLS) && defined(LWS_WITH_CLIENT) case LEJPVP_CLIENT_SSL_KEY: @@ -906,14 +906,14 @@ dostring: n = lws_ptr_diff(p1, p); if (n > a->end - a->p) n = lws_ptr_diff(a->end, a->p); - lws_strncpy(a->p, p, n + 1); + lws_strncpy(a->p, p, (unsigned int)n + 1u); a->p += n; - a->p += lws_snprintf(a->p, a->end - a->p, "%s", + a->p += lws_snprintf(a->p, lws_ptr_diff_size_t(a->end, a->p), "%s", LWS_INSTALL_DATADIR); - p += n + strlen(ESC_INSTALL_DATADIR); + p += n + (int)strlen(ESC_INSTALL_DATADIR); } - a->p += lws_snprintf(a->p, a->end - a->p, "%s", p); + a->p += lws_snprintf(a->p, lws_ptr_diff_size_t(a->end, a->p), "%s", p); if (reason == LEJPCB_VAL_STR_END) *(a->p)++ = '\0'; @@ -938,10 +938,10 @@ lwsws_get_config(void *user, const char *f, const char * const *paths, return 2; } lwsl_info("%s: %s\n", __func__, f); - lejp_construct(&ctx, cb, user, paths, count_paths); + lejp_construct(&ctx, cb, user, paths, (uint8_t)(unsigned int)count_paths); do { - n = read(fd, buf, sizeof(buf)); + n = (int)read(fd, buf, sizeof(buf)); if (!n) break; @@ -949,7 +949,7 @@ lwsws_get_config(void *user, const char *f, const char * const *paths, } while (m == LEJP_CONTINUE); close(fd); - n = ctx.line; + n = (int32_t)ctx.line; lejp_destruct(&ctx); if (m < 0) { diff --git a/lib/roles/http/server/lws-spa.c b/lib/roles/http/server/lws-spa.c index ef85f69f7..18325ab19 100644 --- a/lib/roles/http/server/lws-spa.c +++ b/lib/roles/http/server/lws-spa.c @@ -193,7 +193,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, continue; } if (s->pos >= (int)sizeof(s->name) - 1) { - lwsl_hexdump_notice(s->name, s->pos); + lwsl_hexdump_notice(s->name, (size_t)s->pos); lwsl_notice("Name too long...\n"); return -1; } @@ -238,7 +238,7 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, return -1; in++; - s->out[s->pos++] = s->sum | n; + s->out[s->pos++] = (char)(s->sum | n); s->state = US_IDLE; break; @@ -275,7 +275,8 @@ retry_as_first: n = 2; if (s->mp >= n) { memcpy(s->out + s->pos, - s->mime_boundary + n, s->mp - n); + s->mime_boundary + n, + (unsigned int)(s->mp - n)); s->pos += s->mp; s->mp = 0; goto retry_as_first; @@ -290,7 +291,7 @@ retry_as_first: case MT_HNAME: c =*in; if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c = (char)(c + 'a' - 'A'); if (!s->mp) /* initially, any of them might match */ s->matchable = (1 << LWS_ARRAY_SIZE(mp_hdrs)) - 1; @@ -304,13 +305,13 @@ retry_as_first: if (s->mp >= mp_hdrs[n].hdr_len) { /* he went past the end of it */ - s->matchable &= ~(1 << n); + s->matchable &= (uint8_t)~(1 << n); continue; } if (c != mp_hdrs[n].hdr[s->mp]) { /* mismatched a char */ - s->matchable &= ~(1 << n); + s->matchable &= (uint8_t)~(1 << n); continue; } @@ -342,7 +343,7 @@ retry_as_first: if (hit == 2) s->state = MT_LOOK_BOUND_IN; else - s->state += hit + 1; + s->state += (unsigned int)hit + 1u; break; case MT_DISP: @@ -503,7 +504,7 @@ lws_urldecode_spa_cb(struct lws_spa *spa, const char *name, char **buf, int len, if (spa->i.opt_cb) { n = spa->i.opt_cb(spa->i.opt_data, name, spa->s->content_disp_filename, - buf ? *buf : NULL, len, final); + buf ? *buf : NULL, len, (enum lws_spa_fileupload_states)final); if (n < 0) return -1; @@ -529,12 +530,12 @@ lws_urldecode_spa_cb(struct lws_spa *spa, const char *name, char **buf, int len, spa->s->out_len -= len + 1; } else { - spa->params[n] = lwsac_use(spa->i.ac, len + 1, + spa->params[n] = lwsac_use(spa->i.ac, (unsigned int)len + 1, spa->i.ac_chunk_size); if (!spa->params[n]) return -1; - memcpy(spa->params[n], *buf, len); + memcpy(spa->params[n], *buf, (unsigned int)len); spa->params[n][len] = '\0'; } @@ -561,10 +562,10 @@ lws_spa_create_via_info(struct lws *wsi, const lws_spa_create_info_t *i) spa->i.max_storage = 512; if (i->ac) - spa->storage = lwsac_use(i->ac, spa->i.max_storage, + spa->storage = lwsac_use(i->ac, (unsigned int)spa->i.max_storage, i->ac_chunk_size); else - spa->storage = lws_malloc(spa->i.max_storage, "spa"); + spa->storage = lws_malloc((unsigned int)spa->i.max_storage, "spa"); if (!spa->storage) goto bail2; @@ -574,9 +575,9 @@ lws_spa_create_via_info(struct lws *wsi, const lws_spa_create_info_t *i) if (i->count_params) { if (i->ac) spa->params = lwsac_use_zero(i->ac, - sizeof(char *) * i->count_params, i->ac_chunk_size); + sizeof(char *) * (unsigned int)i->count_params, i->ac_chunk_size); else - spa->params = lws_zalloc(sizeof(char *) * i->count_params, + spa->params = lws_zalloc(sizeof(char *) * (unsigned int)i->count_params, "spa params"); if (!spa->params) goto bail3; @@ -590,9 +591,9 @@ lws_spa_create_via_info(struct lws *wsi, const lws_spa_create_info_t *i) if (i->count_params) { if (i->ac) spa->param_length = lwsac_use_zero(i->ac, - sizeof(int) * i->count_params, i->ac_chunk_size); + sizeof(int) * (unsigned int)i->count_params, i->ac_chunk_size); else - spa->param_length = lws_zalloc(sizeof(int) * i->count_params, + spa->param_length = lws_zalloc(sizeof(int) * (unsigned int)i->count_params, "spa param len"); if (!spa->param_length) goto bail5; diff --git a/lib/roles/http/server/ranges.c b/lib/roles/http/server/ranges.c index e1adddbd4..15026b580 100644 --- a/lib/roles/http/server/ranges.c +++ b/lib/roles/http/server/ranges.c @@ -111,7 +111,7 @@ lws_ranges_next(struct lws_range_parsing *rp) rp->state = LWSRS_SYNTAX; return 0; } - rp->start = (rp->start * 10) + (c - '0'); + rp->start = (unsigned long long)(((unsigned long long)rp->start * 10) + (unsigned long long)(c - '0')); rp->start_valid = 1; break; @@ -153,7 +153,7 @@ lws_ranges_next(struct lws_range_parsing *rp) rp->state = LWSRS_SYNTAX; return 0; } - rp->end = (rp->end * 10) + (c - '0'); + rp->end = (unsigned long long)(((unsigned long long)rp->end * 10) + (unsigned long long)(c - '0')); rp->end_valid = 1; break; } diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index edd0d3dae..93679bcb0 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -369,7 +369,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) while (vhost) { if (port == vhost->listen_port && - !strncmp(vhost->name, servername, colon)) { + !strncmp(vhost->name, servername, (unsigned int)colon)) { lwsl_info("SNI: Found: %s\n", servername); return vhost; } @@ -389,7 +389,7 @@ lws_select_vhost(struct lws_context *context, int port, const char *servername) if (port && port == vhost->listen_port && m <= (colon - 2) && servername[colon - m - 1] == '.' && - !strncmp(vhost->name, servername + colon - m, m)) { + !strncmp(vhost->name, servername + colon - m, (unsigned int)m)) { lwsl_info("SNI: Found %s on wildcard: %s\n", servername, vhost->name); return vhost; @@ -590,7 +590,7 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, #if !defined(WIN32) && !defined(LWS_PLAT_FREERTOS) if ((S_IFMT & st.st_mode) == S_IFLNK) { - len = readlink(path, sym, sizeof(sym) - 1); + len = (size_t)readlink(path, sym, sizeof(sym) - 1); if (len) { lwsl_err("Failed to read link %s\n", path); goto notfound; @@ -675,10 +675,10 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, if (lws_finalize_http_header(wsi, &p, end)) return -1; - n = lws_write(wsi, start, p - start, + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); - if (n != (p - start)) { + if (n != lws_ptr_diff(p, start)) { lwsl_err("_write returned %d from %ld\n", n, (long)(p - start)); return -1; @@ -721,7 +721,7 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin, while (pvo) { n = (int)strlen(path); if (n > (int)strlen(pvo->name) && - !strcmp(&path[n - strlen(pvo->name)], pvo->name)) { + !strcmp(&path[(unsigned int)n - strlen(pvo->name)], pvo->name)) { wsi->interpreting = 1; if (!wsi->mux_substream) wsi->sending_chunked = 1; @@ -839,7 +839,7 @@ lws_find_string_in_file(const char *filename, const char *string, int stringlen) while (1) { if (pos == n) { - n = read(fd, buf, sizeof(buf)); + n = (int)read(fd, buf, sizeof(buf)); if (n <= 0) { if (match == stringlen) hit = 1; @@ -898,7 +898,7 @@ lws_unauthorised_basic_auth(struct lws *wsi) if (lws_finalize_http_header(wsi, &p, end)) return -1; - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS | + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); if (n < 0) return -1; @@ -1051,7 +1051,7 @@ lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, case LWSAUTHM_BASIC_AUTH_CALLBACK: bar = wsi->a.protocol->callback(wsi, LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION, - wsi->user_space, plain, m); + wsi->user_space, plain, (unsigned int)m); if (!bar) return LCBA_FAILED_AUTH; break; @@ -1066,9 +1066,9 @@ lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, */ *pcolon = '\0'; - wsi->http.ah->frags[fi].len = lws_ptr_diff(pcolon, plain); + wsi->http.ah->frags[fi].len = (uint16_t)lws_ptr_diff_size_t(pcolon, &plain[0]); pcolon = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_AUTHORIZATION); - strncpy(pcolon, plain, ml - 1); + strncpy(pcolon, plain, (unsigned int)(ml - 1)); pcolon[ml - 1] = '\0'; lwsl_info("%s: basic auth accepted for %s\n", __func__, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_AUTHORIZATION)); @@ -1149,7 +1149,7 @@ lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit, n = sizeof(ads) - 2; } - memcpy(ads, hit->origin, n); + memcpy(ads, hit->origin, (unsigned int)n); ads[n] = '\0'; i.address = ads; @@ -1456,7 +1456,7 @@ lws_http_action(struct lws *wsi) sizeof(content_length_str) - 1, WSI_TOKEN_HTTP_CONTENT_LENGTH) > 0) { wsi->http.rx_content_remain = wsi->http.rx_content_length = - atoll(content_length_str); + (lws_filepos_t)atoll(content_length_str); if (!wsi->http.rx_content_length) { wsi->http.content_length_explicitly_zero = 1; lwsl_debug("%s: explicit 0 content-length\n", __func__); @@ -1500,8 +1500,8 @@ lws_http_action(struct lws *wsi) wsi->http.conn_type = conn_type; } - n = wsi->a.protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION, - wsi->user_space, uri_ptr, uri_len); + n = (unsigned int)wsi->a.protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION, + wsi->user_space, uri_ptr, (unsigned int)uri_len); if (n) { lwsl_info("LWS_CALLBACK_HTTP closing\n"); @@ -1513,7 +1513,7 @@ lws_http_action(struct lws *wsi) */ if (!wsi->mux_stream_immortal) lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, - wsi->a.context->timeout_secs); + (int)wsi->a.context->timeout_secs); #if defined(LWS_WITH_TLS) if (wsi->tls.redirect_to_https) { /* @@ -1526,14 +1526,14 @@ lws_http_action(struct lws *wsi) *end = p + wsi->a.context->pt_serv_buf_size - LWS_PRE; - n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST); + n = (unsigned int)lws_hdr_total_length(wsi, WSI_TOKEN_HOST); if (!n || n > 128) goto bail_nuke_ah; if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)) goto bail_nuke_ah; - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), "https://"); + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "https://"); memcpy(p, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), n); p += n; *p++ = '/'; @@ -1542,13 +1542,13 @@ lws_http_action(struct lws *wsi) if (uri_ptr[0]) p--; - memcpy(p, uri_ptr, uri_len); + memcpy(p, uri_ptr, (unsigned int)uri_len); p += uri_len; n = 0; while (lws_hdr_copy_fragment(wsi, (char *)p + 1, lws_ptr_diff(end, p) - 2, - WSI_TOKEN_HTTP_URI_ARGS, n) > 0) { + WSI_TOKEN_HTTP_URI_ARGS, (int)n) > 0) { *p = n ? '&' : '?'; p += strlen((char *)p); if (p >= end - 2) @@ -1556,11 +1556,11 @@ lws_http_action(struct lws *wsi) n++; } - n = lws_ptr_diff(p, start); + n = (unsigned int)lws_ptr_diff(p, start); p += LWS_PRE; - n = lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, - start, n, &p, end); + n = (unsigned int)lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, + start, (int)n, &p, end); if ((int)n < 0) goto bail_nuke_ah; @@ -1587,7 +1587,7 @@ lws_http_action(struct lws *wsi) lwsi_set_state(wsi, LRS_DOING_TRANSACTION); m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, - wsi->user_space, uri_ptr, uri_len); + wsi->user_space, uri_ptr, (unsigned int)uri_len); goto after; } @@ -1595,9 +1595,9 @@ lws_http_action(struct lws *wsi) #if defined(LWS_WITH_FILE_OPS) s = uri_ptr + hit->mountpoint_len; #endif - n = lws_http_redirect_hit(pt, wsi, hit, uri_ptr, uri_len, &ha); + n = (unsigned int)lws_http_redirect_hit(pt, wsi, hit, uri_ptr, uri_len, &ha); if (ha) - return n; + return (int)n; #if defined(LWS_WITH_HTTP_BASIC_AUTH) @@ -1627,10 +1627,10 @@ lws_http_action(struct lws *wsi) if (hit->origin_protocol == LWSMPRO_HTTPS || hit->origin_protocol == LWSMPRO_HTTP) { - n = lws_http_proxy_start(wsi, hit, uri_ptr, 0); + n = (unsigned int)lws_http_proxy_start(wsi, hit, uri_ptr, 0); // lwsl_notice("proxy start says %d\n", n); if (n) - return n; + return (int)n; goto deal_body; } @@ -1667,7 +1667,7 @@ lws_http_action(struct lws *wsi) args.final = 0; /* used to signal callback dealt with it */ args.chunked = 0; - n = wsi->a.protocol->callback(wsi, + n = (unsigned int)wsi->a.protocol->callback(wsi, LWS_CALLBACK_CHECK_ACCESS_RIGHTS, wsi->user_space, &args, 0); if (n) { @@ -1687,7 +1687,7 @@ lws_http_action(struct lws *wsi) m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr + hit->mountpoint_len, - uri_len - hit->mountpoint_len); + (unsigned int)uri_len - hit->mountpoint_len); goto after; } } @@ -1705,9 +1705,9 @@ lws_http_action(struct lws *wsi) n = 5; if (hit->cgi_timeout) - n = hit->cgi_timeout; + n = (unsigned int)hit->cgi_timeout; - n = lws_cgi(wsi, cmd, hit->mountpoint_len, n, + n = (unsigned int)lws_cgi(wsi, cmd, hit->mountpoint_len, (int)n, hit->cgienv); if (n) { lwsl_err("%s: cgi failed\n", __func__); @@ -1719,14 +1719,14 @@ lws_http_action(struct lws *wsi) #endif #if defined(LWS_WITH_FILE_OPS) - n = uri_len - lws_ptr_diff(s, uri_ptr); + n = (unsigned int)(uri_len - lws_ptr_diff(s, uri_ptr)); if (s[0] == '\0' || (n == 1 && s[n - 1] == '/')) s = (char *)hit->def; if (!s) s = "index.html"; #endif - wsi->cache_secs = hit->cache_max_age; + wsi->cache_secs = (unsigned int)hit->cache_max_age; wsi->cache_reuse = hit->cache_reusable; wsi->cache_revalidate = hit->cache_revalidate; wsi->cache_intermediaries = hit->cache_intermediaries; @@ -1759,10 +1759,10 @@ lws_http_action(struct lws *wsi) m = pp->callback(wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr + hit->mountpoint_len, - uri_len - hit->mountpoint_len); + (size_t)(uri_len - hit->mountpoint_len)); } else m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, - wsi->user_space, uri_ptr, uri_len); + wsi->user_space, uri_ptr, (size_t)uri_len); } after: @@ -1842,7 +1842,7 @@ deal_body: break; lwsl_debug("%s: consuming %d\n", __func__, (int)ebuf.len); - m = lws_read_h1(wsi, ebuf.token, ebuf.len); + m = lws_read_h1(wsi, ebuf.token, (lws_filepos_t)ebuf.len); if (m < 0) return -1; @@ -1891,13 +1891,13 @@ lws_confirm_host_header(struct lws *wsi) lwsl_info("%s: missing or oversize host header\n", __func__); return 1; } - ts.len = n; + ts.len = (size_t)n; if (lws_tokenize(&ts) != LWS_TOKZE_TOKEN) goto bad_format; if (strncmp(ts.token, wsi->a.vhost->name, ts.token_len)) { - buf[(ts.token - buf) + ts.token_len] = '\0'; + buf[(size_t)(ts.token - buf) + ts.token_len] = '\0'; lwsl_info("%s: '%s' in host hdr but vhost name %s\n", __func__, ts.token, wsi->a.vhost->name); return 1; @@ -1971,13 +1971,13 @@ lws_http_to_fallback(struct lws *wsi, unsigned char *obuf, size_t olen) ipbuf, role ? role->name : "null", protocol->name, n, wsi->http.ah); - if ((wsi->a.protocol->callback)(wsi, n, wsi->user_space, NULL, 0)) + if ((wsi->a.protocol->callback)(wsi, (enum lws_callback_reasons)n, wsi->user_space, NULL, 0)) return 1; n = LWS_CALLBACK_RAW_RX; if (wsi->role_ops->rx_cb[lwsi_role_server(wsi)]) n = wsi->role_ops->rx_cb[lwsi_role_server(wsi)]; - if (wsi->a.protocol->callback(wsi, n, wsi->user_space, obuf, olen)) + if (wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)n, wsi->user_space, obuf, olen)) return 1; return 0; @@ -2019,7 +2019,7 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len) m = lws_parse(wsi, *buf, &i); lwsl_info("%s: parsed count %d\n", __func__, (int)len - i); (*buf) += (int)len - i; - len = i; + len = (unsigned int)i; if (m == LPR_DO_FALLBACK) { @@ -2107,7 +2107,7 @@ raw_transition: if (msg) msg++; lws_return_http_status(wsi, - atoi(rej->value), msg); + (unsigned int)atoi(rej->value), msg); #ifdef LWS_WITH_ACCESS_LOG meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); @@ -2288,14 +2288,14 @@ upgrade_h2c: lws_h2_settings(wsi, &wsi->h2.h2n->peer_set, (uint8_t *)tbuf, n); - lws_hpack_dynamic_size(wsi, wsi->h2.h2n->peer_set.s[ + lws_hpack_dynamic_size(wsi, (int)wsi->h2.h2n->peer_set.s[ H2SET_HEADER_TABLE_SIZE]); strcpy(tbuf, "HTTP/1.1 101 Switching Protocols\x0d\x0a" "Connection: Upgrade\x0d\x0a" "Upgrade: h2c\x0d\x0a\x0d\x0a"); m = (int)strlen(tbuf); - n = lws_issue_raw(wsi, (unsigned char *)tbuf, m); + n = lws_issue_raw(wsi, (unsigned char *)tbuf, (unsigned int)m); if (n != m) { lwsl_debug("http2 switch: ERROR writing to socket\n"); return 1; @@ -2452,7 +2452,7 @@ lws_http_transaction_completed(struct lws *wsi) n = NO_PENDING_TIMEOUT; if (wsi->a.vhost->keepalive_timeout) n = PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE; - lws_set_timeout(wsi, n, wsi->a.vhost->keepalive_timeout); + lws_set_timeout(wsi, (enum pending_timeout)n, wsi->a.vhost->keepalive_timeout); /* * We already know we are on http1.1 / keepalive and the next thing @@ -2599,7 +2599,7 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, n = HTTP_STATUS_PARTIAL_CONTENT; #endif - if (lws_add_http_header_status(wsi, n, &p, end)) + if (lws_add_http_header_status(wsi, (unsigned int)n, &p, end)) goto bail; if ((wsi->http.fop_fd->flags & (LWS_FOP_FLAG_COMPR_ACCEPTABLE_GZIP | @@ -2673,13 +2673,14 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, "bytes %llu-%llu/%llu", rp->start, rp->end, rp->extent); - total_content_length += + total_content_length = total_content_length + + (lws_filepos_t)( 6 /* header _lws\r\n */ + /* Content-Type: xxx/xxx\r\n */ - 14 + strlen(content_type) + 2 + + 14 + (int)strlen(content_type) + 2 + /* Content-Range: xxxx\r\n */ 15 + n + 2 + - 2; /* /r/n */ + 2); /* /r/n */ } lws_ranges_reset(rp); @@ -2783,14 +2784,14 @@ lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, if (other_headers) { if ((end - p) < other_headers_len) goto bail; - memcpy(p, other_headers, other_headers_len); + memcpy(p, other_headers, (unsigned int)other_headers_len); p += other_headers_len; } if (lws_finalize_http_header(wsi, &p, end)) goto bail; - ret = lws_write(wsi, response, p - response, LWS_WRITE_HTTP_HEADERS); + ret = lws_write(wsi, response, lws_ptr_diff_size_t(p, response), LWS_WRITE_HTTP_HEADERS); if (ret != (p - response)) { lwsl_err("_write returned %d from %ld\n", ret, (long)(p - response)); @@ -2884,8 +2885,8 @@ int lws_serve_http_file_fragment(struct lws *wsi) wsi->http.range.start); if ((long long)lws_vfs_file_seek_cur(wsi->http.fop_fd, - wsi->http.range.start - - wsi->http.filepos) < 0) + (lws_fileofs_t)wsi->http.range.start - + (lws_fileofs_t)wsi->http.filepos) < 0) goto file_had_it; wsi->http.filepos = wsi->http.range.start; @@ -2912,7 +2913,7 @@ int lws_serve_http_file_fragment(struct lws *wsi) } #endif - poss = context->pt_serv_buf_size - n - + poss = context->pt_serv_buf_size - (unsigned int)n - LWS_H2_FRAME_HEADER_LENGTH; if (wsi->http.tx_content_length) @@ -2928,7 +2929,7 @@ int lws_serve_http_file_fragment(struct lws *wsi) poss = wsi->a.protocol->tx_packet_size; if (lws_rops_fidx(wsi->role_ops, LWS_ROPS_tx_credit)) { - lws_filepos_t txc = lws_rops_func_fidx(wsi->role_ops, + lws_filepos_t txc = (unsigned int)lws_rops_func_fidx(wsi->role_ops, LWS_ROPS_tx_credit). tx_credit(wsi, LWSTXCR_US_TO_PEER, 0); @@ -2979,14 +2980,14 @@ int lws_serve_http_file_fragment(struct lws *wsi) if (n) { lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, - context->timeout_secs); + (int)context->timeout_secs); if (wsi->interpreting) { args.p = (char *)p; args.len = n; - args.max_len = (unsigned int)poss + 128; - args.final = wsi->http.filepos + n == - wsi->http.filelen; + args.max_len = (int)(unsigned int)poss + 128; + args.final = wsi->http.filepos + (unsigned int)n == + wsi->http.filelen; args.chunked = wsi->sending_chunked; if (user_callback_handle_rxflow( wsi->a.vhost->protocols[ @@ -3009,7 +3010,7 @@ int lws_serve_http_file_fragment(struct lws *wsi) lwsl_debug("added trailing boundary\n"); } #endif - m = lws_write(wsi, p, n, wsi->http.filepos + amount == + m = lws_write(wsi, p, (unsigned int)n, wsi->http.filepos + amount == wsi->http.filelen ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP); if (m < 0) @@ -3157,14 +3158,14 @@ lws_chunked_html_process(struct lws_process_html_args *args, if (s->pos == sizeof(s->swallow) - 1) goto skip; for (n = 0; n < s->count_vars; n++) - if (!strncmp(s->swallow, s->vars[n], s->pos)) { + if (!strncmp(s->swallow, s->vars[n], (unsigned int)s->pos)) { hits++; hit = n; } if (!hits) { skip: s->swallow[s->pos] = '\0'; - memcpy(s->start, s->swallow, s->pos); + memcpy(s->start, s->swallow, (unsigned int)s->pos); args->len++; s->pos = 0; sp = s->start + 1; @@ -3178,10 +3179,10 @@ skip: s->swallow[s->pos] = '\0'; if (n != s->pos) { memmove(s->start + n, s->start + s->pos, - old_len - (sp - args->p) - 1); + (unsigned int)(old_len - (sp - args->p) - 1)); old_len += (n - s->pos) + 1; } - memcpy(s->start, pc, n); + memcpy(s->start, pc, (unsigned int)n); args->len++; sp = s->start + 1; @@ -3203,7 +3204,7 @@ skip: n = sprintf(buffer, "%X\x0d\x0a", args->len); args->p -= n; - memcpy(args->p, buffer, n); + memcpy(args->p, buffer, (unsigned int)n); args->len += n; if (args->final) { diff --git a/lib/roles/listen/ops-listen.c b/lib/roles/listen/ops-listen.c index e8fdbe77b..a4bbaa3ce 100644 --- a/lib/roles/listen/ops-listen.c +++ b/lib/roles/listen/ops-listen.c @@ -144,7 +144,7 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, opts &= ~LWS_ADOPT_ALLOW_SSL; fd.sockfd = filt.accept_fd; - cwsi = lws_adopt_descriptor_vhost(wsi->a.vhost, opts, fd, + cwsi = lws_adopt_descriptor_vhost(wsi->a.vhost, (lws_adoption_type)opts, fd, wsi->a.vhost->listen_accept_protocol, NULL); if (!cwsi) { lwsl_info("%s: vh %s: adopt failed\n", __func__, diff --git a/lib/roles/mqtt/client/client-mqtt-handshake.c b/lib/roles/mqtt/client/client-mqtt-handshake.c index 9bc2accdf..d395ea045 100644 --- a/lib/roles/mqtt/client/client-mqtt-handshake.c +++ b/lib/roles/mqtt/client/client-mqtt-handshake.c @@ -33,8 +33,8 @@ lws_mqtt_client_send_connect(struct lws *wsi) /* static int */ /* lws_mqttc_abs_writeable(lws_abs_protocol_inst_t *api, size_t budget) */ const lws_mqttc_t *c = &wsi->mqtt->client; - uint8_t b[256 + LWS_PRE], *start = b + LWS_PRE, *p = start, - len = MQTT_CONNECT_MSG_BASE_LEN; + uint8_t b[256 + LWS_PRE], *start = b + LWS_PRE, *p = start; + unsigned int len = MQTT_CONNECT_MSG_BASE_LEN; switch (lwsi_state(wsi)) { case LRS_MQTTC_IDLE: @@ -56,13 +56,13 @@ lws_mqtt_client_send_connect(struct lws *wsi) */ len += c->id->len; if (c->conn_flags & LMQCFT_USERNAME && c->username) { - len += c->username->len + 2; + len = len + (unsigned int)c->username->len + 2; if (c->conn_flags & LMQCFT_PASSWORD) - len += (c->password ? c->password->len : 0) + 2; + len += (unsigned int)(c->password ? c->password->len : 0) + 2u; } if (c->conn_flags & LMQCFT_WILL_FLAG && c->will.topic) { - len += c->will.topic->len + 2; - len += (c->will.message ? c->will.message->len : 0) + 2; + len = len + (unsigned int)c->will.topic->len + 2; + len += (c->will.message ? c->will.message->len : 0) + 2u; } p += lws_mqtt_vbi_encode(len, p); @@ -167,7 +167,7 @@ lws_mqtt_client_send_connect(struct lws *wsi) /* * Perform the actual write */ - if (lws_write(wsi, (unsigned char *)&b[LWS_PRE], lws_ptr_diff(p, start), + if (lws_write(wsi, (unsigned char *)&b[LWS_PRE], lws_ptr_diff_size_t(p, start), LWS_WRITE_BINARY) != lws_ptr_diff(p, start)) { lwsl_notice("%s: write failed\n", __func__); diff --git a/lib/roles/mqtt/client/client-mqtt.c b/lib/roles/mqtt/client/client-mqtt.c index 902ad6f9e..8e87218f8 100644 --- a/lib/roles/mqtt/client/client-mqtt.c +++ b/lib/roles/mqtt/client/client-mqtt.c @@ -92,7 +92,7 @@ lws_read_mqtt(struct lws *wsi, unsigned char *buf, lws_filepos_t len) { lws_mqttc_t *c = &wsi->mqtt->client; - return _lws_mqtt_rx_parser(wsi, &c->par, buf, len); + return _lws_mqtt_rx_parser(wsi, &c->par, buf, (size_t)len); } int @@ -137,8 +137,8 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i, if (!c->will.message) goto oom2; } - c->conn_flags |= (cp->will_param.qos << 3) & LMQCFT_WILL_QOS_MASK; - c->conn_flags |= (!!cp->will_param.retain) * LMQCFT_WILL_RETAIN; + c->conn_flags = (uint8_t)(unsigned int)(c->conn_flags | ((cp->will_param.qos << 3) & LMQCFT_WILL_QOS_MASK)); + c->conn_flags |= (uint8_t)((!!cp->will_param.retain) * LMQCFT_WILL_RETAIN); } if (cp->username && @@ -181,7 +181,7 @@ lws_mqtt_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, int n = 0, m = 0; struct lws_tokens ebuf; int buffered = 0; - char pending = 0; + int pending = 0; #if defined(LWS_WITH_TLS) char erbuf[128]; #endif @@ -268,8 +268,8 @@ lws_mqtt_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, if (context->detailed_latency_cb) { wsi->detlat.type = LDLT_TLS_NEG_CLIENT; wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); } @@ -282,7 +282,7 @@ start_ws_handshake: #endif lwsi_set_state(wsi, LRS_MQTTC_IDLE); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, - context->timeout_secs); + (int)context->timeout_secs); /* fallthru */ @@ -308,17 +308,17 @@ start_ws_handshake: case LRS_MQTTC_AWAIT_CONNACK: buffered = 0; ebuf.token = pt->serv_buf; - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((int)pending > ebuf.len) - pending = ebuf.len; + pending = (char)ebuf.len; ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, - pending ? (int)pending : - ebuf.len); + (unsigned int)(pending ? pending : + ebuf.len)); switch (ebuf.len) { case 0: lwsl_info("%s: zero length read\n", @@ -336,7 +336,7 @@ start_ws_handshake: if (ebuf.len < 0) n = -1; else - n = lws_read_mqtt(wsi, ebuf.token, ebuf.len); + n = lws_read_mqtt(wsi, ebuf.token, (unsigned int)ebuf.len); if (n < 0) { lwsl_err("%s: Parsing packet failed\n", __func__); goto fail; diff --git a/lib/roles/mqtt/mqtt.c b/lib/roles/mqtt/mqtt.c index c6ef724ad..b5052923c 100644 --- a/lib/roles/mqtt/mqtt.c +++ b/lib/roles/mqtt/mqtt.c @@ -224,7 +224,7 @@ lws_mqttc_state_transition(lws_mqttc_t *c, lwsgs_mqtt_states_t s) static int lws_mqtt_pconsume(lws_mqtt_parser_t *par, int consumed) { - par->consumed += consumed; + par->consumed += (unsigned int)consumed; if (par->consumed > par->props_len) return -1; @@ -575,7 +575,7 @@ _lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, goto oom; pub = (lws_mqtt_publish_param_t *)wsi->mqtt->rx_cpkt_param; - pub->topic_len = par->n; + pub->topic_len = (uint16_t)par->n; /* Topic Name */ pub->topic = (char *)lws_zalloc((size_t)pub->topic_len + 1, @@ -594,7 +594,7 @@ _lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, pub->payload_pos = 0; pub->payload_len = par->cpkt_remlen - - (2 + pub->topic_len + ((pub->qos) ? 2 : 0)); + (unsigned int)(2 + pub->topic_len + ((pub->qos) ? 2 : 0)); switch (pub->qos) { case QOS0: @@ -634,7 +634,7 @@ _lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, par->state = LMQCPP_PAYLOAD; pub->payload_pos = 0; pub->payload_len = par->cpkt_remlen - - (2 + pub->topic_len + ((pub->qos) ? 2 : 0)); + (unsigned int)(2 + pub->topic_len + ((pub->qos) ? 2 : 0)); if (pub->payload_len == 0) goto cmd_completion; @@ -719,7 +719,7 @@ _lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, (par->cpkt_flags & LMQCFT_SESSION_PRESENT)) goto send_protocol_error_and_close; - wsi->mqtt->session_resumed = (par->cpkt_flags & + wsi->mqtt->session_resumed = ((unsigned int)par->cpkt_flags & LMQCFT_SESSION_PRESENT); /* Move on to Connect Return Code */ @@ -1275,7 +1275,7 @@ bail1: if (lws_mqtt_find_sub(w->mqtt, pub->topic)) if (w->a.protocol->callback( - w, n, + w, (enum lws_callback_reasons)n, w->user_space, (void *)pub, chunk)) @@ -1325,7 +1325,7 @@ bail1: case LMSPR_NEED_MORE: break; case LMSPR_COMPLETED: - par->consumed += par->vbit.consumed; + par->consumed = (uint32_t)((unsigned int)par->consumed + (unsigned int)par->vbit.consumed); if (par->vbit.value > LWS_ARRAY_SIZE(property_valid)) { lwsl_notice("%s: undef prop id 0x%x\n", @@ -1341,11 +1341,11 @@ bail1: goto send_protocol_error_and_close; } par->prop_id = par->vbit.value; - par->flag_prop_multi = + par->flag_prop_multi = !!( par->props_seen[par->prop_id >> 3] & - (1 << (par->prop_id & 7)); + (1 << (par->prop_id & 7))); par->props_seen[par->prop_id >> 3] |= - (1 << (par->prop_id & 7)); + (uint8_t)(1 << (par->prop_id & 7)); /* * even if it's not a vbi property arg, * .consumed of this will be zero the first time @@ -1515,7 +1515,7 @@ lws_mqtt_fill_fixed_header(uint8_t *p, lws_mqtt_control_packet_t ctrl_pkt_type, lws_mqtt_fixed_hdr_t hdr; hdr.bits = 0; - hdr.flags.ctrl_pkt_type = (uint8_t) ctrl_pkt_type; + hdr.flags.ctrl_pkt_type = ctrl_pkt_type & 0xf; switch(ctrl_pkt_type) { case LMQCP_PUBLISH: @@ -1531,7 +1531,7 @@ lws_mqtt_fill_fixed_header(uint8_t *p, lws_mqtt_control_packet_t ctrl_pkt_type, __func__, qos); return -1; } - hdr.flags.qos = (uint8_t)qos; + hdr.flags.qos = qos & 3; hdr.flags.retain = !!retain; break; @@ -1640,7 +1640,7 @@ lws_mqtt_client_send_publish(struct lws *wsi, lws_mqtt_publish_param_t *pub, * Topic len field + Topic len + Packet ID * (for QOS>0) + Payload len */ - vh_len = 2 + pub->topic_len + ((pub->qos) ? 2 : 0); + vh_len = (unsigned int)(2 + pub->topic_len + ((pub->qos) ? 2 : 0)); rem_len = vh_len + pub->payload_len; lwsl_debug("%s: Remaining len = %d\n", __func__, (int) rem_len); @@ -1663,7 +1663,7 @@ lws_mqtt_client_send_publish(struct lws *wsi, lws_mqtt_publish_param_t *pub, * chuncked payload) */ lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, - (pub->topic_len + ((pub->qos) ? 2 : 0) + len), + (uint16_t)(unsigned int)(pub->topic_len + ((pub->qos) ? 2u : 0u) + len), 0); p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); @@ -1692,7 +1692,7 @@ lws_mqtt_client_send_publish(struct lws *wsi, lws_mqtt_publish_param_t *pub, if (pub->payload_len && len) { p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); memcpy(p, buf, len); - if (lws_mqtt_str_advance(&mqtt_vh_payload, len)) + if (lws_mqtt_str_advance(&mqtt_vh_payload, (int)len)) return 1; p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); } @@ -1704,7 +1704,7 @@ do_write: // lwsl_hexdump_err(start, lws_ptr_diff(p, start)); - if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + if (lws_write(nwsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_BINARY) != lws_ptr_diff(p, start)) { lwsl_err("%s: write failed\n", __func__); return 1; @@ -1845,7 +1845,7 @@ lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub) if (!exists[n]) rem_len += (2 + (uint32_t)strlen(sub->topic[n].name) + (uint32_t)1); - wsi->mqtt->sub_size = rem_len; + wsi->mqtt->sub_size = (uint16_t)rem_len; #if defined(_DEBUG) lwsl_debug("%s: Number of topics = %d, Remaining len = %d\n", @@ -1854,14 +1854,14 @@ lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub) p += lws_mqtt_vbi_encode(rem_len, p); - if ((rem_len + lws_ptr_diff(p, start)) >= + if ((rem_len + lws_ptr_diff_size_t(p, start)) >= wsi->a.context->pt_serv_buf_size) { lwsl_err("%s: Payload is too big\n", __func__); return 1; } /* Init lws_mqtt_str */ - lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, rem_len, 0); + lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, (uint16_t)rem_len, 0); p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); /* Packet ID */ @@ -1909,7 +1909,7 @@ lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub) p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); /* QoS */ - *p = sub->topic[n].qos; + *p = (uint8_t)sub->topic[n].qos; if (lws_mqtt_str_advance(&mqtt_vh_payload, 1)) return 1; p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); @@ -1920,7 +1920,7 @@ lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub) return 1; } - if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + if (lws_write(nwsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_BINARY) != lws_ptr_diff(p, start)) return 1; @@ -2010,21 +2010,21 @@ lws_mqtt_client_send_unsubcribe(struct lws *wsi, if (send_unsub[n]) rem_len += (2 + (uint32_t)strlen(unsub->topic[n].name)); - wsi->mqtt->sub_size = rem_len; + wsi->mqtt->sub_size = (uint16_t)rem_len; lwsl_debug("%s: Number of topics = %d, Remaining len = %d\n", __func__, (int)tops, (int)rem_len); p += lws_mqtt_vbi_encode(rem_len, p); - if ((rem_len + lws_ptr_diff(p, start)) >= + if ((rem_len + lws_ptr_diff_size_t(p, start)) >= wsi->a.context->pt_serv_buf_size) { lwsl_err("%s: Payload is too big\n", __func__); return 1; } /* Init lws_mqtt_str */ - lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, rem_len, 0); + lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, (uint16_t)rem_len, 0); p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); /* Packet ID */ @@ -2069,7 +2069,7 @@ lws_mqtt_client_send_unsubcribe(struct lws *wsi, return 1; } - if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + if (lws_write(nwsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_BINARY) != lws_ptr_diff(p, start)) return 1; diff --git a/lib/roles/mqtt/ops-mqtt.c b/lib/roles/mqtt/ops-mqtt.c index fbaa83552..6b812d26a 100644 --- a/lib/roles/mqtt/ops-mqtt.c +++ b/lib/roles/mqtt/ops-mqtt.c @@ -119,17 +119,17 @@ read: buffered = 0; ebuf.token = pt->serv_buf; - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((int)pending > ebuf.len) - pending = ebuf.len; + pending = (unsigned int)ebuf.len; ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, - pending ? (int)pending : - ebuf.len); + pending ? pending : + (unsigned int)ebuf.len); switch (ebuf.len) { case 0: lwsl_info("%s: zero length read\n", @@ -155,7 +155,7 @@ drain: /* service incoming data */ //lws_buflist_describe(&wsi->buflist, wsi, __func__); if (ebuf.len) { - n = lws_read_mqtt(wsi, ebuf.token, ebuf.len); + n = lws_read_mqtt(wsi, ebuf.token, (unsigned int)ebuf.len); if (n < 0) { lwsl_notice("%s: lws_read_mqtt returned %d\n", __func__, n); @@ -172,7 +172,7 @@ drain: ebuf.token = NULL; ebuf.len = 0; - pending = lws_ssl_pending(wsi); + pending = (unsigned int)lws_ssl_pending(wsi); if (pending) { pending = pending > wsi->a.context->pt_serv_buf_size ? wsi->a.context->pt_serv_buf_size : pending; @@ -541,7 +541,7 @@ rops_close_kill_connection_mqtt(struct lws *wsi, enum lws_close_status reason) lws_wsi_mux_dump_children(wsi); } - lws_wsi_mux_close_children(wsi, reason); + lws_wsi_mux_close_children(wsi, (int)reason); } if (( diff --git a/lib/roles/mqtt/primitives.c b/lib/roles/mqtt/primitives.c index 0fd8e5c9d..7842187f4 100644 --- a/lib/roles/mqtt/primitives.c +++ b/lib/roles/mqtt/primitives.c @@ -100,8 +100,8 @@ lws_mqtt_vbi_r(lws_mqtt_vbi *vbi, const uint8_t **in, size_t *len) (*len)--; vbi->consumed++; - vbi->value += (u & 0x7f) << multiplier; - multiplier += 7; + vbi->value = vbi->value + (uint32_t)((u & 0x7f) << multiplier); + multiplier = (uint8_t)(multiplier + 7); if (!(u & 0x80)) return LMSPR_COMPLETED; /* finished */ } @@ -208,7 +208,7 @@ uint8_t * lws_mqtt_str_next(lws_mqtt_str_t *s, uint16_t *budget) { if (budget) - *budget = s->limit - s->pos; + *budget = (uint16_t)(s->limit - s->pos); return &s->buf[s->pos]; } @@ -222,8 +222,8 @@ lws_mqtt_str_advance(lws_mqtt_str_t *s, int n) return 1; } - s->pos += n; - s->len += n; + s->pos = (uint16_t)(s->pos + (uint16_t)n); + s->len = (uint16_t)(s->len + (uint16_t)n); return 0; } @@ -266,7 +266,7 @@ lws_mqtt_str_parse(lws_mqtt_str_t *s, const uint8_t **in, size_t *len) /* handle the length + allocation if needed */ while (*len && !s->len_valid && s->pos < 2) { - s->len = (s->len << 8) | *((*in)++); + s->len = (uint16_t)((s->len << 8) | *((*in)++)); (*len)--; oin = *in; if (++s->pos == 2) { @@ -291,17 +291,17 @@ lws_mqtt_str_parse(lws_mqtt_str_t *s, const uint8_t **in, size_t *len) /* handle copying bulk data into allocation */ if (s->len_valid && *len) { - uint16_t span = s->len - s->pos; + uint16_t span = (uint16_t)(s->len - s->pos); if (span > *len) span = (uint16_t)*len; memcpy(s->buf + s->pos, *in, span); *in += span; - s->pos += span; + s->pos = (uint16_t)(s->pos + (uint16_t)span); } - *len -= *in - oin; + *len -= (unsigned long)(*in - oin); return s->buf && s->pos == s->len ? LMSPR_COMPLETED : LMSPR_NEED_MORE; } diff --git a/lib/roles/netlink/ops-netlink.c b/lib/roles/netlink/ops-netlink.c index 52ed0665a..f167e3b47 100644 --- a/lib/roles/netlink/ops-netlink.c +++ b/lib/roles/netlink/ops-netlink.c @@ -64,7 +64,7 @@ rops_handle_POLLIN_netlink(struct lws_context_per_thread *pt, struct lws *wsi, struct nlmsghdr *h; struct msghdr msg; struct iovec iov; - int n; + unsigned int n; if (!(pollfd->revents & LWS_POLLIN)) return LWS_HPI_RET_HANDLED; @@ -91,31 +91,17 @@ rops_handle_POLLIN_netlink(struct lws_context_per_thread *pt, struct lws *wsi, msg.msg_iov = &iov; msg.msg_iovlen = 1; - n = recvmsg(wsi->desc.sockfd, &msg, 0); - if (n < 0) + n = (unsigned int)recvmsg(wsi->desc.sockfd, &msg, 0); + if ((int)n < 0) return LWS_HPI_RET_PLEASE_CLOSE_ME; h = (struct nlmsghdr *)s; -/* - * On some platforms nlh->nlmsg_len is a uint32_t but len is expected to be - * an int. This causes the last comparison to blow with - * - * comparison of integers of different signs: '__u32' (aka 'unsigned int') and - * 'int' [-Werror,-Wsign-compare] - * - * rtnetlink messages cannot be huge, solve it by casting nmmsg_len to int - */ - -#define LWS_NLMSG_OK(nlh, len) ((len) >= (int) sizeof(struct nlmsghdr) && \ - (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \ - (int)(nlh)->nlmsg_len <= (len)) - - for ( ; LWS_NLMSG_OK(h, n); h = NLMSG_NEXT(h, n)) { + for ( ; NLMSG_OK(h, n); h = NLMSG_NEXT(h, n)) { struct ifaddrmsg *ifam; struct rtattr *ra; struct rtmsg *rm; - int ra_len; + unsigned int ra_len; uint8_t *p; /* @@ -157,18 +143,23 @@ rops_handle_POLLIN_netlink(struct lws_context_per_thread *pt, struct lws *wsi, robj.source_ads = 1; robj.dest_len = ifam->ifa_prefixlen; - robj.if_idx = ifam->ifa_index; + robj.if_idx = (int)ifam->ifa_index; robj.scope = ifam->ifa_scope; robj.ifa_flags = ifam->ifa_flags; robj.dest.sa4.sin_family = ifam->ifa_family; /* address attributes */ ra = (struct rtattr *)IFA_RTA(ifam); - ra_len = IFA_PAYLOAD(h); + ra_len = (unsigned int)IFA_PAYLOAD(h); } else { + + if (h->nlmsg_type != RTM_NEWROUTE && + h->nlmsg_type != RTM_DELROUTE) + continue; + /* route attributes */ ra = (struct rtattr *)RTM_RTA(rm); - ra_len = RTM_PAYLOAD(h); + ra_len = (unsigned int)RTM_PAYLOAD(h); } robj.proto = rm->rtm_protocol; @@ -370,7 +361,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, memset(&sanl, 0, sizeof(sanl)); sanl.nl_family = AF_NETLINK; - sanl.nl_pid = getpid(); + sanl.nl_pid = (uint32_t)getpid(); sanl.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE #if defined(LWS_WITH_IPV6) | RTMGRP_IPV6_ROUTE @@ -408,7 +399,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, req.hdr.nlmsg_type = RTM_GETROUTE; req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; req.hdr.nlmsg_seq = 1; - req.hdr.nlmsg_pid = getpid(); + req.hdr.nlmsg_pid = (uint32_t)getpid(); req.gen.rtm_family = AF_PACKET; req.gen.rtm_table = RT_TABLE_DEFAULT; @@ -419,7 +410,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, msg.msg_name = &sanl; msg.msg_namelen = sizeof(sanl); - n = sendmsg(wsi->desc.sockfd, (struct msghdr *)&msg, 0); + n = (int)sendmsg(wsi->desc.sockfd, (struct msghdr *)&msg, 0); if (n < 0) { lwsl_notice("%s: rt dump req failed... permissions? errno %d\n", __func__, LWS_ERRNO); diff --git a/lib/roles/pipe/ops-pipe.c b/lib/roles/pipe/ops-pipe.c index 7f68c8e4b..d678135d8 100644 --- a/lib/roles/pipe/ops-pipe.c +++ b/lib/roles/pipe/ops-pipe.c @@ -47,7 +47,7 @@ rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, * We really don't care about the number of bytes, but coverity * thinks we should. */ - n = read(wsi->desc.sockfd, s, sizeof(s)); + n = (int)read(wsi->desc.sockfd, s, sizeof(s)); (void)n; if (n < 0) return LWS_HPI_RET_PLEASE_CLOSE_ME; diff --git a/lib/roles/private-lib-roles.h b/lib/roles/private-lib-roles.h index 1b79aefea..1c7adb6f5 100644 --- a/lib/roles/private-lib-roles.h +++ b/lib/roles/private-lib-roles.h @@ -64,7 +64,7 @@ enum lwsi_role { LWSI_ROLE_ENCAP_MASK = (0x0f00 << _RS), }; -#define lwsi_role(wsi) (wsi->wsistate & LWSI_ROLE_MASK) +#define lwsi_role(wsi) (wsi->wsistate & (unsigned int)LWSI_ROLE_MASK) #if !defined (_DEBUG) #define lwsi_set_role(wsi, role) wsi->wsistate = \ (wsi->wsistate & (~LWSI_ROLE_MASK)) | role @@ -162,7 +162,7 @@ enum lwsi_state { #define lwsi_state_can_handle_POLLOUT(wsi) (wsi->wsistate & LWSIFS_POCB) #if !defined (_DEBUG) #define lwsi_set_state(wsi, lrs) wsi->wsistate = \ - (wsi->wsistate & (~LRS_MASK)) | lrs + (wsi->wsistate & (lws_wsi_state_t)(~LRS_MASK)) | lrs #else void lwsi_set_state(struct lws *wsi, lws_wsi_state_t lrs); #endif diff --git a/lib/roles/raw-proxy/ops-raw-proxy.c b/lib/roles/raw-proxy/ops-raw-proxy.c index 3c81fc861..93e5cb5e4 100644 --- a/lib/roles/raw-proxy/ops-raw-proxy.c +++ b/lib/roles/raw-proxy/ops-raw-proxy.c @@ -85,7 +85,7 @@ rops_handle_POLLIN_raw_proxy(struct lws_context_per_thread *pt, struct lws *wsi, LWS_CALLBACK_RAW_PROXY_CLI_RX : LWS_CALLBACK_RAW_PROXY_SRV_RX, wsi->user_space, ebuf.token, - ebuf.len); + (size_t)ebuf.len); if (n < 0) { lwsl_info("LWS_CALLBACK_RAW_PROXY_*_RX fail\n"); goto fail; diff --git a/lib/roles/raw-skt/ops-raw-skt.c b/lib/roles/raw-skt/ops-raw-skt.c index 53c06749b..37a08423d 100644 --- a/lib/roles/raw-skt/ops-raw-skt.c +++ b/lib/roles/raw-skt/ops-raw-skt.c @@ -160,7 +160,7 @@ rops_handle_POLLIN_raw_skt(struct lws_context_per_thread *pt, struct lws *wsi, n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RAW_RX, wsi->user_space, ebuf.token, - ebuf.len); + (unsigned int)ebuf.len); #if defined(LWS_WITH_UDP) || defined(LWS_WITH_SOCKS5) post_rx: #endif diff --git a/lib/roles/ws/client-parser-ws.c b/lib/roles/ws/client-parser-ws.c index 317ca0c0f..8fc6ef4f4 100644 --- a/lib/roles/ws/client-parser-ws.c +++ b/lib/roles/ws/client-parser-ws.c @@ -213,7 +213,7 @@ int lws_ws_client_rx_sm(struct lws *wsi, unsigned char c) break; case LWS_RXPS_04_FRAME_HDR_LEN16_2: - wsi->ws->rx_packet_length = c << 8; + wsi->ws->rx_packet_length = (size_t)((unsigned int)c << 8); wsi->lws_rx_parse_state = LWS_RXPS_04_FRAME_HDR_LEN16_1; break; @@ -406,7 +406,7 @@ spill: lwsl_parser("client sees server close len = %d\n", (int)wsi->ws->rx_ubuf_head); if (wsi->ws->rx_ubuf_head >= 2) { - close_code = (pp[0] << 8) | pp[1]; + close_code = (unsigned short)((pp[0] << 8) | pp[1]); if (close_code < 1000 || close_code == 1004 || close_code == 1005 || @@ -431,7 +431,7 @@ spill: memcpy(wsi->ws->ping_payload_buf + LWS_PRE, pp, wsi->ws->rx_ubuf_head); wsi->ws->close_in_ping_buffer_len = - wsi->ws->rx_ubuf_head; + (uint8_t)wsi->ws->rx_ubuf_head; lwsl_info("%s: scheduling return close as ack\n", __func__); @@ -472,7 +472,7 @@ spill: &wsi->ws->rx_ubuf[LWS_PRE], wsi->ws->rx_ubuf_head); - wsi->ws->ping_payload_len = wsi->ws->rx_ubuf_head; + wsi->ws->ping_payload_len = (uint8_t)wsi->ws->rx_ubuf_head; wsi->ws->ping_pending_flag = 1; /* get it sent as soon as possible */ @@ -523,7 +523,7 @@ ping_drop: goto already_done; pmdrx.eb_in.token = &wsi->ws->rx_ubuf[LWS_PRE]; - pmdrx.eb_in.len = wsi->ws->rx_ubuf_head; + pmdrx.eb_in.len = (int)wsi->ws->rx_ubuf_head; /* for the non-pm-deflate case */ @@ -583,7 +583,7 @@ drain_extension: if (lws_check_utf8(&wsi->ws->utf8, pmdrx.eb_out.token, - pmdrx.eb_out.len)) { + (unsigned int)pmdrx.eb_out.len)) { lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, (uint8_t *)"bad utf8", 8); @@ -605,7 +605,7 @@ drain_extension: utf8_fail: lwsl_info("utf8 error\n"); lwsl_hexdump_info(pmdrx.eb_out.token, - pmdrx.eb_out.len); + (unsigned int)pmdrx.eb_out.len); return -1; } @@ -655,7 +655,7 @@ utf8_fail: m = wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)callback_action, wsi->user_space, pmdrx.eb_out.token, - pmdrx.eb_out.len); + (unsigned int)pmdrx.eb_out.len); wsi->ws->first_fragment = 0; diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index 6cd38ea4e..af733cc7c 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -36,7 +36,7 @@ strtolower(char *s) int tolower_optee(int c); *s = tolower_optee((int)*s); #else - *s = tolower((int)*s); + *s = (char)tolower((int)*s); #endif s++; } @@ -60,7 +60,7 @@ lws_create_client_ws_object(const struct lws_client_connect_info *i, i->ietf_version_or_minus_one) v = i->ietf_version_or_minus_one; - wsi->ws->ietf_spec_revision = v; + wsi->ws->ietf_spec_revision = (uint8_t)v; return 0; } @@ -94,7 +94,7 @@ lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) * effectively "putting it back in the cache", we have * to place it at the cache head, not the tail as usual. */ - if (lws_rxflow_cache(wsi, *buf, 0, (int)len) == + if (lws_rxflow_cache(wsi, *buf, 0, len) == LWSRXFC_TRIMMED) { /* * we dealt with it by trimming the existing @@ -222,7 +222,7 @@ lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1) n = sprintf(buf, "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11", key_b64); - lws_SHA1((unsigned char *)buf, n, (unsigned char *)hash); + lws_SHA1((unsigned char *)buf, (unsigned int)n, (unsigned char *)hash); lws_b64_encode_string(hash, 20, wsi->http.ah->initial_handshake_hash_base64, @@ -306,7 +306,7 @@ lws_client_ws_upgrade(struct lws *wsi, const char **cce) n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); if (n <= 0) /* won't fit, or absent */ goto bad_conn_format; - ts.len = n; + ts.len = (unsigned int)n; do { e = lws_tokenize(&ts); @@ -365,7 +365,7 @@ bad_conn_format: len = (int)strlen(p); while (pc && *pc && !okay) { - if (!strncmp(pc, p, len) && + if (!strncmp(pc, p, (unsigned int)len) && (pc[len] == ',' || pc[len] == '\0')) { okay = 1; continue; @@ -463,7 +463,7 @@ check_extensions: * and go through matching them or identifying bogons */ - if (lws_hdr_copy(wsi, sb, context->pt_serv_buf_size, + if (lws_hdr_copy(wsi, sb, (int)context->pt_serv_buf_size, WSI_TOKEN_EXTENSIONS) < 0) { lwsl_warn("ext list from server failed to copy\n"); *cce = "HS: EXT: list too big"; @@ -648,16 +648,16 @@ check_accept: */ n = (int)wsi->a.protocol->rx_buffer_size; if (!n) - n = context->pt_serv_buf_size; + n = (int)context->pt_serv_buf_size; n += LWS_PRE; - wsi->ws->rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */, + wsi->ws->rx_ubuf = lws_malloc((unsigned int)n + 4 /* 0x0000ffff zlib */, "client frame buffer"); if (!wsi->ws->rx_ubuf) { lwsl_err("Out of Mem allocating rx buffer %d\n", n); *cce = "HS: OOM"; goto bail2; } - wsi->ws->rx_ubuf_alloc = n; + wsi->ws->rx_ubuf_alloc = (unsigned int)n; lwsl_debug("handshake OK for protocol %s\n", wsi->a.protocol->name); diff --git a/lib/roles/ws/ext/extension-permessage-deflate.c b/lib/roles/ws/ext/extension-permessage-deflate.c index de7fc1d41..c442f7c1a 100644 --- a/lib/roles/ws/ext/extension-permessage-deflate.c +++ b/lib/roles/ws/ext/extension-permessage-deflate.c @@ -52,7 +52,7 @@ lws_extension_pmdeflate_restrict_args(struct lws *wsi, /* cap the RX buf at the nearest power of 2 to protocol rx buf */ - n = wsi->a.context->pt_serv_buf_size; + n = (int)wsi->a.context->pt_serv_buf_size; if (wsi->a.protocol->rx_buffer_size) n = (int)wsi->a.protocol->rx_buffer_size; @@ -61,7 +61,7 @@ lws_extension_pmdeflate_restrict_args(struct lws *wsi, extra++; if (extra < priv->args[PMD_RX_BUF_PWR2]) { - priv->args[PMD_RX_BUF_PWR2] = extra; + priv->args[PMD_RX_BUF_PWR2] = (unsigned char)extra; lwsl_info(" Capping pmd rx to %d\n", 1 << extra); } } @@ -108,7 +108,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, lwsl_ext("%s: option set: idx %d, %s, len %d\n", __func__, oa->option_index, oa->start, oa->len); if (oa->start) - priv->args[oa->option_index] = atoi(oa->start); + priv->args[oa->option_index] = (unsigned char)atoi(oa->start); else priv->args[oa->option_index] = 1; @@ -129,7 +129,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, case LWS_EXT_CB_CLIENT_CONSTRUCT: case LWS_EXT_CB_CONSTRUCT: - n = context->pt_serv_buf_size; + n = (int)context->pt_serv_buf_size; if (wsi->a.protocol->rx_buffer_size) n = (int)wsi->a.protocol->rx_buffer_size; @@ -231,8 +231,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, priv->rx_init = 1; if (!priv->buf_rx_inflated) priv->buf_rx_inflated = lws_malloc( - LWS_PRE + 7 + 5 + - (1 << priv->args[PMD_RX_BUF_PWR2]), + (unsigned int)(LWS_PRE + 7 + 5 + + (1 << priv->args[PMD_RX_BUF_PWR2])), "pmd rx inflate buf"); if (!priv->buf_rx_inflated) { lwsl_err("%s: OOM\n", __func__); @@ -255,12 +255,12 @@ lws_extension_callback_pm_deflate(struct lws_context *context, #endif if (!priv->rx.avail_in && pmdrx->eb_in.token && pmdrx->eb_in.len) { priv->rx.next_in = (unsigned char *)pmdrx->eb_in.token; - priv->rx.avail_in = pmdrx->eb_in.len; + priv->rx.avail_in = (uInt)pmdrx->eb_in.len; } priv->rx.next_out = priv->buf_rx_inflated + LWS_PRE; pmdrx->eb_out.token = priv->rx.next_out; - priv->rx.avail_out = 1 << priv->args[PMD_RX_BUF_PWR2]; + priv->rx.avail_out = (uInt)(1 << priv->args[PMD_RX_BUF_PWR2]); /* so... if... * @@ -310,8 +310,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, */ pmdrx->eb_in.token = pmdrx->eb_in.token + - (pmdrx->eb_in.len - priv->rx.avail_in); - pmdrx->eb_in.len = priv->rx.avail_in; + ((unsigned int)pmdrx->eb_in.len - (unsigned int)priv->rx.avail_in); + pmdrx->eb_in.len = (int)priv->rx.avail_in; lwsl_debug("%s: %d %d %d %d %d\n", __func__, priv->rx.avail_in, @@ -353,7 +353,7 @@ lws_extension_callback_pm_deflate(struct lws_context *context, pmdrx->eb_out.len = lws_ptr_diff(priv->rx.next_out, pmdrx->eb_out.token); - priv->count_rx_between_fin += pmdrx->eb_out.len; + priv->count_rx_between_fin = priv->count_rx_between_fin + (size_t)pmdrx->eb_out.len; lwsl_ext(" %s: RX leaving with new effbuff len %d, " "rx.avail_in=%d, TOTAL RX since FIN %lu\n", @@ -400,8 +400,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, } if (!priv->buf_tx_deflated) - priv->buf_tx_deflated = lws_malloc(LWS_PRE + 7 + 5 + - (1 << priv->args[PMD_TX_BUF_PWR2]), + priv->buf_tx_deflated = lws_malloc((unsigned int)(LWS_PRE + 7 + 5 + + (1 << priv->args[PMD_TX_BUF_PWR2])), "pmd tx deflate buf"); if (!priv->buf_tx_deflated) { lwsl_err("%s: OOM\n", __func__); @@ -414,22 +414,23 @@ lws_extension_callback_pm_deflate(struct lws_context *context, assert(!priv->tx.avail_in); - priv->count_tx_between_fin += pmdrx->eb_in.len; + priv->count_tx_between_fin = priv->count_tx_between_fin + (size_t)pmdrx->eb_in.len; lwsl_ext("%s: TX: eb_in length %d, " "TOTAL TX since FIN: %d\n", __func__, pmdrx->eb_in.len, (int)priv->count_tx_between_fin); priv->tx.next_in = (unsigned char *)pmdrx->eb_in.token; - priv->tx.avail_in = pmdrx->eb_in.len; + priv->tx.avail_in = (uInt)pmdrx->eb_in.len; } priv->tx.next_out = priv->buf_tx_deflated + LWS_PRE + 5; pmdrx->eb_out.token = priv->tx.next_out; - priv->tx.avail_out = 1 << priv->args[PMD_TX_BUF_PWR2]; + priv->tx.avail_out = (uInt)(1 << priv->args[PMD_TX_BUF_PWR2]); - pen = penbits = 0; + pen = 0; + penbits = 0; deflatePending(&priv->tx, &pen, &penbits); - pen |= penbits; + pen = pen | (unsigned int)penbits; if (!priv->tx.avail_in && (len & LWS_WRITE_NO_FIN)) { lwsl_ext("%s: no available in, pen: %u\n", __func__, pen); @@ -492,8 +493,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, */ pmdrx->eb_in.token = pmdrx->eb_in.token + - (pmdrx->eb_in.len - priv->tx.avail_in); - pmdrx->eb_in.len = priv->tx.avail_in; + ((unsigned int)pmdrx->eb_in.len - (unsigned int)priv->tx.avail_in); + pmdrx->eb_in.len = (int)priv->tx.avail_in; priv->compressed_out = 1; pmdrx->eb_out.len = lws_ptr_diff(priv->tx.next_out, @@ -522,8 +523,8 @@ lws_extension_callback_pm_deflate(struct lws_context *context, * use of CONTINUATION when the first real write does come. */ if (priv->tx_first_frame_type & 0xf) { - *pmdrx->eb_in.token = ((*pmdrx->eb_in.token) & ~0xf) | - (priv->tx_first_frame_type & 0xf); + *pmdrx->eb_in.token = (unsigned char)((((unsigned char)*pmdrx->eb_in.token) & (unsigned char)~0xf) | + ((unsigned char)priv->tx_first_frame_type & (unsigned char)0xf)); /* * We have now written the "first" fragment, only * do that once diff --git a/lib/roles/ws/ext/extension.c b/lib/roles/ws/ext/extension.c index 9ec95eb6d..38fd29953 100644 --- a/lib/roles/ws/ext/extension.c +++ b/lib/roles/ws/ext/extension.c @@ -65,7 +65,7 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, len = 1; break; } - match_map = (1 << count_options) - 1; + match_map = (unsigned int)(1 << count_options) - 1; leap = LEAPS_EAT_NAME; w = 0; @@ -87,7 +87,7 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, if (*in == opts[n].name[w]) { if (!opts[n].name[w + 1]) { - oa.option_index = n; + oa.option_index = (int)n; lwsl_ext("hit %d\n", oa.option_index); leap = LEAPS_SEEK_VAL; @@ -96,7 +96,7 @@ lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, break; } } else { - match_map &= ~(1 << n); + match_map &= (unsigned int)~(1 << n); if (!match_map) { lwsl_ext("empty match map\n"); return -1; @@ -198,7 +198,7 @@ int lws_ext_cb_active(struct lws *wsi, int reason, void *arg, int len) for (n = 0; n < wsi->ws->count_act_ext; n++) { m = wsi->ws->active_extensions[n]->callback( lws_get_context(wsi), wsi->ws->active_extensions[n], - wsi, reason, wsi->ws->act_ext_user[n], arg, len); + wsi, (enum lws_extension_callback_reasons)reason, wsi->ws->act_ext_user[n], arg, (size_t)len); if (m < 0) { lwsl_ext("Ext '%s' failed to handle callback %d!\n", wsi->ws->active_extensions[n]->name, reason); @@ -226,8 +226,8 @@ int lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, ext = wsi->a.vhost->ws.extensions; while (ext && ext->callback && !handled) { - m = ext->callback(context, ext, wsi, reason, - (void *)(lws_intptr_t)n, arg, len); + m = ext->callback(context, ext, wsi, (enum lws_extension_callback_reasons)reason, + (void *)(lws_intptr_t)n, arg, (size_t)len); if (m < 0) { lwsl_ext("Ext '%s' failed to handle callback %d!\n", wsi->ws->active_extensions[n]->name, reason); @@ -282,7 +282,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) /* assuming they left us something to send, send it */ if (ebuf.len) { - n = lws_issue_raw(wsi, ebuf.token, ebuf.len); + n = lws_issue_raw(wsi, ebuf.token, (size_t)ebuf.len); if (n < 0) { lwsl_info("closing from ext access\n"); return -1; @@ -290,7 +290,7 @@ lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len) /* always either sent it all or privately buffered */ if (wsi->ws->clean_buffer) - len = n; + len = (size_t)n; lwsl_ext("%s: written %d bytes to client\n", __func__, n); diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index dff2490fa..fc1bfe7fb 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -278,7 +278,7 @@ handle_first: break; case LWS_RXPS_04_FRAME_HDR_LEN16_2: - wsi->ws->rx_packet_length = c << 8; + wsi->ws->rx_packet_length = (size_t)(c << 8); wsi->lws_rx_parse_state = LWS_RXPS_04_FRAME_HDR_LEN16_1; break; @@ -481,7 +481,7 @@ spill: } if (wsi->ws->rx_ubuf_head >= 2) { - close_code = (pp[0] << 8) | pp[1]; + close_code = (unsigned short)((pp[0] << 8) | pp[1]); if (close_code < 1000 || close_code == 1004 || close_code == 1005 || @@ -535,7 +535,7 @@ process_as_ping: &wsi->ws->rx_ubuf[LWS_PRE], wsi->ws->rx_ubuf_head); - wsi->ws->ping_payload_len = wsi->ws->rx_ubuf_head; + wsi->ws->ping_payload_len = (uint8_t)wsi->ws->rx_ubuf_head; wsi->ws->ping_pending_flag = 1; /* get it sent as soon as possible */ @@ -582,7 +582,7 @@ ping_drop: */ pmdrx.eb_in.token = &wsi->ws->rx_ubuf[LWS_PRE]; - pmdrx.eb_in.len = wsi->ws->rx_ubuf_head; + pmdrx.eb_in.len = (int)wsi->ws->rx_ubuf_head; /* for the non-pm-deflate case */ @@ -616,7 +616,7 @@ drain_extension: lwsl_debug("%s: ext says %d / ebuf.len %d\n", __func__, n, pmdrx.eb_out.len); if (wsi->ws->rx_draining_ext) - already_processed &= ~ALREADY_PROCESSED_NO_CB; + already_processed &= (char)~ALREADY_PROCESSED_NO_CB; #endif /* @@ -662,7 +662,7 @@ drain_extension: wsi->ws->check_utf8 && !wsi->ws->defeat_check_utf8) { if (lws_check_utf8(&wsi->ws->utf8, pmdrx.eb_out.token, - pmdrx.eb_out.len)) { + (size_t)pmdrx.eb_out.len)) { lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, (uint8_t *)"bad utf8", 8); @@ -684,7 +684,7 @@ drain_extension: utf8_fail: lwsl_notice("utf8 error\n"); lwsl_hexdump_notice(pmdrx.eb_out.token, - pmdrx.eb_out.len); + (size_t)pmdrx.eb_out.len); return -1; } @@ -720,7 +720,7 @@ utf8_fail: callback_action, wsi->user_space, pmdrx.eb_out.token, - pmdrx.eb_out.len); + (size_t)pmdrx.eb_out.len); } wsi->ws->first_fragment = 0; } @@ -840,14 +840,14 @@ lws_server_init_wsi_for_ws(struct lws *wsi) n = (int)wsi->a.protocol->rx_buffer_size; if (!n) - n = wsi->a.context->pt_serv_buf_size; + n = (int)wsi->a.context->pt_serv_buf_size; n += LWS_PRE; - wsi->ws->rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */, "rx_ubuf"); + wsi->ws->rx_ubuf = lws_malloc((unsigned int)n + 4 /* 0x0000ffff zlib */, "rx_ubuf"); if (!wsi->ws->rx_ubuf) { lwsl_err("Out of Mem allocating rx buffer %d\n", n); return 1; } - wsi->ws->rx_ubuf_alloc = n; + wsi->ws->rx_ubuf_alloc = (uint32_t)n; /* notify user code that we're ready to roll */ @@ -919,14 +919,14 @@ lws_close_reason(struct lws *wsi, enum lws_close_status status, start = p = &wsi->ws->ping_payload_buf[LWS_PRE]; - *p++ = (((int)status) >> 8) & 0xff; - *p++ = ((int)status) & 0xff; + *p++ = (uint8_t)((((int)status) >> 8) & 0xff); + *p++ = (uint8_t)(((int)status) & 0xff); if (buf) while (len-- && p < start + budget) *p++ = *buf++; - wsi->ws->close_in_ping_buffer_len = lws_ptr_diff(p, start); + wsi->ws->close_in_ping_buffer_len = (uint8_t)lws_ptr_diff(p, start); } static int @@ -1123,19 +1123,19 @@ read: buffered = 0; ebuf.token = pt->serv_buf; if (lwsi_role_ws(wsi)) - ebuf.len = wsi->ws->rx_ubuf_alloc; + ebuf.len = (int)wsi->ws->rx_ubuf_alloc; else - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) - ebuf.len = wsi->a.context->pt_serv_buf_size; + ebuf.len = (int)wsi->a.context->pt_serv_buf_size; if ((int)pending > ebuf.len) - pending = ebuf.len; + pending = (unsigned int)ebuf.len; ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, - pending ? (int)pending : - ebuf.len); + (size_t)(pending ? pending : + (unsigned int)ebuf.len)); switch (ebuf.len) { case 0: lwsl_info("%s: zero length read\n", @@ -1175,16 +1175,16 @@ drain: /* service incoming data */ //lws_buflist_describe(&wsi->buflist, wsi, __func__); - if (ebuf.len) { + if (ebuf.len > 0) { #if defined(LWS_ROLE_H2) if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY && lwsi_state(wsi) != LRS_DISCARD_BODY) n = lws_read_h2(wsi, ebuf.token, - ebuf.len); + (unsigned int)ebuf.len); else #endif n = lws_read_h1(wsi, ebuf.token, - ebuf.len); + (unsigned int)ebuf.len); if (n < 0) { /* we closed wsi */ @@ -1211,7 +1211,7 @@ drain: lws_header_table_detach(wsi, 0); } - pending = lws_ssl_pending(wsi); + pending = (unsigned int)lws_ssl_pending(wsi); #if defined(LWS_WITH_CLIENT) if (!pending && (wsi->flags & LCCSCF_PRIORITIZE_READS) && @@ -1307,7 +1307,7 @@ int rops_handle_POLLOUT_ws(struct lws *wsi) } n = lws_write(wsi, &wsi->ws->ping_payload_buf[LWS_PRE], - wsi->ws->ping_payload_len, write_type); + wsi->ws->ping_payload_len, (enum lws_write_protocol)write_type); if (n < 0) return LWS_HP_RET_BAIL_DIE; @@ -1411,7 +1411,7 @@ int rops_handle_POLLOUT_ws(struct lws *wsi) if (pmdrx.eb_in.len) { n = lws_issue_raw(wsi, (unsigned char *)pmdrx.eb_in.token, - pmdrx.eb_in.len); + (unsigned int)pmdrx.eb_in.len); if (n < 0) { lwsl_info("closing from POLLOUT spill\n"); return LWS_HP_RET_BAIL_DIE; @@ -1475,8 +1475,9 @@ rops_service_flag_pending_ws(struct lws_context *context, int tsi) */ wsi = pt->ws.rx_draining_ext_list; while (wsi && wsi->position_in_fds_table != LWS_NO_FDS_POS) { - pt->fds[wsi->position_in_fds_table].revents |= - pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; + pt->fds[wsi->position_in_fds_table].revents = + (short)((short)pt->fds[wsi->position_in_fds_table].revents | + (short)(pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); if (pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN) forced = 1; @@ -1615,7 +1616,7 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, */ if (!(wpt & LWS_WRITE_NO_FIN) && len) - *wp &= ~LWS_WRITE_NO_FIN; + *wp &= (enum lws_write_protocol)~LWS_WRITE_NO_FIN; lwsl_ext("FORCED draining wp to 0x%02X " "(stashed 0x%02X, incoming 0x%02X)\n", *wp, @@ -1669,7 +1670,7 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, break; default: #if !defined(LWS_WITHOUT_EXTENSIONS) - n = lws_ext_cb_active(wsi, LWS_EXT_CB_PAYLOAD_TX, &pmdrx, *wp); + n = lws_ext_cb_active(wsi, (int)LWS_EXT_CB_PAYLOAD_TX, &pmdrx, (int)*wp); if (n < 0) return -1; lwsl_ext("%s: defl ext ret %d, ext in remaining %d, " @@ -1694,7 +1695,7 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, * action that has provoked generation of these * fragments, so the last guy can use its FIN state. */ - wsi->ws->tx_draining_stashed_wp = *wp; + wsi->ws->tx_draining_stashed_wp = (uint8_t)*wp; /* * Despite what we may have thought, this is definitely * NOT the last fragment, because the extension asserted @@ -1710,7 +1711,7 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, #endif if (pmdrx.eb_out.len && wsi->ws->stashed_write_pending) { wsi->ws->stashed_write_pending = 0; - *wp = ((*wp) & 0xc0) | (int)wsi->ws->stashed_write_type; + *wp = (unsigned int)(((*wp) & 0xc0) | (unsigned int)wsi->ws->stashed_write_type); } } @@ -1740,7 +1741,7 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, } buf = pmdrx.eb_out.token; - len = pmdrx.eb_out.len; + len = (unsigned int)pmdrx.eb_out.len; if (!buf) { lwsl_err("null buf (%d)\n", (int)len); @@ -1785,24 +1786,24 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, if (len < 126) { pre += 2; - buf[-pre] = n; + buf[-pre] = (uint8_t)n; buf[-pre + 1] = (unsigned char)(len | is_masked_bit); } else { if (len < 65536) { pre += 4; - buf[-pre] = n; - buf[-pre + 1] = 126 | is_masked_bit; + buf[-pre] = (uint8_t)n; + buf[-pre + 1] = (uint8_t)(126 | is_masked_bit); buf[-pre + 2] = (unsigned char)(len >> 8); buf[-pre + 3] = (unsigned char)len; } else { pre += 10; - buf[-pre] = n; - buf[-pre + 1] = 127 | is_masked_bit; + buf[-pre] = (uint8_t)n; + buf[-pre + 1] = (uint8_t)(127 | is_masked_bit); #if defined __LP64__ buf[-pre + 2] = (len >> 56) & 0x7f; - buf[-pre + 3] = len >> 48; - buf[-pre + 4] = len >> 40; - buf[-pre + 5] = len >> 32; + buf[-pre + 3] = (uint8_t)(len >> 48); + buf[-pre + 4] = (uint8_t)(len >> 40); + buf[-pre + 5] = (uint8_t)(len >> 32); #else buf[-pre + 2] = 0; buf[-pre + 3] = 0; @@ -1853,7 +1854,7 @@ do_more_inside_frame: return lws_rops_func_fidx(encap->role_ops, LWS_ROPS_write_role_protocol). write_role_protocol(wsi, buf - pre, - len + pre, wp); + len + (unsigned int)pre, wp); } switch ((*wp) & 0x1f) { @@ -1885,7 +1886,7 @@ do_more_inside_frame: * consumed. */ - n = lws_issue_raw_ext_access(wsi, buf - pre, len + pre); + n = lws_issue_raw_ext_access(wsi, buf - pre, len + (unsigned int)pre); wsi->ws->inside_frame = 1; if (n <= 0) return n; @@ -1912,7 +1913,7 @@ do_more_inside_frame: } send_raw: - return lws_issue_raw(wsi, (unsigned char *)buf - pre, len + pre); + return lws_issue_raw(wsi, (unsigned char *)buf - pre, len + (unsigned int)pre); } static int @@ -1971,13 +1972,13 @@ rops_init_vhost_ws(struct lws_vhost *vh, * ones that came from plugins */ vh->ws.extensions = lws_zalloc(sizeof(struct lws_extension) * - (m + vh->context->plugin_extension_count + 1), + (unsigned int)(m + vh->context->plugin_extension_count + 1), "extensions"); if (!vh->ws.extensions) return 1; memcpy((struct lws_extension *)vh->ws.extensions, info->extensions, - sizeof(struct lws_extension) * m); + sizeof(struct lws_extension) * (unsigned int)m); plugin = vh->context->plugin_list; while (plugin) { const lws_plugin_protocol_t *plpr = @@ -1986,7 +1987,7 @@ rops_init_vhost_ws(struct lws_vhost *vh, memcpy((struct lws_extension *)&vh->ws.extensions[m], plpr->extensions, sizeof(struct lws_extension) * - plpr->count_extensions); + (unsigned int)plpr->count_extensions); m += plpr->count_extensions; plugin = plugin->list; } @@ -2055,7 +2056,7 @@ rops_issue_keepalive_ws(struct lws *wsi, int isvalid) if (isvalid) _lws_validity_confirmed_role(wsi); else { - us = lws_now_usecs(); + us = (uint64_t)lws_now_usecs(); memcpy(&wsi->ws->ping_payload_buf[LWS_PRE], &us, 8); wsi->ws->send_check_ping = 1; lws_callback_on_writable(wsi); diff --git a/lib/roles/ws/server-ws.c b/lib/roles/ws/server-ws.c index 5f01b0006..b8469a4c5 100644 --- a/lib/roles/ws/server-ws.c +++ b/lib/roles/ws/server-ws.c @@ -53,7 +53,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) * and go through them */ - if (lws_hdr_copy(wsi, (char *)pt->serv_buf, context->pt_serv_buf_size, + if (lws_hdr_copy(wsi, (char *)pt->serv_buf, (int)context->pt_serv_buf_size, WSI_TOKEN_EXTENSIONS) < 0) return 1; @@ -177,7 +177,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) else LWS_CPYAPP(*p, "\x0d\x0aSec-WebSocket-Extensions: "); - *p += lws_snprintf(*p, (end - *p), "%s", ext_name); + *p += lws_snprintf(*p, lws_ptr_diff_size_t(end, *p), "%s", ext_name); /* * The client may send a bunch of different option @@ -216,10 +216,10 @@ lws_extension_server_handshake(struct lws *wsi, char **p, int budget) LWS_EXT_CB_OPTION_SET, wsi->ws->act_ext_user[ wsi->ws->count_act_ext], - &oa, (end - *p))) { + &oa, lws_ptr_diff_size_t(end, *p))) { *p += lws_snprintf(*p, - (end - *p), + lws_ptr_diff_size_t(end, *p), "; %s", po->name); lwsl_debug("adding option %s\n", po->name); @@ -339,7 +339,7 @@ lws_process_ws_upgrade2(struct lws *wsi) } if (lws_hdr_total_length(wsi, WSI_TOKEN_VERSION)) - wsi->ws->ietf_spec_revision = + wsi->ws->ietf_spec_revision = (uint8_t) atoi(lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION)); /* allocate wsi->user storage */ @@ -465,7 +465,7 @@ lws_process_ws_upgrade(struct lws *wsi) n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); if (n <= 0) goto bad_conn_format; - ts.len = n; + ts.len = (unsigned int)n; do { e = lws_tokenize(&ts); @@ -534,7 +534,7 @@ lws_process_ws_upgrade(struct lws *wsi) lwsl_err("%s: protocol list too long\n", __func__); return 1; } - ts.len = n; + ts.len = (unsigned int)n; if (!ts.len) { int n = wsi->a.vhost->default_protocol_index; /* @@ -665,10 +665,10 @@ handshake_0405(struct lws_context *context, struct lws *wsi) "%s258EAFA5-E914-47DA-95CA-C5AB0DC85B11", lws_hdr_simple_ptr(wsi, WSI_TOKEN_KEY)); - lws_SHA1(pt->serv_buf, n, hash); + lws_SHA1(pt->serv_buf, (unsigned int)n, hash); accept_len = lws_b64_encode_string((char *)hash, 20, - (char *)pt->serv_buf, context->pt_serv_buf_size); + (char *)pt->serv_buf, (int)context->pt_serv_buf_size); if (accept_len < 0) { lwsl_warn("Base64 encoded hash too long\n"); goto bail; @@ -763,9 +763,9 @@ handshake_0405(struct lws_context *context, struct lws *wsi) #if defined(DEBUG) fwrite(response, 1, p - response, stderr); #endif - n = lws_write(wsi, (unsigned char *)response, p - response, + n = lws_write(wsi, (unsigned char *)response, lws_ptr_diff_size_t(p, response), LWS_WRITE_HTTP_HEADERS); - if (n != (p - response)) { + if (n != lws_ptr_diff(p, response)) { lwsl_info("%s: ERROR writing to socket %d\n", __func__, n); goto bail; } @@ -808,7 +808,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) unsigned int avail = (unsigned int)len; uint8_t *buffer = *buf, mask[4]; #if !defined(LWS_WITHOUT_EXTENSIONS) - unsigned int old_packet_length = (int)wsi->ws->rx_packet_length; + unsigned int old_packet_length = (unsigned int)wsi->ws->rx_packet_length; #endif int n = 0; @@ -825,7 +825,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) #endif { if (wsi->a.protocol->rx_buffer_size) - avail = (int)wsi->a.protocol->rx_buffer_size; + avail = (unsigned int)wsi->a.protocol->rx_buffer_size; else avail = wsi->a.context->pt_serv_buf_size; } @@ -842,9 +842,9 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) return 0; pmdrx.eb_in.token = buffer; - pmdrx.eb_in.len = avail; + pmdrx.eb_in.len = (int)avail; pmdrx.eb_out.token = buffer; - pmdrx.eb_out.len = avail; + pmdrx.eb_out.len = (int)avail; if (!wsi->ws->all_zero_nonce) { @@ -852,7 +852,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) mask[n] = wsi->ws->mask[(wsi->ws->mask_idx + n) & 3]; /* deal with 4-byte chunks using unwrapped loop */ - n = avail >> 2; + n = (int)(avail >> 2); while (n--) { *(buffer) = *(buffer) ^ mask[0]; buffer++; @@ -924,7 +924,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) wsi->user_space, NULL, 0)) return -1; - return avail; + return (int)avail; } /* @@ -932,7 +932,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) * length receive. Otherwise we're more willing. */ if (wsi->ws->count_act_ext && !pmdrx.eb_out.len) - return avail; + return (int)avail; if (n == PMDR_HAS_PENDING) /* extension had more... main loop will come back */ @@ -945,7 +945,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) wsi->ws->check_utf8 && !wsi->ws->defeat_check_utf8) { if (lws_check_utf8(&wsi->ws->utf8, pmdrx.eb_out.token, - pmdrx.eb_out.len)) { + (unsigned int)pmdrx.eb_out.len)) { lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, (uint8_t *)"bad utf8", 8); goto utf8_fail; @@ -960,7 +960,7 @@ lws_ws_frame_rest_is_payload(struct lws *wsi, uint8_t **buf, size_t len) utf8_fail: lwsl_info("utf8 error\n"); - lwsl_hexdump_info(pmdrx.eb_out.token, pmdrx.eb_out.len); + lwsl_hexdump_info(pmdrx.eb_out.token, (size_t)pmdrx.eb_out.len); return -1; } @@ -971,7 +971,7 @@ utf8_fail: LWS_CALLBACK_RECEIVE, wsi->user_space, pmdrx.eb_out.token, - pmdrx.eb_out.len)) + (unsigned int)pmdrx.eb_out.len)) return -1; wsi->ws->first_fragment = 0; @@ -982,7 +982,7 @@ utf8_fail: wsi->ws->rx_draining_ext); #endif - return avail; /* how much we used from the input */ + return (int)avail; /* how much we used from the input */ } @@ -1014,7 +1014,7 @@ lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len) * effectively "putting it back in the cache", we have * leave it where it is, already pointed to by the head. */ - if (lws_rxflow_cache(wsi, *buf, 0, (int)len) == + if (lws_rxflow_cache(wsi, *buf, 0, len) == LWSRXFC_TRIMMED) { /* * We dealt with it by trimming the existing @@ -1051,7 +1051,7 @@ lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len) bulk = 1; m = lws_ws_frame_rest_is_payload(wsi, buf, len); assert((int)lws_ptr_diff(*buf, bin) <= (int)len); - len -= lws_ptr_diff(*buf, bin); + len -= lws_ptr_diff_size_t(*buf, bin); if (!m) { diff --git a/lib/secure-streams/policy-json.c b/lib/secure-streams/policy-json.c index f77c28128..175f5330b 100644 --- a/lib/secure-streams/policy-json.c +++ b/lib/secure-streams/policy-json.c @@ -253,13 +253,13 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) // lwsl_notice("%s: allocating respmap %d\n", __func__, a->count); a->curr[LTY_POLICY].p->u.http.respmap = lwsac_use_zero(&a->ac, - sizeof(lws_ss_http_respmap_t) * a->count, POL_AC_GRAIN); + sizeof(lws_ss_http_respmap_t) * (unsigned int)a->count, POL_AC_GRAIN); if (!a->curr[LTY_POLICY].p->u.http.respmap) goto oom; memcpy((void *)a->curr[LTY_POLICY].p->u.http.respmap, - a->respmap, sizeof(lws_ss_http_respmap_t) * a->count); + a->respmap, sizeof(lws_ss_http_respmap_t) * (unsigned int)a->count); a->curr[LTY_POLICY].p->u.http.count_respmap = (uint8_t)a->count; a->count = 0; a->pending_respmap = 0; @@ -276,11 +276,11 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) * The struct *x is in the lwsac... the ca_der it points to * is individually allocated from the heap */ - a->curr[LTY_X509].x->ca_der = lws_malloc(a->count, "ssx509"); + a->curr[LTY_X509].x->ca_der = lws_malloc((unsigned int)a->count, "ssx509"); if (!a->curr[LTY_X509].x->ca_der) goto oom; - memcpy((uint8_t *)a->curr[LTY_X509].x->ca_der, a->p, a->count); - a->curr[LTY_X509].x->ca_der_len = a->count; + memcpy((uint8_t *)a->curr[LTY_X509].x->ca_der, a->p, (unsigned int)a->count); + a->curr[LTY_X509].x->ca_der_len = (unsigned int)a->count; /* * ... and then we can free the temp buffer @@ -305,8 +305,8 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) while (p2) { if (!strncmp(p2->streamtype, ctx->path + ctx->st[ctx->sp].p, - ctx->path_match_len - - ctx->st[ctx->sp].p)) { + (unsigned int)(ctx->path_match_len - + ctx->st[ctx->sp].p))) { lwsl_info("%s: overriding s[] %s\n", __func__, p2->streamtype); break; @@ -382,23 +382,23 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) } ((uint32_t *)b->retry_ms_table) - [b->retry_ms_table_count++] = atoi(ctx->buf); + [b->retry_ms_table_count++] = (uint32_t)atoi(ctx->buf); break; case LSSPPT_CONCEAL: - a->curr[LTY_BACKOFF].b->r.conceal_count = atoi(ctx->buf); + a->curr[LTY_BACKOFF].b->r.conceal_count = (uint16_t)atoi(ctx->buf); break; case LSSPPT_JITTERPC: - a->curr[LTY_BACKOFF].b->r.jitter_percent = atoi(ctx->buf); + a->curr[LTY_BACKOFF].b->r.jitter_percent = (uint8_t)atoi(ctx->buf); break; case LSSPPT_VALIDPING_S: - a->curr[LTY_BACKOFF].b->r.secs_since_valid_ping = atoi(ctx->buf); + a->curr[LTY_BACKOFF].b->r.secs_since_valid_ping = (uint16_t)atoi(ctx->buf); break; case LSSPPT_VALIDHUP_S: - a->curr[LTY_BACKOFF].b->r.secs_since_valid_hangup = atoi(ctx->buf); + a->curr[LTY_BACKOFF].b->r.secs_since_valid_hangup = (uint16_t)atoi(ctx->buf); break; case LSSPPT_CERTS: @@ -407,7 +407,7 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) goto oom; } inl = ctx->npos; - outl = MAX_CERT_TEMP - a->count; + outl = MAX_CERT_TEMP - (unsigned int)a->count; lws_b64_decode_stateful(&a->b64, ctx->buf, &inl, a->p + a->count, &outl, @@ -518,7 +518,7 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) goto string2; case LSSPPT_PORT: - a->curr[LTY_POLICY].p->port = atoi(ctx->buf); + a->curr[LTY_POLICY].p->port = (uint16_t)atoi(ctx->buf); break; case LSSPPT_PROXY_BUFLEN: @@ -571,15 +571,15 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) break; case LSSPPT_TLS_CLIENT_CERT: - a->curr[LTY_POLICY].p->client_cert = atoi(ctx->buf) + 1; + a->curr[LTY_POLICY].p->client_cert = (uint8_t)(atoi(ctx->buf) + 1); break; case LSSPPT_HTTP_EXPECT: - a->curr[LTY_POLICY].p->u.http.resp_expect = atoi(ctx->buf); + a->curr[LTY_POLICY].p->u.http.resp_expect = (uint16_t)atoi(ctx->buf); break; case LSSPPT_DEFAULT_TIMEOUT_MS: - a->curr[LTY_POLICY].p->timeout_ms = atoi(ctx->buf); + a->curr[LTY_POLICY].p->timeout_ms = (uint32_t)atoi(ctx->buf); break; case LSSPPT_OPPORTUNISTIC: @@ -659,7 +659,7 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) pmd = a->curr[LTY_POLICY].p->metadata; a->curr[LTY_POLICY].p->metadata = lwsac_use_zero(&a->ac, sizeof(lws_ss_metadata_t) + ctx->npos + - (ctx->path_match_len - ctx->st[ctx->sp - 2].p + 1) + 2, + (unsigned int)(ctx->path_match_len - ctx->st[ctx->sp - 2].p + 1) + 2, POL_AC_GRAIN); a->curr[LTY_POLICY].p->metadata->next = pmd; @@ -667,7 +667,7 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) sizeof(lws_ss_metadata_t); a->curr[LTY_POLICY].p->metadata->name = q; memcpy(q, ctx->path + ctx->st[ctx->sp - 2].p + 1, - ctx->path_match_len - ctx->st[ctx->sp - 2].p); + (unsigned int)(ctx->path_match_len - ctx->st[ctx->sp - 2].p)); q += ctx->path_match_len - ctx->st[ctx->sp - 2].p; a->curr[LTY_POLICY].p->metadata->value__may_own_heap = q; @@ -696,9 +696,9 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) lwsl_err("%s: respmap too big\n", __func__); return -1; } - a->respmap[a->count].resp = + a->respmap[a->count].resp = (uint16_t) atoi(ctx->path + ctx->st[ctx->sp - 2].p + 1); - a->respmap[a->count].state = atoi(ctx->buf); + a->respmap[a->count].state = (uint16_t)atoi(ctx->buf); a->pending_respmap = 1; a->count++; break; @@ -782,11 +782,11 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) goto string2; case LSSPPT_MQTT_QOS: - a->curr[LTY_POLICY].p->u.mqtt.qos = atoi(ctx->buf); + a->curr[LTY_POLICY].p->u.mqtt.qos = (uint8_t)atoi(ctx->buf); break; case LSSPPT_MQTT_KEEPALIVE: - a->curr[LTY_POLICY].p->u.mqtt.keep_alive = atoi(ctx->buf); + a->curr[LTY_POLICY].p->u.mqtt.keep_alive = (uint16_t)atoi(ctx->buf); break; case LSSPPT_MQTT_CLEAN_START: @@ -802,7 +802,7 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) goto string2; case LSSPPT_MQTT_WILL_QOS: - a->curr[LTY_POLICY].p->u.mqtt.will_qos = atoi(ctx->buf); + a->curr[LTY_POLICY].p->u.mqtt.will_qos = (uint8_t)atoi(ctx->buf); break; case LSSPPT_MQTT_WILL_RETAIN: a->curr[LTY_POLICY].p->u.mqtt.will_retain = @@ -834,13 +834,13 @@ string2: * If we can do const string folding, reuse the existing string rather * than make a new entry */ - extant = lwsac_scan_extant(a->ac, (uint8_t *)ctx->buf, ctx->npos, 1); + extant = lwsac_scan_extant(a->ac, (uint8_t *)ctx->buf, (size_t)ctx->npos, 1); if (extant) { *pp = (char *)extant; return 0; } - *pp = lwsac_use_backfill(&a->ac, ctx->npos + 1, POL_AC_GRAIN); + *pp = lwsac_use_backfill(&a->ac, (size_t)(ctx->npos + 1), POL_AC_GRAIN); if (!*pp) goto oom; memcpy(*pp, ctx->buf, ctx->npos); @@ -850,11 +850,11 @@ string2: string1: n = ctx->st[ctx->sp].p; - *pp = lwsac_use_backfill(&a->ac, ctx->path_match_len + 1 - n, + *pp = lwsac_use_backfill(&a->ac, (size_t)ctx->path_match_len + (size_t)1 - (size_t)n, POL_AC_GRAIN); if (!*pp) goto oom; - memcpy(*pp, ctx->path + n, ctx->path_match_len - n); + memcpy(*pp, ctx->path + n, ctx->path_match_len - (unsigned int)n); (*pp)[ctx->path_match_len - n] = '\0'; return 0; diff --git a/lib/secure-streams/protocols/ss-h1.c b/lib/secure-streams/protocols/ss-h1.c index 713079096..c573241e6 100644 --- a/lib/secure-streams/protocols/ss-h1.c +++ b/lib/secure-streams/protocols/ss-h1.c @@ -77,9 +77,9 @@ ss_http_multipart_parser(lws_ss_handle_t *h, void *in, size_t len) (h->u.http.any ? 2 : 0) + 1) h->info.rx(ss_to_userobj(h), &q[pending_issue], - n - pending_issue - + (unsigned int)(n - pending_issue - h->u.http.boundary_len - 1 - - (h->u.http.any ? 2 : 0) /* crlf */, + (h->u.http.any ? 2 : 0) /* crlf */), (!h->u.http.som ? LWSSS_FLAG_SOM : 0) | LWSSS_FLAG_EOM | LWSSS_FLAG_RELATED_END); @@ -125,9 +125,9 @@ ss_http_multipart_parser(lws_ss_handle_t *h, void *in, size_t len) if (n >= pending_issue + h->u.http.boundary_len + (h->u.http.any ? 2 : 0)) h->info.rx(ss_to_userobj(h), &q[pending_issue], - n - pending_issue - + (unsigned int)(n - pending_issue - h->u.http.boundary_len - - (h->u.http.any ? 2 /* crlf */ : 0), + (h->u.http.any ? 2 /* crlf */ : 0)), (!h->u.http.som ? LWSSS_FLAG_SOM : 0) | LWSSS_FLAG_EOM); } @@ -142,7 +142,8 @@ around: } if (pending_issue != n) { - h->info.rx(ss_to_userobj(h), &q[pending_issue], n - pending_issue, + h->info.rx(ss_to_userobj(h), &q[pending_issue], + (unsigned int)(n - pending_issue), (!h->u.http.som ? LWSSS_FLAG_SOM : 0)); h->u.http.any = 1; h->u.http.som = 1; @@ -268,7 +269,7 @@ lws_extract_metadata(lws_ss_handle_t *h, struct lws *wsi) * set the related metadata name to it then */ - _lws_ss_set_metadata(omd, polmd->name, cp, n); + _lws_ss_set_metadata(omd, polmd->name, cp, (unsigned int)n); #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) /* @@ -299,7 +300,7 @@ lws_extract_metadata(lws_ss_handle_t *h, struct lws *wsi) polmd->value_length); if (n > 0) { - p = lws_malloc(n + 1, __func__); + p = lws_malloc((unsigned int)n + 1, __func__); if (!p) return 1; @@ -491,7 +492,7 @@ secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user, */ int n = lws_ss_http_resp_to_state(h, status); if (n) { - r = lws_ss_event_helper(h, n); + r = lws_ss_event_helper(h, (lws_ss_constate_t)n); if (r != LWSSSSRET_OK) return _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE(r, wsi, &h); @@ -627,17 +628,17 @@ malformed: if (!ab) return -1; - buflen = sizeof(buf) - o - 2; + buflen = sizeof(buf) - (unsigned int)o - 2u; n = lws_system_blob_get(ab, buf + o, &buflen, 0); if (n < 0) return -1; - buf[o + buflen] = '\0'; + buf[(unsigned int)o + buflen] = '\0'; lwsl_debug("%s: adding blob %d: %s\n", __func__, m, buf); if (lws_add_http_header_by_name(wsi, (uint8_t *)h->policy->u.http.blob_header[m], - buf, (int)(buflen + o), p, end)) + buf, (int)((int)buflen + o), p, end)) return -1; } @@ -756,9 +757,9 @@ malformed: h->txn_resp_pending = 0; if (lws_add_http_common_headers(wsi, - h->txn_resp_set ? + (unsigned int)(h->txn_resp_set ? (h->txn_resp ? h->txn_resp : 200) : - HTTP_STATUS_NOT_FOUND, + HTTP_STATUS_NOT_FOUND), NULL, h->wsi->http.writeable_len, &p, end)) return 1; @@ -800,13 +801,13 @@ malformed: h->rideshare->u.http.multipart_content_type, (char **)&p, (char *)end); - buflen = lws_ptr_diff(end, p); + buflen = lws_ptr_diff_size_t(end, p); if (h->policy->u.http.multipart_name) buflen -= 24; /* allow space for end of multipart */ #else - buflen = lws_ptr_diff(end, p); + buflen = lws_ptr_diff_size_t(end, p); #endif - r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f); + r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f); if (r == LWSSSSRET_TX_DONT_SEND) return 0; if (r < 0) @@ -852,7 +853,7 @@ malformed: lwsl_info("%s: lws_write %d %d\n", __func__, lws_ptr_diff(p, buf + LWS_PRE), f); - if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff(p, buf + LWS_PRE), + if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff_size_t(p, buf + LWS_PRE), (!conceal_eom && (f & LWSSS_FLAG_EOM)) ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP) != (int)lws_ptr_diff(p, buf + LWS_PRE)) { @@ -888,11 +889,11 @@ malformed: if (m) { lws_ss_set_metadata(h, "method", lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_COLON_METHOD), m); + WSI_TOKEN_HTTP_COLON_METHOD), (unsigned int)m); m = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH); lws_ss_set_metadata(h, "path", lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_COLON_PATH), m); + WSI_TOKEN_HTTP_COLON_PATH), (unsigned int)m); } else #endif { @@ -900,14 +901,14 @@ malformed: if (m) { lws_ss_set_metadata(h, "path", lws_hdr_simple_ptr(wsi, - WSI_TOKEN_GET_URI), m); + WSI_TOKEN_GET_URI), (unsigned int)m); lws_ss_set_metadata(h, "method", "GET", 3); } else { m = lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI); if (m) { lws_ss_set_metadata(h, "path", lws_hdr_simple_ptr(wsi, - WSI_TOKEN_POST_URI), m); + WSI_TOKEN_POST_URI), (unsigned int)m); lws_ss_set_metadata(h, "method", "POST", 4); } } diff --git a/lib/secure-streams/protocols/ss-h2.c b/lib/secure-streams/protocols/ss-h2.c index 96d309839..2bd772d0e 100644 --- a/lib/secure-streams/protocols/ss-h2.c +++ b/lib/secure-streams/protocols/ss-h2.c @@ -189,7 +189,7 @@ secstream_tx_credit_add_h2(lws_ss_handle_t *h, int add) { lwsl_info("%s: %s: add %d\n", __func__, lws_ss_tag(h), add); if (h->wsi) - return lws_h2_update_peer_txcredit(h->wsi, LWS_H2_STREAM_SID, add); + return lws_h2_update_peer_txcredit(h->wsi, (unsigned int)LWS_H2_STREAM_SID, add); return 0; } diff --git a/lib/secure-streams/protocols/ss-mqtt.c b/lib/secure-streams/protocols/ss-mqtt.c index 83b4eb98f..1e1d1cdb4 100644 --- a/lib/secure-streams/protocols/ss-mqtt.c +++ b/lib/secure-streams/protocols/ss-mqtt.c @@ -205,13 +205,13 @@ secstream_mqtt(struct lws *wsi, enum lws_callback_reasons reason, void *user, lwsl_notice("%s, expbuf - %s\n", __func__, expbuf); mqpp.topic = (char *)expbuf; - mqpp.topic_len = strlen(mqpp.topic); - mqpp.packet_id = h->txord - 1; + mqpp.topic_len = (uint16_t)strlen(mqpp.topic); + mqpp.packet_id = (uint16_t)(h->txord - 1); mqpp.payload = buf + LWS_PRE; if (h->writeable_len) - mqpp.payload_len = h->writeable_len; + mqpp.payload_len = (uint32_t)h->writeable_len; else - mqpp.payload_len = buflen; + mqpp.payload_len = (uint32_t)buflen; lwsl_notice("%s: payload len %d\n", __func__, (int)mqpp.payload_len); @@ -219,7 +219,8 @@ secstream_mqtt(struct lws *wsi, enum lws_callback_reasons reason, void *user, mqpp.qos = h->policy->u.mqtt.qos; if (lws_mqtt_client_send_publish(wsi, &mqpp, - (const char *)buf + LWS_PRE, buflen, + (const char *)buf + LWS_PRE, + (uint32_t)buflen, f & LWSSS_FLAG_EOM)) { lwsl_notice("%s: failed to publish\n", __func__); diff --git a/lib/secure-streams/protocols/ss-raw.c b/lib/secure-streams/protocols/ss-raw.c index f0e2ae4b7..aa020a233 100644 --- a/lib/secure-streams/protocols/ss-raw.c +++ b/lib/secure-streams/protocols/ss-raw.c @@ -118,7 +118,7 @@ secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (!h || !h->info.tx) return 0; - buflen = lws_ptr_diff(end, p); + buflen = lws_ptr_diff_size_t(end, p); r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f); if (r == LWSSSSRET_TX_DONT_SEND) return 0; @@ -131,8 +131,8 @@ secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user, */ p += buflen; - if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff(p, buf + LWS_PRE), - LWS_WRITE_HTTP) != (int)lws_ptr_diff(p, buf + LWS_PRE)) { + if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff_size_t(p, buf + LWS_PRE), + LWS_WRITE_HTTP) != lws_ptr_diff(p, buf + LWS_PRE)) { lwsl_err("%s: write failed\n", __func__); return -1; } diff --git a/lib/secure-streams/protocols/ss-ws.c b/lib/secure-streams/protocols/ss-ws.c index 1f0eae106..fb25a28a0 100644 --- a/lib/secure-streams/protocols/ss-ws.c +++ b/lib/secure-streams/protocols/ss-ws.c @@ -154,7 +154,7 @@ secstream_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, !!(f & LWSSS_FLAG_SOM), !!(f & LWSSS_FLAG_EOM)); - n = lws_write(wsi, buf + LWS_PRE, buflen, f1); + n = lws_write(wsi, buf + LWS_PRE, buflen, (enum lws_write_protocol)f1); if (n < (int)buflen) { lwsl_info("%s: write failed %d %d\n", __func__, n, (int)buflen); diff --git a/lib/secure-streams/secure-streams-client.c b/lib/secure-streams/secure-streams-client.c index 17c653508..8fbd2ecdc 100644 --- a/lib/secure-streams/secure-streams-client.c +++ b/lib/secure-streams/secure-streams-client.c @@ -79,7 +79,7 @@ lws_sspc_serialize_metadata(lws_sspc_metadata_t *md, uint8_t *p, uint8_t *end) p[0] = LWSSS_SER_TXPRE_TXCR_UPDATE; lws_ser_wu16be(&p[1], 4); - lws_ser_wu32be(&p[3], md->tx_cr_adjust); + lws_ser_wu32be(&p[3], (uint32_t)md->tx_cr_adjust); n = 7; @@ -88,19 +88,19 @@ lws_sspc_serialize_metadata(lws_sspc_metadata_t *md, uint8_t *p, uint8_t *end) lwsl_info("%s: sending metadata\n", __func__); p[0] = LWSSS_SER_TXPRE_METADATA; - txc = strlen(md->name); - n = txc + 1 + md->len; + txc = (int)strlen(md->name); + n = txc + 1 + (int)md->len; if (n > 0xffff) /* we can't serialize this metadata in 16b length */ return -1; if (n > lws_ptr_diff(end, &p[4])) /* we don't have space for this metadata */ return -1; - lws_ser_wu16be(&p[1], n); - p[3] = txc; - memcpy(&p[4], md->name, txc); + lws_ser_wu16be(&p[1], (uint16_t)n); + p[3] = (uint8_t)txc; + memcpy(&p[4], md->name, (unsigned int)txc); memcpy(&p[4 + txc], &md[1], md->len); - n = 4 + txc + md->len; + n = 4 + txc + (int)md->len; } lws_dll2_remove(&md->list); @@ -248,11 +248,11 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, * We are negotating the opening of a particular * streamtype */ - n = strlen(h->ssi.streamtype) + 4; + n = (int)strlen(h->ssi.streamtype) + 4; s[0] = LWSSS_SER_TXPRE_STREAMTYPE; - lws_ser_wu16be(&s[1], n); - lws_ser_wu32be(&s[3], h->txc.peer_tx_cr_est); + lws_ser_wu16be(&s[1], (uint16_t)n); + lws_ser_wu32be(&s[3], (uint32_t)h->txc.peer_tx_cr_est); //h->txcr_out = txc; lws_strncpy((char *)&s[7], h->ssi.streamtype, sizeof(s) - 7); n += 3; @@ -288,7 +288,7 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, __func__, (unsigned int)h->writeable_len); s[0] = LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT; lws_ser_wu16be(&s[1], 4); - lws_ser_wu32be(&s[3], h->writeable_len); + lws_ser_wu32be(&s[3], (uint32_t)h->writeable_len); h->pending_writeable_len = 0; n = 7; goto req_write_and_issue; @@ -339,7 +339,7 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, __func__, (unsigned int)h->writeable_len); s[0] = LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT; lws_ser_wu16be(&s[1], 4); - lws_ser_wu32be(&s[3], h->writeable_len); + lws_ser_wu32be(&s[3], (uint32_t)h->writeable_len); h->pending_writeable_len = 0; n = 7; goto req_write_and_issue; @@ -370,18 +370,18 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, break; } - h->txc.tx_cr -= len; + h->txc.tx_cr = h->txc.tx_cr - (int)len; cp = p; - n = len + 19; + n = (int)(len + 19); us = lws_now_usecs(); p[0] = LWSSS_SER_TXPRE_TX_PAYLOAD; - lws_ser_wu16be(&p[1], len + 19 - 3); - lws_ser_wu32be(&p[3], flags); + lws_ser_wu16be(&p[1], (uint16_t)(len + 19 - 3)); + lws_ser_wu32be(&p[3], (uint32_t)flags); /* time spent here waiting to send this */ - lws_ser_wu32be(&p[7], us - h->us_earliest_write_req); + lws_ser_wu32be(&p[7], (uint32_t)(us - h->us_earliest_write_req)); /* ust that the client write happened */ - lws_ser_wu64be(&p[11], us); + lws_ser_wu64be(&p[11], (uint64_t)us); h->us_earliest_write_req = 0; if (flags & LWSSS_FLAG_EOM) @@ -400,7 +400,7 @@ do_write_nz: break; do_write: - n = lws_write(wsi, (uint8_t *)cp, n, LWS_WRITE_RAW); + n = lws_write(wsi, (uint8_t *)cp, (unsigned int)n, LWS_WRITE_RAW); if (n < 0) { lwsl_notice("%s: WRITEABLE: %d\n", __func__, n); diff --git a/lib/secure-streams/secure-streams-process.c b/lib/secure-streams/secure-streams-process.c index 0d1751594..724d4b16b 100644 --- a/lib/secure-streams/secure-streams-process.c +++ b/lib/secure-streams/secure-streams-process.c @@ -503,13 +503,13 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason, while (rsp) { if (n != 4 && n < (int)sizeof(s) - 2) s[n++] = ','; - n += lws_snprintf(&s[n], sizeof(s) - n, + n += lws_snprintf(&s[n], sizeof(s) - (unsigned int)n, "%s", rsp->streamtype); rsp = lws_ss_policy_lookup(wsi->a.context, rsp->rideshare_streamtype); } } - s[2] = n - 3; + s[2] = (char)(n - 3); conn->state = LPCSPROX_OPERATIONAL; lws_set_timeout(wsi, 0, 0); break; @@ -536,8 +536,8 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason, md->pending_onward = 0; p = (uint8_t *)s; p[0] = LWSSS_SER_RXPRE_METADATA; - lws_ser_wu16be(&p[1], 1 + naml + - md->length); + lws_ser_wu16be(&p[1], (uint16_t)(1 + naml + + md->length)); p[3] = (uint8_t)naml; memcpy(&p[4], md->name, naml); p += 4 + naml; @@ -601,7 +601,7 @@ again: if (!n) break; - n = lws_write(wsi, (uint8_t *)cp, n, LWS_WRITE_RAW); + n = lws_write(wsi, (uint8_t *)cp, (unsigned int)n, LWS_WRITE_RAW); if (n < 0) { lwsl_info("%s: WRITEABLE: %d\n", __func__, n); diff --git a/lib/secure-streams/secure-streams-serialize.c b/lib/secure-streams/secure-streams-serialize.c index 3ab4e7e6b..1783d581e 100644 --- a/lib/secure-streams/secure-streams-serialize.c +++ b/lib/secure-streams/secure-streams-serialize.c @@ -109,7 +109,7 @@ lws_ss_serialize_state_transition(lws_ss_conn_states_t *state, int new_state) #if defined(_DEBUG) lwsl_info("%s: %s -> %s\n", __func__, sn[*state], sn[new_state]); #endif - *state = new_state; + *state = (lws_ss_conn_states_t)new_state; } @@ -134,7 +134,7 @@ lws_ss_serialize_rx_payload(struct lws_dsh *dsh, const uint8_t *buf, assert(rsp); if (!rsp) return 1; - l = strlen(rsp); + l = (int)strlen(rsp); est += 1 + l; } else assert(!rsp); @@ -143,10 +143,10 @@ lws_ss_serialize_rx_payload(struct lws_dsh *dsh, const uint8_t *buf, // lwsl_hexdump_info(buf, len); pre[0] = LWSSS_SER_RXPRE_RX_PAYLOAD; - lws_ser_wu16be(&pre[1], len + est - 3); - lws_ser_wu32be(&pre[3], flags); + lws_ser_wu16be(&pre[1], (uint16_t)(len + (size_t)est - 3)); + lws_ser_wu32be(&pre[3], (uint32_t)flags); lws_ser_wu32be(&pre[7], 0); /* write will compute latency here... */ - lws_ser_wu64be(&pre[11], us); /* ... and set this to the write time */ + lws_ser_wu64be(&pre[11], (uint64_t)us); /* ... and set this to the write time */ /* * If we are on a non-default rideshare, append the non-default name to @@ -155,10 +155,10 @@ lws_ss_serialize_rx_payload(struct lws_dsh *dsh, const uint8_t *buf, if (flags & LWSSS_FLAG_RIDESHARE) { pre[19] = (uint8_t)l; - memcpy(&pre[20], rsp, l); + memcpy(&pre[20], rsp, (unsigned int)l); } - if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, est, buf, len)) { + if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, (unsigned int)est, buf, len)) { lwsl_err("%s: unable to alloc in dsh 1\n", __func__); return 1; @@ -205,7 +205,7 @@ lws_ss_deserialize_tx_payload(struct lws_dsh *dsh, struct lws *wsi, return 1; } - *len = lws_ser_ru16be(&p[1]) - (23 - 3); + *len = (size_t)(lws_ser_ru16be(&p[1]) - (23 - 3)); if (*len != si - 23) { /* * We cannot accept any length that doesn't reflect the actual @@ -219,7 +219,7 @@ lws_ss_deserialize_tx_payload(struct lws_dsh *dsh, struct lws *wsi, memcpy(buf, p + 23, si - 23); - *flags = lws_ser_ru32be(&p[3]); + *flags = (int)lws_ser_ru32be(&p[3]); #if defined(LWS_WITH_DETAILED_LATENCY) if (wsi && wsi->a.context->detailed_latency_cb) { @@ -265,7 +265,7 @@ lws_ss_serialize_state(struct lws_dsh *dsh, lws_ss_constate_t state, uint8_t pre[12]; int n = 4; - lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); pre[0] = LWSSS_SER_RXPRE_CONNSTATE; @@ -282,7 +282,7 @@ lws_ss_serialize_state(struct lws_dsh *dsh, lws_ss_constate_t state, lws_ser_wu32be(&pre[n], ack); - if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, n + 4, NULL, 0)) { + if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, (unsigned int)n + 4, NULL, 0)) { lwsl_err("%s: unable to alloc in dsh 2\n", __func__); return 1; @@ -306,7 +306,7 @@ lws_ss_serialize_txcr(struct lws_dsh *dsh, int txcr) pre[0] = LWSSS_SER_RXPRE_TXCR_UPDATE; pre[1] = 0; pre[2] = 4; - lws_ser_wu32be(&pre[3], txcr); + lws_ser_wu32be(&pre[3], (uint32_t)txcr); if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, 7, NULL, 0)) { lwsl_err("%s: unable to alloc in dsh 2\n", __func__); @@ -376,12 +376,12 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par, break; case RPAR_LEN_MSB: /* this is remaining frame length */ - par->rem = (*cp++) << 8; + par->rem = (uint16_t)((*cp++) << 8); par->ps++; break; case RPAR_LEN_LSB: - par->rem |= *cp++; + par->rem |= (uint16_t)*cp++; switch (par->type) { /* event loop side */ @@ -603,7 +603,7 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par, break; case RPAR_RIDESHARE: - par->rideshare[par->ctr++] = *cp++; + par->rideshare[par->ctr++] = (char)*cp++; if (!par->rem--) goto hangup; if (par->ctr != par->slen) @@ -679,17 +679,17 @@ payload_ff: p = pre; pre[0] = LWSSS_SER_TXPRE_TX_PAYLOAD; - lws_ser_wu16be(&p[1], n + 23 - 3); + lws_ser_wu16be(&p[1], (uint16_t)((unsigned int)n + 23 - 3)); lws_ser_wu32be(&p[3], flags); /* us held at client before written */ lws_ser_wu32be(&p[7], par->usd_phandling); /* us taken for transit to proxy */ - lws_ser_wu32be(&p[11], us - par->ust_pwait); + lws_ser_wu32be(&p[11], (uint32_t)(us - (lws_usec_t)par->ust_pwait)); /* time used later to find proxy hold time */ - lws_ser_wu64be(&p[15], us); + lws_ser_wu64be(&p[15], (uint64_t)us); if (lws_dsh_alloc_tail(dsh, KIND_C_TO_P, pre, - 23, cp, n)) { + 23, cp, (unsigned int)n)) { lwsl_err("%s: unable to alloc in dsh 3\n", __func__); @@ -717,7 +717,7 @@ payload_ff: if (client_pss_to_sspc_h(pss, ssi)) { /* we still have an sspc handle */ int ret = ssi->rx(client_pss_to_userdata(pss), - (uint8_t *)cp, n, flags); + (uint8_t *)cp, (unsigned int)n, (int)flags); switch (ret) { case LWSSSSRET_OK: break; @@ -748,8 +748,8 @@ payload_ff: if (n) { cp += n; - par->rem -= n; - len = (len + 1) - n; + par->rem = (uint16_t)(par->rem - (uint16_t)(unsigned int)n); + len = (len + 1) - (unsigned int)n; /* * if we didn't consume it all, we'll come * around again and produce more dsh entries up @@ -877,7 +877,7 @@ payload_ff: } else { if (!par->temp32) - par->temp32 = + par->temp32 = (int) proxy_pss_to_ss_h(pss)-> policy->timeout_ms; @@ -885,7 +885,7 @@ payload_ff: __func__, par->temp32); lws_ss_start_timeout( - proxy_pss_to_ss_h(pss), + proxy_pss_to_ss_h(pss), (unsigned int) par->temp32); } } @@ -913,7 +913,7 @@ payload_ff: if (proxy_pss_to_ss_h(pss)) lws_ss_request_tx_len(proxy_pss_to_ss_h(pss), - par->temp32); + (unsigned long)par->temp32); par->ps = RPAR_TYPE; break; @@ -933,7 +933,7 @@ payload_ff: /* both client and proxy */ if (!--par->rem) goto hangup; - par->metadata_name[par->ctr++] = *cp++; + par->metadata_name[par->ctr++] = (char)*cp++; if (par->ctr != par->slen) break; par->metadata_name[par->ctr] = '\0'; @@ -1021,7 +1021,7 @@ payload_ff: lws_free_set_NULL(par->ssmd->value__may_own_heap); par->ssmd->value_on_lws_heap = 0; - par->ssmd->value__may_own_heap = lws_malloc(par->rem + 1, "metadata"); + par->ssmd->value__may_own_heap = lws_malloc((unsigned int)par->rem + 1, "metadata"); if (!par->ssmd->value__may_own_heap) { lwsl_err("%s: OOM mdv\n", __func__); goto hangup; @@ -1080,7 +1080,7 @@ payload_ff: * client */ - par->streamtype[par->ctr++] = *cp++; + par->streamtype[par->ctr++] = (char)*cp++; if (--par->rem) break; @@ -1214,7 +1214,7 @@ payload_ff: goto hangup; h->rideshare_ofs[++par->rsl_idx] = par->rsl_pos; } else - h->rideshare_list[par->rsl_pos++] = *cp++; + h->rideshare_list[par->rsl_pos++] = (char)*cp++; if (!--par->rem) par->ps = RPAR_TYPE; break; @@ -1226,22 +1226,22 @@ payload_ff: break; case RPAR_ORD3: - par->flags = (*cp++) << 24; + par->flags = (uint32_t)((*cp++) << 24); par->ps++; break; case RPAR_ORD2: - par->flags |= (*cp++) << 16; + par->flags |= (uint32_t)((*cp++) << 16); par->ps++; break; case RPAR_ORD1: - par->flags |= (*cp++) << 8; + par->flags |= (uint32_t)((*cp++) << 8); par->ps++; break; case RPAR_ORD0: - par->flags |= *cp++; + par->flags |= (uint32_t)(*cp++); par->ps++; par->ps = RPAR_TYPE; diff --git a/lib/secure-streams/secure-streams.c b/lib/secure-streams/secure-streams.c index 66ea5c165..7e1aa4d8c 100644 --- a/lib/secure-streams/secure-streams.c +++ b/lib/secure-streams/secure-streams.c @@ -229,7 +229,7 @@ _lws_ss_backoff(lws_ss_handle_t *h, lws_usec_t us_override) /* Only increase our planned backoff, or go with it */ if (us_override < (lws_usec_t)ms * LWS_US_PER_MS) - us_override = ms * LWS_US_PER_MS; + us_override = (lws_usec_t)(ms * LWS_US_PER_MS); h->seqstate = SSSEQ_RECONNECT_WAIT; lws_ss_set_timeout_us(h, us_override); @@ -274,7 +274,7 @@ lws_smd_ss_cb(void *opaque, lws_smd_class_t _class, */ lws_ser_wu64be(p, _class); - lws_ser_wu64be(p + 8, timestamp); + lws_ser_wu64be(p + 8, (uint64_t)timestamp); if (h->info.rx) h->info.rx((void *)&h[1], p, len + LWS_SMD_SS_RX_HEADER_LEN, @@ -362,7 +362,7 @@ _lws_ss_client_connect(lws_ss_handle_t *h, int is_retry, void *conn_if_sspc_onw) h->u.smd.smd_peer = lws_smd_register(h->context, h, (h->info.flags & LWSSSINFLAGS_PROXIED) ? LWSSMDREG_FLAG_PROXIED_SS : 0, - h->info.manual_initial_tx_credit, + (lws_smd_class_t)h->info.manual_initial_tx_credit, lws_smd_ss_cb); if (!h->u.smd.smd_peer) return LWSSSSRET_TX_DONT_SEND; @@ -623,7 +623,7 @@ lws_ss_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, h->info = *ssi; h->policy = pol; h->context = context; - h->tsi = tsi; + h->tsi = (uint8_t)tsi; h->seq = seq_owner; if (h->info.flags & LWSSSINFLAGS_PROXIED) @@ -675,7 +675,7 @@ lws_ss_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, memcpy(p, ssi->streamtype, strlen(ssi->streamtype) + 1); /* don't mark accepted ss as being the server */ if (ssi->flags & LWSSSINFLAGS_SERVER) - h->info.flags &= ~LWSSSINFLAGS_SERVER; + h->info.flags &= (uint8_t)~LWSSSINFLAGS_SERVER; h->info.streamtype = p; lws_pt_lock(pt, __func__); @@ -710,7 +710,7 @@ lws_ss_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, * format as well) */ h->u.smd.smd_peer = lws_smd_register(context, h, 0, - ssi->manual_initial_tx_credit, + (lws_smd_class_t)ssi->manual_initial_tx_credit, lws_smd_ss_cb); if (!h->u.smd.smd_peer) goto late_bail; diff --git a/lib/secure-streams/system/auth-api.amazon.com/auth.c b/lib/secure-streams/system/auth-api.amazon.com/auth.c index 62d15bf93..6caaef591 100644 --- a/lib/secure-streams/system/auth-api.amazon.com/auth.c +++ b/lib/secure-streams/system/auth-api.amazon.com/auth.c @@ -101,7 +101,7 @@ auth_api_amazon_com_parser_cb(struct lejp_ctx *ctx, char reason) m->expires_secs = atoi(ctx->buf); lws_sul_schedule(context, 0, &context->sul_api_amazon_com, lws_ss_sys_auth_api_amazon_com_renew, - (uint64_t)m->expires_secs * LWS_US_PER_SEC); + (lws_usec_t)m->expires_secs * LWS_US_PER_SEC); break; } @@ -206,7 +206,7 @@ ss_api_amazon_auth_state(void *userobj, void *sh, lws_ss_constate_t state, lws_system_blob_t *ab; size_t s; - lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); ab = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, AUTH_IDX_ROOT); diff --git a/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c b/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c index 9090dd46d..04900f077 100644 --- a/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c +++ b/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c @@ -41,7 +41,7 @@ ss_cpd_state(void *userobj, void *sh, lws_ss_constate_t state, ss_cpd_t *m = (ss_cpd_t *)userobj; struct lws_context *cx = (struct lws_context *)m->opaque_data; - lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { diff --git a/lib/secure-streams/system/fetch-policy/fetch-policy.c b/lib/secure-streams/system/fetch-policy/fetch-policy.c index e84174dd2..dd2ec638c 100644 --- a/lib/secure-streams/system/fetch-policy/fetch-policy.c +++ b/lib/secure-streams/system/fetch-policy/fetch-policy.c @@ -97,7 +97,7 @@ ss_fetch_policy_state(void *userobj, void *sh, lws_ss_constate_t state, ss_fetch_policy_t *m = (ss_fetch_policy_t *)userobj; struct lws_context *context = (struct lws_context *)m->opaque_data; - lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { diff --git a/lib/system/async-dns/async-dns-parse.c b/lib/system/async-dns/async-dns-parse.c index c4068cfcb..24db2c647 100644 --- a/lib/system/async-dns/async-dns-parse.c +++ b/lib/system/async-dns/async-dns-parse.c @@ -30,7 +30,7 @@ static int lws_adns_parse_label(const uint8_t *pkt, int len, const uint8_t *ls, int budget, - char **dest, int dl) + char **dest, size_t dl) { const uint8_t *e = pkt + len, *ols = ls; char pointer = 0, first = 1; @@ -87,7 +87,7 @@ again1: return -1; } - if (ll + 2 > dl) { + if ((unsigned int)ll + 2 > dl) { lwsl_notice("%s: qname too large\n", __func__); return -1; @@ -204,7 +204,7 @@ start: n = lws_adns_parse_label(pkt, len, p, len, &sp, sizeof(stack[0].name) - - lws_ptr_diff(sp, stack[0].name)); + lws_ptr_diff_size_t(sp, stack[0].name)); /* includes case name won't fit */ if (n < 0) return -1; @@ -262,7 +262,7 @@ start: m--; if (n < 1 || n != m || - strncmp(stack[0].name, stack[stp].name, n)) { + strncmp(stack[0].name, stack[stp].name, (unsigned int)n)) { lwsl_notice("%s: skipping %s vs %s\n", __func__, stack[0].name, stack[stp].name); goto skip; @@ -331,7 +331,7 @@ do_cb: /* get the cname alias */ n = lws_adns_parse_label(pkt, len, p, rrpaylen, &sp, sizeof(stack[stp].name) - - lws_ptr_diff(sp, stack[stp].name)); + lws_ptr_diff_size_t(sp, stack[stp].name)); /* includes case name won't fit */ if (n < 0) return -1; @@ -416,7 +416,7 @@ skip: char *cp = (char *)&q[1]; while (stack[stp].name[n]) - *cp++ = tolower(stack[stp].name[n++]); + *cp++ = (char)tolower(stack[stp].name[n++]); /* trim the following . if any */ if (n && cp[-1] == '.') cp--; @@ -493,7 +493,7 @@ lws_async_dns_store(const char *name, void *opaque, uint32_t ttl, i = sizeof(*in6); memset(in6, 0, i); - in6->sin6_family = adst->pos->ai_family; + in6->sin6_family = (sa_family_t)adst->pos->ai_family; memcpy(in6->sin6_addr.s6_addr, payload, 16); adst->flags |= 2; } else @@ -503,7 +503,7 @@ lws_async_dns_store(const char *name, void *opaque, uint32_t ttl, i = sizeof(*in); memset(in, 0, i); - in->sin_family = adst->pos->ai_family; + in->sin_family = (sa_family_t)adst->pos->ai_family; memcpy(&in->sin_addr.s_addr, payload, 4); adst->flags |= 1; } @@ -568,7 +568,7 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len) goto fail_out; } - q->responded |= n; + q->responded |= (uint8_t)n; /* we want to confirm the results against what we last requested... */ @@ -585,7 +585,7 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len) ncname = (int)strlen(nmcname) + 1; - est = sizeof(lws_adns_cache_t) + ncname; + est = sizeof(lws_adns_cache_t) + (unsigned int)ncname; if (lws_ser_ru16be(pkt + DHO_NANSWERS)) { int ir = lws_adns_iterate(q, pkt, (int)len, nmcname, lws_async_dns_estimate, &est); @@ -612,7 +612,7 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len) /* place it at end, no need to care about alignment padding */ adst.name = ((const char *)c) + est - n; - memcpy((char *)adst.name, nm, n); + memcpy((char *)adst.name, nm, (unsigned int)n); /* * Then walk the packet again, placing the objects we accounted for diff --git a/lib/system/async-dns/async-dns.c b/lib/system/async-dns/async-dns.c index c8b91742b..bacd0af0a 100644 --- a/lib/system/async-dns/async-dns.c +++ b/lib/system/async-dns/async-dns.c @@ -195,13 +195,13 @@ lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q) do { if (*name == '.' || !*name) { - *pl = lws_ptr_diff(p, pl + 1); + *pl = (uint8_t)(unsigned int)lws_ptr_diff(p, pl + 1); pl = p; *p++ = 0; /* also serves as terminal length */ if (!*name++) break; } else - *p++ = *name++; + *p++ = (uint8_t)*name++; } while (p + 6 < e); if (p + 6 >= e) { @@ -219,7 +219,7 @@ lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q) assert(p < pkt + sizeof(pkt) - LWS_PRE); n = lws_ptr_diff(p, pkt + LWS_PRE); - m = lws_write(wsi, pkt + LWS_PRE, n, 0); + m = lws_write(wsi, pkt + LWS_PRE, (unsigned int)n, 0); if (m != n) { lwsl_notice("%s: dns write failed %d %d errno %d\n", __func__, m, n, errno); @@ -647,7 +647,7 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name, ai->ai_family = sa46->sa4.sin_family = AF_INET; ai->ai_addrlen = sizeof(sa46->sa4); ai->ai_addr = (struct sockaddr *)&sa46->sa4; - memcpy(&sa46->sa4.sin_addr, ads, m); + memcpy(&sa46->sa4.sin_addr, ads, (unsigned int)m); lws_async_dns_complete(&tmq.tq, c); @@ -659,7 +659,7 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name, ai->ai_family = sa46->sa6.sin6_family = AF_INET6; ai->ai_addrlen = sizeof(sa46->sa6); ai->ai_addr = (struct sockaddr *)&sa46->sa6; - memcpy(&sa46->sa6.sin6_addr, ads, m); + memcpy(&sa46->sa6.sin6_addr, ads, (unsigned int)m); lws_async_dns_complete(&tmq.tq, c); @@ -725,7 +725,7 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name, q->tid &= 0xfffe; q->context = context; - q->tsi = tsi; + q->tsi = (uint8_t)tsi; q->opaque = opaque; q->dns = dns; @@ -745,7 +745,7 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name, p = (char *)&q[1]; while (nlen--) { - *p++ = tolower(*name++); + *p++ = (char)tolower(*name++); p[DNS_MAX - 1] = p[-1]; } *p = '\0'; diff --git a/lib/system/dhcpclient/dhcpclient.c b/lib/system/dhcpclient/dhcpclient.c index 1db442ff1..438757ae5 100644 --- a/lib/system/dhcpclient/dhcpclient.c +++ b/lib/system/dhcpclient/dhcpclient.c @@ -235,7 +235,7 @@ lws_dhcpc_retry_write(struct lws_sorted_usec_list *sul) } static int -lws_dhcpc_prep(uint8_t *start, int bufsiz, lws_dhcpc_req_t *r, int op) +lws_dhcpc_prep(uint8_t *start, unsigned int bufsiz, lws_dhcpc_req_t *r, int op) { uint8_t *p = start; @@ -266,7 +266,7 @@ lws_dhcpc_prep(uint8_t *start, int bufsiz, lws_dhcpc_req_t *r, int op) *p++ = LWSDHCPOPT_MESSAGE_TYPE; *p++ = 1; /* length */ - *p++ = op; + *p++ = (uint8_t)op; switch (op) { case LWSDHCPDISCOVER: @@ -419,7 +419,7 @@ callback_dhcpc(struct lws *wsi, enum lws_callback_reasons reason, void *user, m = IPV4_DNS_SRV_1; while (l && m - IPV4_DNS_SRV_1 < 4) { r->ipv4[m++] = lws_ser_ru32be(p); - l -= 4; + l = (uint8_t)(l - 4); p += 4; } break; @@ -427,7 +427,7 @@ callback_dhcpc(struct lws *wsi, enum lws_callback_reasons reason, void *user, m = l; if (m > (int)sizeof(r->domain) - 1) m = sizeof(r->domain) - 1; - memcpy(r->domain, p, m); + memcpy(r->domain, p, (unsigned int)m); r->domain[m] = '\0'; break; @@ -470,7 +470,7 @@ broken: dhcp_entry_names[n], r->ipv4[n]); else { - m = ntohl(r->ipv4[n]); + m = (int)ntohl(r->ipv4[n]); lws_write_numeric_address((uint8_t *)&m, 4,(char *)pkt, 20); lwsl_info("%s: %s: %s\n", __func__, @@ -594,8 +594,8 @@ broken: /* fallthru */ bcast: - n = lws_dhcpc_prep(p + 28, sizeof(pkt) - LWS_PRE - 28, - r, n); + n = lws_dhcpc_prep(p + 28, (unsigned int) + (sizeof(pkt) - LWS_PRE - 28), r, n); if (n < 0) { lwsl_err("%s: failed to prep\n", __func__); break; @@ -603,7 +603,7 @@ bcast: m = lws_plat_rawudp_broadcast(p, rawdisc, LWS_ARRAY_SIZE(rawdisc), - n + 28, + (size_t)(n + 28), r->wsi_raw->desc.sockfd, (const char *)&r[1]); if (m < 0) @@ -709,13 +709,13 @@ lws_dhcpc_request(struct lws_context *context, const char *iface, int af, /* nope... let's create a request object as he asks */ - n = strlen(iface); - r = lws_zalloc(sizeof(*r) + n + 1, __func__); + n = (int)strlen(iface); + r = lws_zalloc(sizeof(*r) + (unsigned int)n + 1u, __func__); if (!r) return 1; - memcpy(&r[1], iface, n + 1); - r->af = af; + memcpy(&r[1], iface, (unsigned int)n + 1); + r->af = (uint8_t)af; r->cb = cb; r->opaque = opaque; r->context = context; diff --git a/lib/system/ntpclient/ntpclient.c b/lib/system/ntpclient/ntpclient.c index 3d5d43a51..86536c898 100644 --- a/lib/system/ntpclient/ntpclient.c +++ b/lib/system/ntpclient/ntpclient.c @@ -203,7 +203,7 @@ do_close: * and add in the ns */ - ns = lws_ser_ru32be(((uint8_t *)in) + 40) - 2208988800; + ns = (uint64_t)lws_ser_ru32be(((uint8_t *)in) + 40) - (uint64_t)2208988800; ns = (ns * 1000000000) + lws_ser_ru32be(((uint8_t *)in) + 44); /* @@ -212,7 +212,7 @@ do_close: gettimeofday(&t1, NULL); - delta_us = (ns / 1000) - + delta_us = ((int64_t)ns / 1000) - ((t1.tv_sec * LWS_US_PER_SEC) + t1.tv_usec); lwsl_notice("%s: Unix time: %llu, step: %lldus\n", __func__, @@ -233,7 +233,7 @@ do_close: #endif if (lws_system_get_ops(wsi->a.context) && lws_system_get_ops(wsi->a.context)->set_clock) - lws_system_get_ops(wsi->a.context)->set_clock(ns / 1000); + lws_system_get_ops(wsi->a.context)->set_clock((int64_t)ns / 1000); v->set_time = 1; lws_state_transition_steps(&wsi->a.context->mgr_system, diff --git a/lib/system/smd/smd.c b/lib/system/smd/smd.c index 83232e985..37a1b9aec 100644 --- a/lib/system/smd/smd.c +++ b/lib/system/smd/smd.c @@ -141,7 +141,7 @@ lws_smd_msg_send(struct lws_context *ctx, void *pay) if (!ctx->smd.delivering) lws_mutex_lock(ctx->smd.lock_peers); /* +++++++++++++++ peers */ - msg->refcount = _lws_smd_msg_assess_peers_interested(&ctx->smd, msg); + msg->refcount = (uint16_t)_lws_smd_msg_assess_peers_interested(&ctx->smd, msg); lws_mutex_lock(ctx->smd.lock_messages); /* +++++++++++++++++ messages */ lws_dll2_add_tail(&msg->list, &ctx->smd.owner_messages); @@ -199,7 +199,7 @@ lws_smd_msg_printf(struct lws_context *ctx, lws_smd_class_t _class, sizeof(*msg)); msg->length = (uint16_t)n; va_start(ap, format); - vsnprintf((char*)p, n + 2, format, ap); + vsnprintf((char *)p, (unsigned int)n + 2, format, ap); va_end(ap); /* @@ -384,7 +384,7 @@ lws_smd_msg_distribute(struct lws_context *ctx) lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); /* may destroy pr if zombie, hence _safe iterator */ - more |= _lws_smd_msg_deliver_peer(ctx, pr); + more |= (char)!!_lws_smd_msg_deliver_peer(ctx, pr); } lws_end_foreach_dll_safe(p, p1); diff --git a/lib/system/system.c b/lib/system/system.c index 035f76292..824ac6883 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -99,7 +99,7 @@ lws_system_blob_get(lws_system_blob_t *b, uint8_t *buf, size_t *len, size_t ofs) if (n < 0) return -2; - *len = n; + *len = (unsigned int)n; return 0; } @@ -141,7 +141,7 @@ lws_system_get_blob(struct lws_context *context, lws_system_blob_item_t type, idx >= (int)LWS_ARRAY_SIZE(context->system_blobs)) return NULL; - return &context->system_blobs[type + idx]; + return &context->system_blobs[type + (unsigned int)idx]; } #if defined(LWS_WITH_NETWORK) diff --git a/lib/tls/lws-genec-common.c b/lib/tls/lws-genec-common.c index df536be2d..0ea3fb024 100644 --- a/lib/tls/lws-genec-common.c +++ b/lib/tls/lws-genec-common.c @@ -51,7 +51,8 @@ lws_genec_confirm_curve_allowed_by_tls_id(const char *allowed, int id, { struct lws_tokenize ts; lws_tokenize_elem e; - int n, len; + size_t len; + int n; lws_tokenize_init(&ts, allowed, LWS_TOKENIZE_F_COMMA_SEP_LIST | LWS_TOKENIZE_F_MINUS_NONTERM); @@ -68,8 +69,8 @@ lws_genec_confirm_curve_allowed_by_tls_id(const char *allowed, int id, } lwsl_info("match curve %s\n", lws_ec_curves[n].name); - len = (int)strlen(lws_ec_curves[n].name); - jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].len = len; + len = strlen(lws_ec_curves[n].name); + jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].len = (uint32_t)len; jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].buf = lws_malloc(len + 1, "cert crv"); if (!jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].buf) { diff --git a/lib/tls/mbedtls/lws-genaes.c b/lib/tls/mbedtls/lws-genaes.c index 4f4b85ddd..0bde745c1 100644 --- a/lib/tls/mbedtls/lws-genaes.c +++ b/lib/tls/mbedtls/lws-genaes.c @@ -34,8 +34,8 @@ static int operation_map[] = { MBEDTLS_AES_ENCRYPT, MBEDTLS_AES_DECRYPT }; static unsigned int _write_pkcs7_pad(uint8_t *p, int len) { - unsigned int n = 0, padlen = LWS_AES_CBC_BLOCKLEN * (len / - LWS_AES_CBC_BLOCKLEN + 1) - len; + unsigned int n = 0, padlen = LWS_AES_CBC_BLOCKLEN * ((unsigned int)len / + LWS_AES_CBC_BLOCKLEN + 1) - (unsigned int)len; p += len; @@ -54,7 +54,7 @@ lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op, ctx->mode = mode; ctx->k = el; - ctx->op = operation_map[op]; + ctx->op = (enum enum_aes_operation)operation_map[op]; ctx->underway = 0; ctx->padding = padding == LWS_GAESP_WITH_PADDING; @@ -139,12 +139,12 @@ lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen) lwsl_notice("%s: mbedtls_gcm_finish: -0x%x\n", __func__, -n); if (tag && ctx->op == MBEDTLS_AES_DECRYPT && !n) { - if (lws_timingsafe_bcmp(ctx->tag, tag, ctx->taglen)) { + if (lws_timingsafe_bcmp(ctx->tag, tag, (unsigned int)ctx->taglen)) { lwsl_err("%s: lws_genaes_crypt tag " "mismatch (bad first)\n", __func__); lwsl_hexdump_notice(tag, tlen); - lwsl_hexdump_notice(ctx->tag, ctx->taglen); + lwsl_hexdump_notice(ctx->tag, (unsigned int)ctx->taglen); n = -1; } } @@ -200,8 +200,8 @@ lws_genaes_rfc3394_wrap(int wrap, int cek_bits, const uint8_t *kek, * A[0] = IV = A6A6A6A6A6A6A6A6 */ memset(out, 0xa6, 8); - memcpy(out + 8, in, 8 * c64); - n = mbedtls_aes_setkey_enc(&ctx, kek, kek_bits); + memcpy(out + 8, in, 8 * (unsigned int)c64); + n = mbedtls_aes_setkey_enc(&ctx, kek, (unsigned int)kek_bits); } else { /* * 2.2.2 Key Unwrap @@ -217,8 +217,8 @@ lws_genaes_rfc3394_wrap(int wrap, int cek_bits, const uint8_t *kek, * Outputs: Plaintext, n 64-bit values {P1, P2, ..., Pn}. */ memcpy(a, in, 8); - memcpy(out, in + 8, 8 * c64); - n = mbedtls_aes_setkey_dec(&ctx, kek, kek_bits); + memcpy(out, in + 8, 8 * (unsigned int)c64); + n = mbedtls_aes_setkey_dec(&ctx, kek, (unsigned int)kek_bits); } if (n < 0) { @@ -236,7 +236,7 @@ lws_genaes_rfc3394_wrap(int wrap, int cek_bits, const uint8_t *kek, goto bail; memcpy(out, b, 8); - out[7] ^= c64 * n + m; + out[7] ^= (uint8_t)(c64 * n + m); memcpy(r, b + 8, 8); r += 8; } @@ -250,7 +250,7 @@ lws_genaes_rfc3394_wrap(int wrap, int cek_bits, const uint8_t *kek, uint8_t *r = out + (c64 - 1) * 8; for (m = c64; m >= 1; m--) { memcpy(b, a, 8); - b[7] ^= c64 * n + m; + b[7] ^= (uint8_t)(c64 * n + m); memcpy(b + 8, r, 8); if (mbedtls_internal_aes_decrypt(&ctx, b, b)) goto bail; @@ -289,9 +289,9 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, #if defined(LWS_HAVE_mbedtls_internal_aes_encrypt) /* a key of length ctx->k->len is wrapped by a 128-bit KEK */ n = lws_genaes_rfc3394_wrap(ctx->op == MBEDTLS_AES_ENCRYPT, - ctx->op == MBEDTLS_AES_ENCRYPT ? len * 8 : - (len - 8) * 8, ctx->k->buf, - ctx->k->len * 8, + (ctx->op == MBEDTLS_AES_ENCRYPT ? (int)len * 8 : + ((int)len - 8) * 8), ctx->k->buf, + (int)ctx->k->len * 8, in, out); break; #else @@ -319,25 +319,25 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, return -1; memcpy(padin, in, len); - len += _write_pkcs7_pad((uint8_t *)padin, len); - n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, ctx->op, len, iv, + len += _write_pkcs7_pad((uint8_t *)padin, (int)len); + n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, (int)ctx->op, len, iv, padin, out); lws_free(padin); } else - n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, ctx->op, len, iv, + n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, (int)ctx->op, len, iv, in, out); break; case LWS_GAESM_CFB128: memcpy(iv, iv_or_nonce_ctr_or_data_unit_16, 16); - n = mbedtls_aes_crypt_cfb128(&ctx->u.ctx, ctx->op, len, + n = mbedtls_aes_crypt_cfb128(&ctx->u.ctx, (int)ctx->op, len, nc_or_iv_off, iv, in, out); break; case LWS_GAESM_CFB8: memcpy(iv, iv_or_nonce_ctr_or_data_unit_16, 16); - n = mbedtls_aes_crypt_cfb8(&ctx->u.ctx, ctx->op, len, iv, + n = mbedtls_aes_crypt_cfb8(&ctx->u.ctx, (int)ctx->op, len, iv, in, out); break; @@ -351,7 +351,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, break; case LWS_GAESM_ECB: - n = mbedtls_aes_crypt_ecb(&ctx->u.ctx, ctx->op, in, out); + n = mbedtls_aes_crypt_ecb(&ctx->u.ctx, (int)ctx->op, in, out); break; case LWS_GAESM_OFB: @@ -367,7 +367,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, case LWS_GAESM_XTS: #if defined(MBEDTLS_CIPHER_MODE_XTS) memcpy(iv, iv_or_nonce_ctr_or_data_unit_16, 16); - n = mbedtls_aes_crypt_xts(&ctx->u.ctx_xts, ctx->op, len, iv, + n = mbedtls_aes_crypt_xts(&ctx->u.ctx_xts, (int)ctx->op, len, iv, in, out); break; #else @@ -377,7 +377,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, if (!ctx->underway) { ctx->underway = 1; - memcpy(ctx->tag, stream_block_16, taglen); + memcpy(ctx->tag, stream_block_16, (unsigned int)taglen); ctx->taglen = taglen; /* @@ -388,7 +388,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, * additional data len: len */ - n = mbedtls_gcm_starts(&ctx->u.ctx_gcm, ctx->op, + n = mbedtls_gcm_starts(&ctx->u.ctx_gcm, (int)ctx->op, iv_or_nonce_ctr_or_data_unit_16, *nc_or_iv_off, in, len); if (n) { diff --git a/lib/tls/mbedtls/lws-gencrypto.c b/lib/tls/mbedtls/lws-gencrypto.c index fb89ab359..c5d5f3d09 100644 --- a/lib/tls/mbedtls/lws-gencrypto.c +++ b/lib/tls/mbedtls/lws-gencrypto.c @@ -30,7 +30,7 @@ mbedtls_md_type_t lws_gencrypto_mbedtls_hash_to_MD_TYPE(enum lws_genhash_types hash_type) { - mbedtls_md_type_t h = -1; + mbedtls_md_type_t h = (mbedtls_md_type_t)-1; switch (hash_type) { case LWS_GENHASH_TYPE_MD5: diff --git a/lib/tls/mbedtls/lws-genec.c b/lib/tls/mbedtls/lws-genec.c index 88f660506..ef95c3166 100644 --- a/lib/tls/mbedtls/lws-genec.c +++ b/lib/tls/mbedtls/lws-genec.c @@ -76,7 +76,7 @@ lws_genec_keypair_import(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, return -23; mbedtls_ecp_keypair_init(&kp); - if (mbedtls_ecp_group_load(&kp.grp, curve->tls_lib_nid)) + if (mbedtls_ecp_group_load(&kp.grp, (mbedtls_ecp_group_id)curve->tls_lib_nid)) goto bail1; ctx->has_private = !!el[LWS_GENCRYPTO_EC_KEYEL_D].len; @@ -243,7 +243,7 @@ lws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, } mbedtls_ecdsa_init(&ecdsa); - n = mbedtls_ecdsa_genkey(&ecdsa, curve->tls_lib_nid, + n = mbedtls_ecdsa_genkey(&ecdsa, (mbedtls_ecp_group_id)curve->tls_lib_nid, lws_gencrypto_mbedtls_rngf, ctx->context); if (n) { @@ -269,7 +269,7 @@ lws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, mpi[1] = &kp->d; mpi[2] = &kp->Q.Y; - el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = strlen(curve_name) + 1; + el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = (uint32_t)strlen(curve_name) + 1; el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf = lws_malloc(el[LWS_GENCRYPTO_EC_KEYEL_CRV].len, "ec"); if (!el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf) @@ -325,7 +325,7 @@ lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name, } //mbedtls_ecdsa_init(ctx->u.ctx_ecdsa); - n = mbedtls_ecdsa_genkey(ctx->u.ctx_ecdsa, curve->tls_lib_nid, + n = mbedtls_ecdsa_genkey(ctx->u.ctx_ecdsa, (mbedtls_ecp_group_id)curve->tls_lib_nid, lws_gencrypto_mbedtls_rngf, ctx->context); if (n) { lwsl_err("mbedtls_ecdsa_genkey failed 0x%x\n", -n); @@ -343,7 +343,7 @@ lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name, mpi[1] = &kp->d; mpi[2] = &kp->Q.Y; - el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = strlen(curve_name) + 1; + el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = (uint32_t)strlen(curve_name) + 1; el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf = lws_malloc(el[LWS_GENCRYPTO_EC_KEYEL_CRV].len, "ec"); if (!el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf) @@ -422,10 +422,10 @@ lws_genecdsa_hash_sign_jws(struct lws_genec_ctx *ctx, const uint8_t *in, goto bail2; } - if (mbedtls_mpi_write_binary(&mpi_r, sig, keybytes)) + if (mbedtls_mpi_write_binary(&mpi_r, sig, (unsigned int)keybytes)) goto bail2; mbedtls_mpi_free(&mpi_r); - if (mbedtls_mpi_write_binary(&mpi_s, sig + keybytes, keybytes)) + if (mbedtls_mpi_write_binary(&mpi_s, sig + keybytes, (unsigned int)keybytes)) goto bail1; mbedtls_mpi_free(&mpi_s); @@ -471,9 +471,9 @@ lws_genecdsa_hash_sig_verify_jws(struct lws_genec_ctx *ctx, const uint8_t *in, mbedtls_mpi_init(&mpi_r); mbedtls_mpi_init(&mpi_s); - if (mbedtls_mpi_read_binary(&mpi_r, sig, keybytes)) + if (mbedtls_mpi_read_binary(&mpi_r, sig, (unsigned int)keybytes)) return -1; - if (mbedtls_mpi_read_binary(&mpi_s, sig + keybytes, keybytes)) + if (mbedtls_mpi_read_binary(&mpi_s, sig + keybytes, (unsigned int)keybytes)) goto bail1; n = mbedtls_ecdsa_verify(&ctx->u.ctx_ecdsa->grp, in, hlen, @@ -511,7 +511,7 @@ lws_genecdh_compute_shared_secret(struct lws_genec_ctx *ctx, uint8_t *ss, return -1; } - n = mbedtls_ecdh_calc_secret(ctx->u.ctx_ecdh, &st, ss, *ss_len, + n = mbedtls_ecdh_calc_secret(ctx->u.ctx_ecdh, &st, ss, (size_t)*ss_len, lws_gencrypto_mbedtls_rngf, ctx->context); if (n) return -1; diff --git a/lib/tls/mbedtls/lws-genhash.c b/lib/tls/mbedtls/lws-genhash.c index b983686a7..8f578a957 100644 --- a/lib/tls/mbedtls/lws-genhash.c +++ b/lib/tls/mbedtls/lws-genhash.c @@ -36,7 +36,7 @@ int lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type) { - ctx->type = type; + ctx->type = (uint8_t)type; switch (ctx->type) { case LWS_GENHASH_TYPE_MD5: @@ -240,7 +240,7 @@ lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, { int t; - ctx->type = type; + ctx->type = (uint8_t)type; switch (type) { case LWS_GENHMAC_TYPE_SHA256: @@ -256,7 +256,7 @@ lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, return -1; } - ctx->hmac = mbedtls_md_info_from_type(t); + ctx->hmac = mbedtls_md_info_from_type((mbedtls_md_type_t)t); if (!ctx->hmac) return -1; diff --git a/lib/tls/mbedtls/lws-genrsa.c b/lib/tls/mbedtls/lws-genrsa.c index 5269d1266..e5d9ba0a6 100644 --- a/lib/tls/mbedtls/lws-genrsa.c +++ b/lib/tls/mbedtls/lws-genrsa.c @@ -59,7 +59,7 @@ lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_gencrypto_keyelem *el, mbedtls_rsa_init(ctx->ctx, mode_map[mode], 0); ctx->ctx->padding = mode_map[mode]; - ctx->ctx->hash_id = lws_gencrypto_mbedtls_hash_to_MD_TYPE(oaep_hashid); + ctx->ctx->hash_id = (int)lws_gencrypto_mbedtls_hash_to_MD_TYPE(oaep_hashid); { int n; @@ -134,7 +134,7 @@ lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, mbedtls_rsa_init(ctx->ctx, mode_map[mode], 0); - n = mbedtls_rsa_gen_key(ctx->ctx, _rngf, context, bits, 65537); + n = mbedtls_rsa_gen_key(ctx->ctx, _rngf, context, (unsigned int)bits, 65537); if (n) { lwsl_err("mbedtls_rsa_gen_key failed 0x%x\n", -n); goto cleanup_1; @@ -153,7 +153,7 @@ lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, mbedtls_mpi_size(mpi[n]), "genrsakey"); if (!el[n].buf) goto cleanup; - el[n].len = mbedtls_mpi_size(mpi[n]); + el[n].len = (uint32_t)mbedtls_mpi_size(mpi[n]); if (mbedtls_mpi_write_binary(mpi[n], el[n].buf, el[n].len)) goto cleanup; @@ -209,7 +209,7 @@ lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, return -1; } - return olen; + return (int)olen; } int @@ -249,7 +249,7 @@ lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, return -1; } - return olen; + return (int)olen; } int @@ -286,7 +286,7 @@ lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, return -1; } - return mbedtls_mpi_size(&ctx->ctx->N); + return (int)mbedtls_mpi_size(&ctx->ctx->N); } int @@ -323,7 +323,7 @@ lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, return -1; } - return mbedtls_mpi_size(&ctx->ctx->N); + return (int)mbedtls_mpi_size(&ctx->ctx->N); } int @@ -331,7 +331,7 @@ lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, const uint8_t *sig, size_t sig_len) { - int n, h = lws_gencrypto_mbedtls_hash_to_MD_TYPE(hash_type); + int n, h = (int)lws_gencrypto_mbedtls_hash_to_MD_TYPE(hash_type); if (h < 0) return -1; @@ -344,12 +344,12 @@ lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, case LGRSAM_PKCS1_1_5: n = mbedtls_rsa_rsassa_pkcs1_v15_verify(ctx->ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - h, 0, in, sig); + (mbedtls_md_type_t)h, 0, in, sig); break; case LGRSAM_PKCS1_OAEP_PSS: n = mbedtls_rsa_rsassa_pss_verify(ctx->ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, - h, 0, in, sig); + (mbedtls_md_type_t)h, 0, in, sig); break; default: return -1; @@ -368,7 +368,7 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, uint8_t *sig, size_t sig_len) { - int n, h = lws_gencrypto_mbedtls_hash_to_MD_TYPE(hash_type); + int n, h = (int)lws_gencrypto_mbedtls_hash_to_MD_TYPE(hash_type); if (h < 0) return -1; @@ -388,12 +388,12 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, case LGRSAM_PKCS1_1_5: n = mbedtls_rsa_rsassa_pkcs1_v15_sign(ctx->ctx, NULL, NULL, MBEDTLS_RSA_PRIVATE, - h, 0, in, sig); + (mbedtls_md_type_t)h, 0, in, sig); break; case LGRSAM_PKCS1_OAEP_PSS: n = mbedtls_rsa_rsassa_pss_sign(ctx->ctx, NULL, NULL, MBEDTLS_RSA_PRIVATE, - h, 0, in, sig); + (mbedtls_md_type_t)h, 0, in, sig); break; default: return -1; @@ -405,7 +405,7 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, return -1; } - return ctx->ctx->len; + return (int)ctx->ctx->len; } int @@ -446,44 +446,44 @@ lws_genrsa_render_pkey_asn1(struct lws_genrsa_ctx *ctx, int _private, *p++ = 0x00; for (n = 0; n < LWS_GENCRYPTO_RSA_KEYEL_COUNT; n++) { - int m = mbedtls_mpi_size(mpi[n]); + int m = (int)mbedtls_mpi_size(mpi[n]); uint8_t *elen; *p++ = 0x02; elen = p; if (m < 0x7f) - *p++ = m; + *p++ = (uint8_t)m; else { *p++ = 0x82; - *p++ = m >> 8; - *p++ = m & 0xff; + *p++ = (uint8_t)(m >> 8); + *p++ = (uint8_t)(m & 0xff); } if (p + m > end) return -1; - if (mbedtls_mpi_write_binary(mpi[n], p, m)) + if (mbedtls_mpi_write_binary(mpi[n], p, (unsigned int)m)) return -1; if (p[0] & 0x80) { p[0] = 0x00; - if (mbedtls_mpi_write_binary(mpi[n], &p[1], m)) + if (mbedtls_mpi_write_binary(mpi[n], &p[1], (unsigned int)m)) return -1; m++; } if (m < 0x7f) - *elen = m; + *elen = (uint8_t)m; else { *elen++ = 0x82; - *elen++ = m >> 8; - *elen = m & 0xff; + *elen++ = (uint8_t)(m >> 8); + *elen = (uint8_t)(m & 0xff); } p += m; } n = lws_ptr_diff(p, pkey_asn1); - *totlen++ = (n - 4) >> 8; - *totlen = (n - 4) & 0xff; + *totlen++ = (uint8_t)((n - 4) >> 8); + *totlen = (uint8_t)((n - 4) & 0xff); return n; } diff --git a/lib/tls/mbedtls/mbedtls-client.c b/lib/tls/mbedtls/mbedtls-client.c index 97e600908..f370be146 100644 --- a/lib/tls/mbedtls/mbedtls-client.c +++ b/lib/tls/mbedtls/mbedtls-client.c @@ -92,7 +92,7 @@ lws_ssl_client_bio_create(struct lws *wsi) lwsl_info("%s: %s: client conn sending ALPN list '%s'\n", __func__, lws_wsi_tag(wsi), alpn_comma); - protos.len = lws_alpn_comma_to_openssl(alpn_comma, protos.data, + protos.len = (uint8_t)lws_alpn_comma_to_openssl(alpn_comma, protos.data, sizeof(protos.data) - 1); /* with mbedtls, protos is not pointed to after exit from this call */ @@ -137,7 +137,7 @@ lws_ssl_client_bio_create(struct lws *wsi) goto no_client_cert; size = (size_t) flen; - err = SSL_use_certificate_ASN1(wsi->tls.ssl, data, size); + err = SSL_use_certificate_ASN1(wsi->tls.ssl, data, (int)size); lws_free_set_NULL(data); if (err != 1) goto no_client_cert; @@ -160,7 +160,7 @@ lws_ssl_client_bio_create(struct lws *wsi) goto no_client_cert; size = (size_t) flen; - err = SSL_use_PrivateKey_ASN1(0, wsi->tls.ssl, data, size); + err = SSL_use_PrivateKey_ASN1(0, wsi->tls.ssl, data, (int)size); lws_free_set_NULL(data); if (err != 1) goto no_client_cert; @@ -186,7 +186,7 @@ int ERR_get_error(void) } enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) +lws_tls_client_connect(struct lws *wsi, char *errbuf, size_t elen) { int m, n = SSL_connect(wsi->tls.ssl); const unsigned char *prot; @@ -216,7 +216,7 @@ lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) } int -lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) +lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, size_t ebuf_len) { int n; X509 *peer = SSL_get_peer_certificate(wsi->tls.ssl); @@ -231,7 +231,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) } lwsl_info("peer provided cert\n"); - n = SSL_get_verify_result(wsi->tls.ssl); + n = (int)SSL_get_verify_result(wsi->tls.ssl); lwsl_debug("get_verify says %d\n", n); if (n == X509_V_OK) @@ -258,7 +258,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) } lws_snprintf(ebuf, ebuf_len, "server's cert didn't look good, (use_ssl 0x%x) X509_V_ERR = %d: %s\n", - (unsigned int)wsi->tls.use_ssl, n, ERR_error_string(n, sb)); + (unsigned int)wsi->tls.use_ssl, n, ERR_error_string((unsigned long)n, sb)); lwsl_info("%s\n", ebuf); lws_tls_err_describe_clear(); @@ -286,7 +286,7 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, int n; if (!method) { - error = ERR_get_error(); + error = (unsigned long)ERR_get_error(); lwsl_err("problem creating ssl method %lu: %s\n", error, ERR_error_string(error, (char *)vh->context->pt[0].serv_buf)); @@ -295,7 +295,7 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, /* create context */ vh->tls.ssl_client_ctx = SSL_CTX_new(method); if (!vh->tls.ssl_client_ctx) { - error = ERR_get_error(); + error = (unsigned long)ERR_get_error(); lwsl_err("problem creating ssl context %lu: %s\n", error, ERR_error_string(error, (char *)vh->context->pt[0].serv_buf)); @@ -314,12 +314,12 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, lwsl_err("Load CA cert file %s failed\n", ca_filepath); return 1; } - vh->tls.x509_client_CA = d2i_X509(NULL, buf, len); + vh->tls.x509_client_CA = d2i_X509(NULL, buf, (long)len); free(buf); lwsl_notice("Loading client CA for verification %s\n", ca_filepath); #endif } else { - vh->tls.x509_client_CA = d2i_X509(NULL, (uint8_t*)ca_mem, ca_mem_len); + vh->tls.x509_client_CA = d2i_X509(NULL, (uint8_t*)ca_mem, (long)ca_mem_len); lwsl_notice("%s: using mem client CA cert %d\n", __func__, ca_mem_len); } @@ -354,10 +354,10 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, buf[amount++] = '\0'; SSL_CTX_use_PrivateKey_ASN1(0, vh->tls.ssl_client_ctx, - buf, amount); + buf, (long)amount); n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, - amount, buf); + (int)amount, buf); lws_free(buf); if (n < 1) { lwsl_err("problem %d getting cert '%s'\n", n, @@ -371,9 +371,9 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, } else if (cert_mem && cert_mem_len) { /* lwsl_hexdump_notice(cert_mem, cert_mem_len - 1); */ SSL_CTX_use_PrivateKey_ASN1(0, vh->tls.ssl_client_ctx, - cert_mem, cert_mem_len - 1); + cert_mem, (long)cert_mem_len - 1); n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, - cert_mem_len, cert_mem); + (int)cert_mem_len, cert_mem); if (n < 1) { lwsl_err("%s: (mbedtls) problem interpreting client cert\n", __func__); @@ -391,7 +391,7 @@ int lws_tls_client_vhost_extra_cert_mem(struct lws_vhost *vh, const uint8_t *der, size_t der_len) { - if (SSL_CTX_add_client_CA_ASN1(vh->tls.ssl_client_ctx, der_len, der) != 1) { + if (SSL_CTX_add_client_CA_ASN1(vh->tls.ssl_client_ctx, (int)der_len, der) != 1) { lwsl_err("%s: failed\n", __func__); return 1; } diff --git a/lib/tls/mbedtls/mbedtls-server.c b/lib/tls/mbedtls/mbedtls-server.c index 80307f7d2..1b9d6f546 100644 --- a/lib/tls/mbedtls/mbedtls-server.c +++ b/lib/tls/mbedtls/mbedtls-server.c @@ -125,7 +125,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, return 0; } - n = lws_tls_generic_cert_checks(vhost, cert, private_key); + n = (int)lws_tls_generic_cert_checks(vhost, cert, private_key); if (n == LWS_TLS_EXTANT_NO && (!mem_cert || !mem_privkey)) return 0; @@ -161,7 +161,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, return 1; } - err = SSL_CTX_use_certificate_ASN1(vhost->tls.ssl_ctx, flen, p); + err = SSL_CTX_use_certificate_ASN1(vhost->tls.ssl_ctx, (int)flen, p); lws_free_set_NULL(p); if (!err) { lwsl_err("Problem loading cert\n"); @@ -176,7 +176,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, return 1; } - err = SSL_CTX_use_PrivateKey_ASN1(0, vhost->tls.ssl_ctx, p, flen); + err = SSL_CTX_use_PrivateKey_ASN1(0, vhost->tls.ssl_ctx, p, (long)flen); lws_free_set_NULL(p); if (!err) { lwsl_err("Problem loading key\n"); @@ -464,7 +464,7 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, const char *san_b) { int buflen = 0x560; - uint8_t *buf = lws_malloc(buflen, "tmp cert buf"), *p = buf, *pkey_asn1; + uint8_t *buf = lws_malloc((unsigned int)buflen, "tmp cert buf"), *p = buf, *pkey_asn1; struct lws_genrsa_ctx ctx; struct lws_gencrypto_keyelem el[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; uint8_t digest[32]; @@ -483,31 +483,31 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, } n = sizeof(ss_cert_leadin); - memcpy(p, ss_cert_leadin, n); + memcpy(p, ss_cert_leadin, (unsigned int)n); p += n; adj = (0x0556 - 0x401) + (keybits / 4) + 1; - buf[2] = adj >> 8; - buf[3] = adj & 0xff; + buf[2] = (uint8_t)(adj >> 8); + buf[3] = (uint8_t)(adj & 0xff); adj = (0x033e - 0x201) + (keybits / 8) + 1; - buf[6] = adj >> 8; - buf[7] = adj & 0xff; + buf[6] = (uint8_t)(adj >> 8); + buf[7] = (uint8_t)(adj & 0xff); adj = (0x0222 - 0x201) + (keybits / 8) + 1; - buf[0xc3] = adj >> 8; - buf[0xc4] = adj & 0xff; + buf[0xc3] = (uint8_t)(adj >> 8); + buf[0xc4] = (uint8_t)(adj & 0xff); adj = (0x020f - 0x201) + (keybits / 8) + 1; - buf[0xd6] = adj >> 8; - buf[0xd7] = adj & 0xff; + buf[0xd6] = (uint8_t)(adj >> 8); + buf[0xd7] = (uint8_t)(adj & 0xff); adj = (0x020a - 0x201) + (keybits / 8) + 1; - buf[0xdb] = adj >> 8; - buf[0xdc] = adj & 0xff; + buf[0xdb] = (uint8_t)(adj >> 8); + buf[0xdc] = (uint8_t)(adj & 0xff); - *p++ = ((keybits / 8) + 1) >> 8; - *p++ = ((keybits / 8) + 1) & 0xff; + *p++ = (uint8_t)(((keybits / 8) + 1) >> 8); + *p++ = (uint8_t)(((keybits / 8) + 1) & 0xff); /* we need to drop 1 + (keybits / 8) bytes of n in here, 00 + key */ @@ -524,8 +524,8 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, p += SAN_A_LENGTH; memcpy(p, ss_cert_sig_leadin, sizeof(ss_cert_sig_leadin)); - p[17] = ((keybits / 8) + 1) >> 8; - p[18] = ((keybits / 8) + 1) & 0xff; + p[17] = (uint8_t)(((keybits / 8) + 1) >> 8); + p[18] = (uint8_t)(((keybits / 8) + 1) & 0xff); p += sizeof(ss_cert_sig_leadin); @@ -534,7 +534,7 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, if (lws_genhash_init(&hash_ctx, LWS_GENHASH_TYPE_SHA256)) goto bail2; - if (lws_genhash_update(&hash_ctx, buf, lws_ptr_diff(p, buf))) { + if (lws_genhash_update(&hash_ctx, buf, lws_ptr_diff_size_t(p, buf))) { lws_genhash_destroy(&hash_ctx, NULL); goto bail2; @@ -545,16 +545,16 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, /* sign the hash */ n = lws_genrsa_hash_sign(&ctx, digest, LWS_GENHASH_TYPE_SHA256, p, - buflen - lws_ptr_diff(p, buf)); + (size_t)((size_t)buflen - lws_ptr_diff_size_t(p, buf))); if (n < 0) goto bail2; p += n; - pkey_asn1 = lws_malloc(pkey_asn1_len, "mbed crt tmp"); + pkey_asn1 = lws_malloc((unsigned int)pkey_asn1_len, "mbed crt tmp"); if (!pkey_asn1) goto bail2; - m = lws_genrsa_render_pkey_asn1(&ctx, 1, pkey_asn1, pkey_asn1_len); + m = lws_genrsa_render_pkey_asn1(&ctx, 1, pkey_asn1, (size_t)pkey_asn1_len); if (m < 0) { lws_free(pkey_asn1); goto bail2; @@ -627,7 +627,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], mbedtls_pk_context mpk; int buf_size = 4096, n; char subject[200], *p = subject, *end = p + sizeof(subject) - 1; - uint8_t *buf = malloc(buf_size); /* malloc because given to user code */ + uint8_t *buf = malloc((unsigned int)buf_size); /* malloc because given to user code */ if (!buf) return -1; @@ -641,7 +641,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], } n = mbedtls_rsa_gen_key(mbedtls_pk_rsa(mpk), _rngf, context, - lws_plat_recommended_rsa_bits(), 65537); + (unsigned int)lws_plat_recommended_rsa_bits(), 65537); if (n) { lwsl_notice("%s: failed to generate keys\n", __func__); @@ -654,7 +654,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], if (p != subject) *p++ = ','; if (elements[n]) - p += lws_snprintf(p, end - p, "%s=%s", x5[n], + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%s=%s", x5[n], elements[n]); } @@ -669,7 +669,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], * return value to determine where you should start * using the buffer */ - n = mbedtls_x509write_csr_der(&csr, buf, buf_size, _rngf, context); + n = mbedtls_x509write_csr_der(&csr, buf, (size_t)buf_size, _rngf, context); if (n < 0) { lwsl_notice("%s: write csr der failed\n", __func__); goto fail1; @@ -677,7 +677,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], /* we have it in DER, we need it in b64URL */ - n = lws_jws_base64_enc((char *)(buf + buf_size) - n, n, + n = lws_jws_base64_enc((char *)(buf + buf_size) - n, (size_t)n, (char *)dcsr, csr_len); if (n < 0) goto fail1; @@ -688,7 +688,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], * one step */ - if (mbedtls_pk_write_key_pem(&mpk, buf, buf_size)) { + if (mbedtls_pk_write_key_pem(&mpk, buf, (size_t)buf_size)) { lwsl_notice("write key pem failed\n"); goto fail1; } diff --git a/lib/tls/mbedtls/mbedtls-ssl.c b/lib/tls/mbedtls/mbedtls-ssl.c index 91aab7e90..daf515255 100644 --- a/lib/tls/mbedtls/mbedtls-ssl.c +++ b/lib/tls/mbedtls/mbedtls-ssl.c @@ -42,7 +42,7 @@ lws_ssl_destroy(struct lws_vhost *vhost) } int -lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, size_t len) { struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; @@ -54,7 +54,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); errno = 0; - n = SSL_read(wsi->tls.ssl, buf, len); + n = SSL_read(wsi->tls.ssl, buf, (int)len); #if defined(LWS_PLAT_FREERTOS) if (!n && errno == LWS_ENOTCONN) { lwsl_debug("%s: SSL_read ENOTCONN\n", lws_wsi_tag(wsi)); @@ -115,11 +115,11 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) lwsl_hexdump_notice(buf, n); #endif - lws_stats_bump(pt, LWSSTATS_B_READ, n); + lws_stats_bump(pt, LWSSTATS_B_READ, (uint64_t)n); #if defined(LWS_WITH_SERVER_STATUS) if (wsi->a.vhost) - wsi->a.vhost->conn_stats.rx += n; + wsi->a.vhost->conn_stats.rx = wsi->a.vhost->conn_stats.rx + (unsigned long long)n; #endif #if defined(LWS_WITH_DETAILED_LATENCY) if (context->detailed_latency_cb) { @@ -139,7 +139,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) * Because these won't signal at the network layer with POLLIN * and if we don't realize, this data will sit there forever */ - if (n != len) + if (n != (int)len) goto bail; if (!wsi->tls.ssl) goto bail; @@ -168,7 +168,7 @@ lws_ssl_pending(struct lws *wsi) } int -lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, size_t len) { int n, m; @@ -178,14 +178,14 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) * paths before sending data into the tls tunnel, where you can dump it * and see what is being sent. */ - lwsl_notice("%s: len %d\n", __func__, len); + lwsl_notice("%s: len %d\n", __func__, (int)len); lwsl_hexdump_notice(buf, len); #endif if (!wsi->tls.ssl) return lws_ssl_capable_write_no_ssl(wsi, buf, len); - n = SSL_write(wsi->tls.ssl, buf, len); + n = SSL_write(wsi->tls.ssl, buf, (int)len); if (n > 0) return n; diff --git a/lib/tls/mbedtls/mbedtls-x509.c b/lib/tls/mbedtls/mbedtls-x509.c index 54d47b1ed..523d55386 100644 --- a/lib/tls/mbedtls/mbedtls-x509.c +++ b/lib/tls/mbedtls/mbedtls-x509.c @@ -80,7 +80,7 @@ lws_tls_mbedtls_get_x509_name(mbedtls_x509_name *name, memcpy(&buf->ns.name[0], name->val.p, name->val.len); buf->ns.name[name->val.len] = '\0'; - buf->ns.len = name->val.len; + buf->ns.len = (int)name->val.len; return 0; } @@ -280,7 +280,7 @@ int lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, const char *curves, int rsa_min_bits) { - int kt = mbedtls_pk_get_type(&x509->cert.pk), n, count = 0, ret = -1; + int kt = (int)mbedtls_pk_get_type(&x509->cert.pk), n, count = 0, ret = -1; mbedtls_rsa_context *rsactx; mbedtls_ecp_keypair *ecpctx; mbedtls_mpi *mpi[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; @@ -315,7 +315,7 @@ lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, mpi[LWS_GENCRYPTO_EC_KEYEL_Y] = &ecpctx->Q.Y; if (lws_genec_confirm_curve_allowed_by_tls_id(curves, - ecpctx->grp.id, jwk)) + (int)ecpctx->grp.id, jwk)) /* already logged */ goto bail; @@ -335,7 +335,7 @@ lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); if (!jwk->e[n].buf) goto bail; - jwk->e[n].len = mbedtls_mpi_size(mpi[n]); + jwk->e[n].len = (uint32_t)mbedtls_mpi_size(mpi[n]); mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); } @@ -363,8 +363,8 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, n = 0; if (passphrase) - n = strlen(passphrase); - n = mbedtls_pk_parse_key(&pk, pem, len, (uint8_t *)passphrase, n); + n = (int)strlen(passphrase); + n = mbedtls_pk_parse_key(&pk, pem, len, (uint8_t *)passphrase, (unsigned int)n); if (n) { lwsl_err("%s: parse PEM key failed: -0x%x\n", __func__, -n); @@ -410,7 +410,7 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); if (!jwk->e[n].buf) goto bail; - jwk->e[n].len = mbedtls_mpi_size(mpi[n]); + jwk->e[n].len = (uint32_t)mbedtls_mpi_size(mpi[n]); mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); } diff --git a/lib/tls/mbedtls/wrapper/library/ssl_lib.c b/lib/tls/mbedtls/wrapper/library/ssl_lib.c index f9c671177..54159ed25 100644 --- a/lib/tls/mbedtls/wrapper/library/ssl_lib.c +++ b/lib/tls/mbedtls/wrapper/library/ssl_lib.c @@ -834,7 +834,7 @@ void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len) { SSL_ASSERT3(ctx); - ctx->read_buffer_len = len; + ctx->read_buffer_len = (int)len; } /** @@ -845,7 +845,7 @@ void SSL_set_default_read_buffer_len(SSL *ssl, size_t len) SSL_ASSERT3(ssl); SSL_ASSERT3(len); - SSL_METHOD_CALL(set_bufflen, ssl, len); + SSL_METHOD_CALL(set_bufflen, ssl, (int)len); } /** @@ -1167,7 +1167,7 @@ _openssl_alpn_to_mbedtls(struct alpn_ctx *ac, char ***palpn_protos) /* allocate space for count + 1 pointers and the data afterwards */ - alpn_protos = ssl_mem_zalloc((count + 1) * sizeof(char *) + ac->len + 1); + alpn_protos = ssl_mem_zalloc((unsigned int)(count + 1) * sizeof(char *) + ac->len + 1); if (!alpn_protos) return; @@ -1175,7 +1175,7 @@ _openssl_alpn_to_mbedtls(struct alpn_ctx *ac, char ***palpn_protos) /* convert to mbedtls format */ - q = (unsigned char *)alpn_protos + (count + 1) * sizeof(char *); + q = (unsigned char *)alpn_protos + (unsigned int)(count + 1) * sizeof(char *); p = ac->data; count = 0; diff --git a/lib/tls/mbedtls/wrapper/library/ssl_pkey.c b/lib/tls/mbedtls/wrapper/library/ssl_pkey.c index 567a33e2c..7c92b699c 100644 --- a/lib/tls/mbedtls/wrapper/library/ssl_pkey.c +++ b/lib/tls/mbedtls/wrapper/library/ssl_pkey.c @@ -100,7 +100,7 @@ EVP_PKEY *d2i_PrivateKey(int type, m = 1; } - ret = EVP_PKEY_METHOD_CALL(load, pkey, *pp, length); + ret = EVP_PKEY_METHOD_CALL(load, pkey, *pp, (int)length); if (ret) { SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "EVP_PKEY_METHOD_CALL(load) return %d", ret); goto failed2; diff --git a/lib/tls/mbedtls/wrapper/library/ssl_x509.c b/lib/tls/mbedtls/wrapper/library/ssl_x509.c index 09a6afdc5..03bceb522 100644 --- a/lib/tls/mbedtls/wrapper/library/ssl_x509.c +++ b/lib/tls/mbedtls/wrapper/library/ssl_x509.c @@ -104,7 +104,7 @@ X509* d2i_X509(X509 **cert, const unsigned char *buffer, long len) m = 1; } - ret = X509_METHOD_CALL(load, x, buffer, len); + ret = X509_METHOD_CALL(load, x, buffer, (int)len); if (ret) { SSL_DEBUG(SSL_PKEY_ERROR_LEVEL, "X509_METHOD_CALL(load) return %d", ret); goto failed2; diff --git a/lib/tls/mbedtls/wrapper/platform/ssl_pm.c b/lib/tls/mbedtls/wrapper/platform/ssl_pm.c index eb4a088e2..2c810d968 100755 --- a/lib/tls/mbedtls/wrapper/platform/ssl_pm.c +++ b/lib/tls/mbedtls/wrapper/platform/ssl_pm.c @@ -123,7 +123,7 @@ int ssl_pm_new(SSL *ssl) if (!ssl->ctx->read_buffer_len) ssl->ctx->read_buffer_len = 2048; - max_content_len = ssl->ctx->read_buffer_len; + max_content_len = (unsigned int)ssl->ctx->read_buffer_len; // printf("ssl->ctx->read_buffer_len = %d ++++++++++++++++++++\n", ssl->ctx->read_buffer_len); mbedtls_net_init(&ssl_pm->fd); @@ -405,7 +405,7 @@ int ssl_pm_read(SSL *ssl, void *buffer, int len) int ret; struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, len); + ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, (size_t)len); if (ret < 0) { // lwsl_notice("%s: mbedtls_ssl_read says -0x%x\n", __func__, -ret); SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "mbedtls_ssl_read() return -0x%x", -ret); @@ -428,7 +428,7 @@ int ssl_pm_send(SSL *ssl, const void *buffer, int len) int ret; struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - ret = mbedtls_ssl_write(&ssl_pm->ssl, buffer, len); + ret = mbedtls_ssl_write(&ssl_pm->ssl, buffer, (size_t)len); /* * We can get a positive number, which may be less than len... that * much was sent successfully and you can call again to send more. @@ -474,7 +474,7 @@ int ssl_pm_pending(const SSL *ssl) { struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm; - return mbedtls_ssl_get_bytes_avail(&ssl_pm->ssl); + return (int)mbedtls_ssl_get_bytes_avail(&ssl_pm->ssl); } void ssl_pm_set_fd(SSL *ssl, int fd, int mode) @@ -654,21 +654,21 @@ int x509_pm_load(X509 *x, const unsigned char *buffer, int len) mbedtls_x509_crt_init(x509_pm->x509_crt); if (buffer[0] != 0x30) { - load_buf = ssl_mem_malloc(len + 1); + load_buf = ssl_mem_malloc((unsigned int)len + 1); if (!load_buf) { SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (load_buf)"); goto failed; } - ssl_memcpy(load_buf, buffer, len); + ssl_memcpy(load_buf, buffer, (unsigned int)len); load_buf[len] = '\0'; - ret = mbedtls_x509_crt_parse(x509_pm->x509_crt, load_buf, len + 1); + ret = mbedtls_x509_crt_parse(x509_pm->x509_crt, load_buf, (unsigned int)len + 1); ssl_mem_free(load_buf); } else { // printf("parsing as der\n"); - ret = mbedtls_x509_crt_parse_der(x509_pm->x509_crt, buffer, len); + ret = mbedtls_x509_crt_parse_der(x509_pm->x509_crt, buffer, (unsigned int)len); } if (ret) { @@ -737,18 +737,18 @@ int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len) } } - load_buf = ssl_mem_malloc(len + 1); + load_buf = ssl_mem_malloc((unsigned int)len + 1); if (!load_buf) { SSL_DEBUG(SSL_PLATFORM_ERROR_LEVEL, "no enough memory > (load_buf)"); goto failed; } - ssl_memcpy(load_buf, buffer, len); + ssl_memcpy(load_buf, buffer, (unsigned int)len); load_buf[len] = '\0'; mbedtls_pk_init(pkey_pm->pkey); - ret = mbedtls_pk_parse_key(pkey_pm->pkey, load_buf, len + 1, NULL, 0); + ret = mbedtls_pk_parse_key(pkey_pm->pkey, load_buf, (unsigned int)len + 1, NULL, 0); ssl_mem_free(load_buf); if (ret) { @@ -770,7 +770,7 @@ no_mem: void ssl_pm_set_bufflen(SSL *ssl, int len) { - max_content_len = len; + max_content_len = (unsigned int)len; } long ssl_pm_get_verify_result(const SSL *ssl) @@ -867,7 +867,7 @@ void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data, *data = (const unsigned char *)alp; if (alp) - *len = strlen(alp); + *len = (unsigned int)strlen(alp); else *len = 0; #endif diff --git a/lib/tls/openssl/lws-genaes.c b/lib/tls/openssl/lws-genaes.c index 6ccb55dc3..bc4d7d82d 100644 --- a/lib/tls/openssl/lws-genaes.c +++ b/lib/tls/openssl/lws-genaes.c @@ -214,12 +214,12 @@ lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op, case LWS_GAESO_ENC: n = EVP_EncryptInit_ex(ctx->ctx, ctx->cipher, ctx->engine, NULL, NULL); - EVP_CIPHER_CTX_set_padding(ctx->ctx, padding); + EVP_CIPHER_CTX_set_padding(ctx->ctx, (int)padding); break; case LWS_GAESO_DEC: n = EVP_DecryptInit_ex(ctx->ctx, ctx->cipher, ctx->engine, NULL, NULL); - EVP_CIPHER_CTX_set_padding(ctx->ctx, padding); + EVP_CIPHER_CTX_set_padding(ctx->ctx, (int)padding); break; } if (!n) { @@ -264,7 +264,7 @@ lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen) } } if (ctx->mode == LWS_GAESM_CBC) - memcpy(tag, buf, outl); + memcpy(tag, buf, (unsigned int)outl); break; @@ -298,7 +298,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, if (!ctx->init) { - EVP_CIPHER_CTX_set_key_length(ctx->ctx, ctx->k->len); + EVP_CIPHER_CTX_set_key_length(ctx->ctx, (int)ctx->k->len); if (ctx->mode == LWS_GAESM_GCM) { n = EVP_CIPHER_CTX_ctrl(ctx->ctx, EVP_CTRL_GCM_SET_IVLEN, @@ -307,7 +307,7 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx, lwsl_err("%s: SET_IVLEN failed\n", __func__); return -1; } - memcpy(ctx->tag, stream_block_16, taglen); + memcpy(ctx->tag, stream_block_16, (unsigned int)taglen); ctx->taglen = taglen; } diff --git a/lib/tls/openssl/lws-genec.c b/lib/tls/openssl/lws-genec.c index 573a6c0ce..d5f69c374 100644 --- a/lib/tls/openssl/lws-genec.c +++ b/lib/tls/openssl/lws-genec.c @@ -111,13 +111,13 @@ lws_genec_eckey_import(int nid, EVP_PKEY *pkey, struct lws_gencrypto_keyelem *el */ bn_x = BN_bin2bn(el[LWS_GENCRYPTO_EC_KEYEL_X].buf, - el[LWS_GENCRYPTO_EC_KEYEL_X].len, NULL); + (int)el[LWS_GENCRYPTO_EC_KEYEL_X].len, NULL); if (!bn_x) { lwsl_err("%s: BN_bin2bn (x) fail\n", __func__); goto bail; } bn_y = BN_bin2bn(el[LWS_GENCRYPTO_EC_KEYEL_Y].buf, - el[LWS_GENCRYPTO_EC_KEYEL_Y].len, NULL); + (int)el[LWS_GENCRYPTO_EC_KEYEL_Y].len, NULL); if (!bn_y) { lwsl_err("%s: BN_bin2bn (y) fail\n", __func__); goto bail1; @@ -135,7 +135,7 @@ lws_genec_eckey_import(int nid, EVP_PKEY *pkey, struct lws_gencrypto_keyelem *el if (el[LWS_GENCRYPTO_EC_KEYEL_D].len) { bn_d = BN_bin2bn(el[LWS_GENCRYPTO_EC_KEYEL_D].buf, - el[LWS_GENCRYPTO_EC_KEYEL_D].len, NULL); + (int)el[LWS_GENCRYPTO_EC_KEYEL_D].len, NULL); if (!bn_d) { lwsl_err("%s: BN_bin2bn (d) fail\n", __func__); goto bail; @@ -383,7 +383,7 @@ lws_genec_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, if (!el[n].buf) goto bail2; - m = BN_bn2binpad(bn[n - 1], el[n].buf, el[n].len); + m = BN_bn2binpad(bn[n - 1], el[n].buf, (int32_t)el[n].len); if ((uint32_t)m != el[n].len) goto bail2; } @@ -651,7 +651,7 @@ lws_genecdh_compute_shared_secret(struct lws_genec_ctx *ctx, uint8_t *ss, len = (EC_GROUP_get_degree(EC_KEY_get0_group(eckey[LDHS_OURS])) + 7) / 8; if (len <= *ss_len) { - *ss_len = ECDH_compute_key(ss, len, + *ss_len = ECDH_compute_key(ss, (unsigned int)len, EC_KEY_get0_public_key(eckey[LDHS_THEIRS]), eckey[LDHS_OURS], NULL); ret = -(*ss_len < 0); diff --git a/lib/tls/openssl/lws-genhash.c b/lib/tls/openssl/lws-genhash.c index 743643986..ecfa54938 100644 --- a/lib/tls/openssl/lws-genhash.c +++ b/lib/tls/openssl/lws-genhash.c @@ -34,7 +34,7 @@ int lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type) { - ctx->type = type; + ctx->type = (uint8_t)type; ctx->mdctx = EVP_MD_CTX_create(); if (!ctx->mdctx) return 1; @@ -104,7 +104,7 @@ lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, return -1; ctx->evp_type = 0; - ctx->type = type; + ctx->type = (uint8_t)type; switch (type) { case LWS_GENHMAC_TYPE_SHA256: diff --git a/lib/tls/openssl/lws-genrsa.c b/lib/tls/openssl/lws-genrsa.c index d2797e7ed..ad8dbd544 100644 --- a/lib/tls/openssl/lws-genrsa.c +++ b/lib/tls/openssl/lws-genrsa.c @@ -93,7 +93,7 @@ lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_gencrypto_keyelem *el, */ for (n = 0; n < 5; n++) { - ctx->bn[n] = BN_bin2bn(el[n].buf, el[n].len, NULL); + ctx->bn[n] = BN_bin2bn(el[n].buf, (int)el[n].len, NULL); if (!ctx->bn[n]) { lwsl_notice("mpi load failed\n"); goto bail; @@ -193,10 +193,10 @@ lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, for (n = 0; n < 5; n++) if (BN_num_bytes(mpi[n])) { el[n].buf = lws_malloc( - BN_num_bytes(mpi[n]), "genrsakey"); + (unsigned int)BN_num_bytes(mpi[n]), "genrsakey"); if (!el[n].buf) goto cleanup; - el[n].len = BN_num_bytes(mpi[n]); + el[n].len = (unsigned int)BN_num_bytes(mpi[n]); BN_bn2bin(mpi[n], el[n].buf); } } @@ -293,7 +293,7 @@ lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, switch(ctx->mode) { case LGRSAM_PKCS1_1_5: - n = RSA_verify(n, in, h, (uint8_t *)sig, (int)sig_len, ctx->rsa); + n = RSA_verify(n, in, (unsigned int)h, (uint8_t *)sig, (unsigned int)sig_len, ctx->rsa); break; case LGRSAM_PKCS1_OAEP_PSS: md = lws_gencrypto_openssl_hash_to_EVP_MD(hash_type); @@ -338,7 +338,7 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, switch(ctx->mode) { case LGRSAM_PKCS1_1_5: - if (RSA_sign(n, in, h, sig, &used, ctx->rsa) != 1) { + if (RSA_sign(n, in, (unsigned int)h, sig, &used, ctx->rsa) != 1) { lwsl_err("%s: RSA_sign failed\n", __func__); goto bail; @@ -368,7 +368,7 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, goto bail; } - if (EVP_DigestSignUpdate(mdctx, in, EVP_MD_size(md))) { + if (EVP_DigestSignUpdate(mdctx, in, (unsigned int)EVP_MD_size(md))) { lwsl_err("%s: EVP_DigestSignUpdate failed\n", __func__); goto bail; @@ -379,14 +379,14 @@ lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, goto bail; } EVP_MD_CTX_free(mdctx); - used = (int)sig_len; + used = (unsigned int)sig_len; break; default: return -1; } - return used; + return (int)used; bail: if (mdctx) diff --git a/lib/tls/openssl/openssl-client.c b/lib/tls/openssl/openssl-client.c index 362779cb2..21d959586 100644 --- a/lib/tls/openssl/openssl-client.c +++ b/lib/tls/openssl/openssl-client.c @@ -108,7 +108,7 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) n = lws_get_context_protocol(wsi->a.context, 0).callback(wsi, LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION, - x509_ctx, ssl, preverify_ok); + x509_ctx, ssl, (unsigned int)preverify_ok); /* keep old behaviour if something wrong with server certs */ /* if ssl error is overruled in callback and cert is ok, @@ -181,8 +181,14 @@ lws_ssl_client_bio_create(struct lws *wsi) wsi->tls.ssl = SSL_new(wsi->a.vhost->tls.ssl_client_ctx); if (!wsi->tls.ssl) { - lwsl_err("SSL_new failed: %s\n", - ERR_error_string(lws_ssl_get_error(wsi, 0), NULL)); + const char *es = ERR_error_string( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif + lws_ssl_get_error(wsi, 0), NULL); + lwsl_err("SSL_new failed: %s\n", es); lws_tls_err_describe_clear(); return -1; } @@ -298,7 +304,7 @@ lws_ssl_client_bio_create(struct lws *wsi) n = lws_alpn_comma_to_openssl(alpn_comma, openssl_alpn, sizeof(openssl_alpn) - 1); - SSL_set_alpn_protos(wsi->tls.ssl, openssl_alpn, n); + SSL_set_alpn_protos(wsi->tls.ssl, openssl_alpn, (unsigned int)n); #endif SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, @@ -329,7 +335,13 @@ lws_ssl_client_bio_create(struct lws *wsi) #if defined(USE_WOLFSSL) (unsigned char *) #endif - data, (int)size) != 1) { + data, +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (int) +#endif + size) != 1) { lwsl_err("%s: use_certificate failed\n", __func__); lws_tls_err_describe_clear(); goto no_client_cert; @@ -353,12 +365,24 @@ lws_ssl_client_bio_create(struct lws *wsi) (unsigned char *) #endif - data, (int)size) != 1 && + data, +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (int) +#endif + size) != 1 && SSL_use_PrivateKey_ASN1(EVP_PKEY_EC, wsi->tls.ssl, #if defined(USE_WOLFSSL) (unsigned char *) #endif - data, (int)size) != 1) { + data, +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (int) +#endif + size) != 1) { lwsl_err("%s: use_privkey failed\n", __func__); lws_tls_err_describe_clear(); goto no_client_cert; @@ -384,7 +408,7 @@ no_client_cert: } enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) +lws_tls_client_connect(struct lws *wsi, char *errbuf, size_t elen) { #if defined(LWS_HAVE_SSL_set_alpn_protos) && \ defined(LWS_HAVE_SSL_get0_alpn_selected) @@ -415,7 +439,7 @@ lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) if (m == SSL_ERROR_SSL) { n = lws_snprintf(errbuf, elen, "connect SSL err %d: ", m); - ERR_error_string_n(m, errbuf + n, elen - n); + ERR_error_string_n((unsigned int)m, errbuf + n, (elen - (unsigned int)n)); return LWS_SSL_CAPABLE_ERROR; } @@ -451,19 +475,20 @@ lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) } int -lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) +lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, size_t ebuf_len) { #if !defined(USE_WOLFSSL) struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; char *p = (char *)&pt->serv_buf[0]; + const char *es; char *sb = p; - int n; + long n; errno = 0; ERR_clear_error(); n = SSL_get_verify_result(wsi->tls.ssl); - lwsl_debug("get_verify says %d\n", n); + lwsl_debug("get_verify says %ld\n", n); if (n == X509_V_OK) return 0; @@ -486,9 +511,16 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) "probably our clock... accepting...\n"); return 0; } + es = ERR_error_string( + #if defined(LWS_WITH_BORINGSSL) + (uint32_t) + #else + (unsigned long) + #endif + n, sb); lws_snprintf(ebuf, ebuf_len, - "server's cert didn't look good, X509_V_ERR = %d: %s\n", - n, ERR_error_string(n, sb)); + "server's cert didn't look good, X509_V_ERR = %ld: %s\n", + n, es); lwsl_info("%s\n", ebuf); lws_tls_err_describe_clear(); @@ -504,7 +536,11 @@ lws_tls_client_vhost_extra_cert_mem(struct lws_vhost *vh, const uint8_t *der, size_t der_len) { X509_STORE *st; +#if defined(USE_WOLFSSL) + X509 *x = d2i_X509(NULL, &der, (int)der_len); +#else X509 *x = d2i_X509(NULL, &der, (long)der_len); +#endif int n; if (!x) { @@ -567,10 +603,18 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, #endif if (!method) { + const char *es; + error = ERR_get_error(); + es = ERR_error_string( + #if defined(LWS_WITH_BORINGSSL) + (uint32_t) + #else + (unsigned long) + #endif + error, (char *)vh->context->pt[0].serv_buf); lwsl_err("problem creating ssl method %lu: %s\n", - error, ERR_error_string(error, - (char *)vh->context->pt[0].serv_buf)); + error, es); return 1; } @@ -666,10 +710,18 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, ERR_clear_error(); vh->tls.ssl_client_ctx = SSL_CTX_new(method); if (!vh->tls.ssl_client_ctx) { + const char *es; + error = ERR_get_error(); + es = ERR_error_string( + #if defined(LWS_WITH_BORINGSSL) + (uint32_t) + #else + (unsigned long) + #endif + error, (char *)vh->context->pt[0].serv_buf); lwsl_err("problem creating ssl context %lu: %s\n", - error, ERR_error_string(error, - (char *)vh->context->pt[0].serv_buf)); + error, es); return 1; } @@ -707,12 +759,24 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, if (info->ssl_client_options_set) SSL_CTX_set_options(vh->tls.ssl_client_ctx, +#if !defined(USE_WOLFSSL) +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif +#endif info->ssl_client_options_set); /* SSL_clear_options introduced in 0.9.8m */ #if (OPENSSL_VERSION_NUMBER >= 0x009080df) && !defined(USE_WOLFSSL) if (info->ssl_client_options_clear) SSL_CTX_clear_options(vh->tls.ssl_client_ctx, +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif info->ssl_client_options_clear); #endif @@ -774,7 +838,11 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, } up = up1; +#if defined(USE_WOLFSSL) + client_CA = d2i_X509(NULL, &up, (int)amount); +#else client_CA = d2i_X509(NULL, &up, (long)amount); +#endif if (!client_CA) { lwsl_err("%s: d2i_X509 failed\n", __func__); lwsl_hexdump_notice(up1, (size_t)amount); @@ -836,7 +904,13 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, return 1; } - n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, (int)flen, p); + n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (int) +#endif + flen, p); if (n < 1) { lwsl_err("%s: problem interpreting client cert\n", __func__); @@ -882,11 +956,21 @@ lws_tls_client_create_vhost_context(struct lws_vhost *vh, } n = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_RSA, vh->tls.ssl_client_ctx, p, - (long)(lws_intptr_t)flen); +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (long)(lws_intptr_t) +#endif + flen); if (n != 1) n = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_EC, vh->tls.ssl_client_ctx, p, - (long)(lws_intptr_t)flen); +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (long)(lws_intptr_t) +#endif + flen); lws_free_set_NULL(p); diff --git a/lib/tls/openssl/openssl-server.c b/lib/tls/openssl/openssl-server.c index 4e0c380e5..c4c36db0c 100644 --- a/lib/tls/openssl/openssl-server.c +++ b/lib/tls/openssl/openssl-server.c @@ -61,7 +61,7 @@ OpenSSL_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) n = wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, - x509_ctx, ssl, preverify_ok); + x509_ctx, ssl, (unsigned int)preverify_ok); /* convert return code from 0 = OK to 1 = OK */ return !n; @@ -172,7 +172,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, #if OPENSSL_VERSION_NUMBER >= 0x10100000L int ret; #endif - int n = lws_tls_generic_cert_checks(vhost, cert, private_key), m; + int n = (int)lws_tls_generic_cert_checks(vhost, cert, private_key), m; if (!cert && !private_key) n = LWS_TLS_EXTANT_ALTERNATIVE; @@ -210,10 +210,18 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, /* set the local certificate from CertFile */ m = SSL_CTX_use_certificate_chain_file(vhost->tls.ssl_ctx, cert); if (m != 1) { + const char *s; error = ERR_get_error(); + + s = ERR_error_string( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#endif + error, + (char *)vhost->context->pt[0].serv_buf); + lwsl_err("problem getting cert '%s' %lu: %s\n", - cert, error, ERR_error_string(error, - (char *)vhost->context->pt[0].serv_buf)); + cert, error, s); return 1; } @@ -222,11 +230,16 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, /* set the private key from KeyFile */ if (SSL_CTX_use_PrivateKey_file(vhost->tls.ssl_ctx, private_key, SSL_FILETYPE_PEM) != 1) { + const char *s; error = ERR_get_error(); + s = ERR_error_string( + #if defined(LWS_WITH_BORINGSSL) + (uint32_t) + #endif + error, + (char *)vhost->context->pt[0].serv_buf); lwsl_err("ssl problem getting key '%s' %lu: %s\n", - private_key, error, - ERR_error_string(error, - (char *)vhost->context->pt[0].serv_buf)); + private_key, error, s); return 1; } } else { @@ -252,7 +265,13 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, } #if !defined(USE_WOLFSSL) - ret = SSL_CTX_use_certificate_ASN1(vhost->tls.ssl_ctx, (int)flen, p); + ret = SSL_CTX_use_certificate_ASN1(vhost->tls.ssl_ctx, +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (int) +#endif + flen, p); #else ret = wolfSSL_CTX_use_certificate_buffer(vhost->tls.ssl_ctx, (uint8_t *)p, (int)flen, @@ -275,11 +294,21 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, #if !defined(USE_WOLFSSL) ret = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_RSA, vhost->tls.ssl_ctx, p, - (long)(long long)flen); +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (long)(long long) +#endif + flen); if (ret != 1) { ret = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_EC, vhost->tls.ssl_ctx, p, - (long)(long long)flen); +#if defined(LWS_WITH_BORINGSSL) + (size_t) +#else + (long)(long long) +#endif + flen); } #else ret = wolfSSL_CTX_use_PrivateKey_buffer(vhost->tls.ssl_ctx, p, flen, @@ -337,7 +366,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi, (long)(long long)flen) != 1) { #else if (wolfSSL_CTX_use_PrivateKey_buffer(vhost->tls.ssl_ctx, p, - flen, WOLFSSL_FILETYPE_ASN1) != 1) { + (long)flen, WOLFSSL_FILETYPE_ASN1) != 1) { #endif lwsl_notice("unable to use memory privkey\n"); @@ -476,18 +505,32 @@ lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info, SSL_METHOD *method = (SSL_METHOD *)SSLv23_server_method(); if (!method) { + const char *s; error = ERR_get_error(); + s = ERR_error_string( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#endif + error, + (char *)vhost->context->pt[0].serv_buf); + lwsl_err("problem creating ssl method %lu: %s\n", - error, ERR_error_string(error, - (char *)vhost->context->pt[0].serv_buf)); + error, s); return 1; } vhost->tls.ssl_ctx = SSL_CTX_new(method); /* create context */ if (!vhost->tls.ssl_ctx) { + const char *s; + error = ERR_get_error(); + s = ERR_error_string( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#endif + error, + (char *)vhost->context->pt[0].serv_buf); lwsl_err("problem creating ssl context %lu: %s\n", - error, ERR_error_string(error, - (char *)vhost->context->pt[0].serv_buf)); + error, s); return 1; } @@ -531,12 +574,27 @@ lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info, } if (info->ssl_options_set) - SSL_CTX_set_options(vhost->tls.ssl_ctx, info->ssl_options_set); + SSL_CTX_set_options(vhost->tls.ssl_ctx, +#if defined(USE_WOLFSSL) + (long) +#else +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif +#endif + info->ssl_options_set); /* SSL_clear_options introduced in 0.9.8m */ #if (OPENSSL_VERSION_NUMBER >= 0x009080df) && !defined(USE_WOLFSSL) if (info->ssl_options_clear) SSL_CTX_clear_options(vhost->tls.ssl_ctx, +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif info->ssl_options_clear); #endif @@ -991,7 +1049,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], if (*p == '/') *csr++ = '_'; else - *csr++ = *p; + *csr++ = (uint8_t)*p; p++; csr_len--; } @@ -1014,7 +1072,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], goto bail3; } bio_len = BIO_get_mem_data(bio, &p); - *privkey_pem = malloc(bio_len); /* malloc so user code can own / free */ + *privkey_pem = malloc((unsigned long)bio_len); /* malloc so user code can own / free */ *privkey_len = (size_t)bio_len; if (!*privkey_pem) { lwsl_notice("%s: need %ld for private key\n", __func__, @@ -1022,7 +1080,7 @@ lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], BIO_free(bio); goto bail3; } - memcpy(*privkey_pem, p, (int)(long long)bio_len); + memcpy(*privkey_pem, p, (unsigned int)(int)(long long)bio_len); BIO_free(bio); ret = lws_ptr_diff(csr, csr_in); diff --git a/lib/tls/openssl/openssl-ssl.c b/lib/tls/openssl/openssl-ssl.c index bcf700c00..7392bb8b6 100644 --- a/lib/tls/openssl/openssl-ssl.c +++ b/lib/tls/openssl/openssl-ssl.c @@ -75,7 +75,7 @@ lws_context_init_ssl_pem_passwd_cb(char *buf, int size, int rwflag, struct lws_context_creation_info * info = (struct lws_context_creation_info *)userdata; - strncpy(buf, info->ssl_private_key_password, size); + strncpy(buf, info->ssl_private_key_password, (unsigned int)size); buf[size - 1] = '\0'; return (int)strlen(buf); @@ -94,7 +94,7 @@ lws_context_init_ssl_pem_passwd_client_cb(char *buf, int size, int rwflag, if (info->client_ssl_private_key_password) p = info->client_ssl_private_key_password; - strncpy(buf, p, size); + strncpy(buf, p, (unsigned int)size); buf[size - 1] = '\0'; return (int)strlen(buf); @@ -200,7 +200,7 @@ lws_ssl_destroy(struct lws_vhost *vhost) } int -lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, size_t len) { struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; @@ -213,7 +213,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) errno = 0; ERR_clear_error(); - n = SSL_read(wsi->tls.ssl, buf, len); + n = SSL_read(wsi->tls.ssl, buf, (int)(ssize_t)len); #if defined(LWS_PLAT_FREERTOS) if (!n && errno == LWS_ENOTCONN) { lwsl_debug("%s: SSL_read ENOTCONN\n", lws_wsi_tag(wsi)); @@ -299,20 +299,20 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) lwsl_hexdump_notice(buf, n); #endif - lws_stats_bump(pt, LWSSTATS_B_READ, n); + lws_stats_bump(pt, LWSSTATS_B_READ, (unsigned int)n); #if defined(LWS_WITH_SERVER_STATUS) if (wsi->a.vhost) - wsi->a.vhost->conn_stats.rx += n; + wsi->a.vhost->conn_stats.rx = (unsigned long long)(wsi->a.vhost->conn_stats.rx + (unsigned long long)(long long)n); #endif #if defined(LWS_WITH_DETAILED_LATENCY) if (context->detailed_latency_cb) { wsi->detlat.req_size = len; - wsi->detlat.acc_size = n; + wsi->detlat.acc_size = (unsigned int)n; wsi->detlat.type = LDLT_READ; wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = - lws_now_usecs() - pt->ust_left_poll; + (uint32_t)(lws_now_usecs() - pt->ust_left_poll); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); } @@ -325,7 +325,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) * Because these won't signal at the network layer with POLLIN * and if we don't realize, this data will sit there forever */ - if (n != len) + if (n != (int)(ssize_t)len) goto bail; if (!wsi->tls.ssl) goto bail; @@ -354,7 +354,7 @@ lws_ssl_pending(struct lws *wsi) } int -lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) +lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, size_t len) { int n, m; @@ -373,7 +373,7 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) errno = 0; ERR_clear_error(); - n = SSL_write(wsi->tls.ssl, buf, len); + n = SSL_write(wsi->tls.ssl, buf, (int)(ssize_t)len); if (n > 0) return n; @@ -394,7 +394,7 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) } } - lwsl_debug("%s failed: %s\n",__func__, ERR_error_string(m, NULL)); + lwsl_debug("%s failed: %s\n",__func__, ERR_error_string((unsigned int)m, NULL)); lws_tls_err_describe_clear(); wsi->socket_is_permanently_unusable = 1; diff --git a/lib/tls/openssl/openssl-tls.c b/lib/tls/openssl/openssl-tls.c index 0b8bfe558..e6ac94585 100644 --- a/lib/tls/openssl/openssl-tls.c +++ b/lib/tls/openssl/openssl-tls.c @@ -78,7 +78,11 @@ lws_tls_err_describe_clear(void) if (!l) break; - ERR_error_string_n(l, buf, sizeof(buf)); + ERR_error_string_n( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#endif + l, buf, sizeof(buf)); lwsl_info(" openssl error: %s\n", buf); } while (l); lwsl_info("\n"); diff --git a/lib/tls/openssl/openssl-x509.c b/lib/tls/openssl/openssl-x509.c index 185a84a8d..c33c7839a 100644 --- a/lib/tls/openssl/openssl-x509.c +++ b/lib/tls/openssl/openssl-x509.c @@ -136,7 +136,7 @@ lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, case LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY: { #ifndef USE_WOLFSSL - size_t klen = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), NULL); + size_t klen = (unsigned int)i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), NULL); uint8_t *tmp, *ptmp; if (!klen || klen > len) @@ -436,7 +436,7 @@ lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, for (; n < count; n++) { if (!mpi[n]) continue; - jwk->e[n].len = BN_num_bytes(mpi[n]); + jwk->e[n].len = (unsigned int)BN_num_bytes(mpi[n]); jwk->e[n].buf = lws_malloc(jwk->e[n].len, "certkeyimp"); if (!jwk->e[n].buf) { if (id == NID_X9_62_id_ecPublicKey) { @@ -475,14 +475,14 @@ static int lws_x509_jwk_privkey_pem_pp_cb(char *buf, int size, int rwflag, void *u) { const char *pp = (const char *)u; - int n = (int)strlen(pp); + size_t n = strlen(pp); - if (n > size - 1) + if ((int)n > size - 1) return -1; memcpy(buf, pp, n + 1); - return n; + return (int)n; } int @@ -538,13 +538,13 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, /* TODO.. check public curve / group + point */ - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len = n; - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf = lws_malloc(n, "ec"); + jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len = (unsigned int)n; + jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf = lws_malloc((unsigned int)n, "ec"); if (!jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf) goto bail1; m = BN_bn2binpad(cmpi, jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len); + (int32_t)jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len); if ((unsigned int)m != (unsigned int)BN_num_bytes(cmpi)) goto bail1; @@ -589,10 +589,10 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, /* then check that n & e match what we got from the cert */ dummy[2] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].buf, - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len, + (int32_t)jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len, NULL); dummy[3] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].buf, - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].len, + (int32_t)jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].len, NULL); m = BN_cmp(dummy[2], dummy[0]) | BN_cmp(dummy[3], dummy[1]); @@ -607,8 +607,8 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, /* accept d from the PEM privkey into the JWK */ - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].len = n; - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf = lws_malloc(n, "privjk"); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].len = (unsigned int)n; + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf = lws_malloc((unsigned int)n, "privjk"); if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf) goto bail1; @@ -616,16 +616,16 @@ lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, /* accept p and q from the PEM privkey into the JWK */ - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].len = BN_num_bytes(dummy[4]); - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf = lws_malloc(n, "privjk"); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].len = (unsigned int)BN_num_bytes(dummy[4]); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf = lws_malloc((unsigned int)n, "privjk"); if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf) { lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); goto bail1; } BN_bn2bin(dummy[4], jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].len = BN_num_bytes(dummy[5]); - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf = lws_malloc(n, "privjk"); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].len = (unsigned int)BN_num_bytes(dummy[5]); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf = lws_malloc((unsigned int)n, "privjk"); if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf) { lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); diff --git a/lib/tls/private-network.h b/lib/tls/private-network.h index 82444031e..c8b15fd1e 100644 --- a/lib/tls/private-network.h +++ b/lib/tls/private-network.h @@ -81,9 +81,9 @@ struct lws_lws_tls { void lws_context_init_alpn(struct lws_vhost *vhost); int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len); +lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, size_t len); int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len); +lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, size_t len); int LWS_WARN_UNUSED_RESULT lws_ssl_pending(struct lws *wsi); int LWS_WARN_UNUSED_RESULT @@ -101,10 +101,9 @@ LWS_VISIBLE void lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi); int lws_ssl_client_bio_create(struct lws *wsi); + int -lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len); -int -lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len); +lws_ssl_client_connect2(struct lws *wsi, char *errbuf, size_t len); int lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt); int @@ -158,9 +157,9 @@ enum lws_ssl_capable_status __lws_tls_shutdown(struct lws *wsi); enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi, char *errbuf, int len); +lws_tls_client_connect(struct lws *wsi, char *errbuf, size_t len); int -lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len); +lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, size_t ebuf_len); int lws_tls_client_create_vhost_context(struct lws_vhost *vh, const struct lws_context_creation_info *info, diff --git a/lib/tls/tls-client.c b/lib/tls/tls-client.c index 139003964..b8f7a5112 100644 --- a/lib/tls/tls-client.c +++ b/lib/tls/tls-client.c @@ -24,8 +24,8 @@ #include "private-lib-core.h" -int -lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len) +static int +lws_ssl_client_connect1(struct lws *wsi, char *errbuf, size_t len) { int n; @@ -48,7 +48,7 @@ lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len) } int -lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len) +lws_ssl_client_connect2(struct lws *wsi, char *errbuf, size_t len) { int n; diff --git a/lib/tls/tls-network.c b/lib/tls/tls-network.c index b1b438a42..5deab5b6c 100644 --- a/lib/tls/tls-network.c +++ b/lib/tls/tls-network.c @@ -42,8 +42,9 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt) if (wsi->position_in_fds_table >= 0) { - pt->fds[wsi->position_in_fds_table].revents |= - pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; + pt->fds[wsi->position_in_fds_table].revents = (short) + (pt->fds[wsi->position_in_fds_table].revents | + (pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; } @@ -141,10 +142,10 @@ lws_tls_generic_cert_checks(struct lws_vhost *vhost, const char *cert, if (!cert || !private_key) return LWS_TLS_EXTANT_NO; - n = lws_tls_use_any_upgrade_check_extant(cert); + n = (int)lws_tls_use_any_upgrade_check_extant(cert); if (n == LWS_TLS_EXTANT_ALTERNATIVE) return LWS_TLS_EXTANT_ALTERNATIVE; - m = lws_tls_use_any_upgrade_check_extant(private_key); + m = (int)lws_tls_use_any_upgrade_check_extant(private_key); if (m == LWS_TLS_EXTANT_ALTERNATIVE) return LWS_TLS_EXTANT_ALTERNATIVE; @@ -240,17 +241,17 @@ lws_alpn_comma_to_openssl(const char *comma, uint8_t *os, int len) } if (*comma == ',') { - *plen = lws_ptr_diff(os, plen + 1); + *plen = (uint8_t)lws_ptr_diff(os, plen + 1); plen = NULL; comma++; } else { - *os++ = *comma++; + *os++ = (uint8_t)*comma++; len--; } } if (plen) - *plen = lws_ptr_diff(os, plen + 1); + *plen = (uint8_t)lws_ptr_diff(os, plen + 1); *os = 0; diff --git a/lib/tls/tls-server.c b/lib/tls/tls-server.c index 4a66bbe5e..c4983dfd1 100644 --- a/lib/tls/tls-server.c +++ b/lib/tls/tls-server.c @@ -130,6 +130,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; struct lws_vhost *vh; + ssize_t s; int n; if (!LWS_SSL_ENABLED(wsi->a.vhost)) @@ -174,7 +175,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f lws_pt_unlock(pt); lws_set_timeout(wsi, PENDING_TIMEOUT_SSL_ACCEPT, - context->timeout_secs); + (int)context->timeout_secs); lwsl_debug("inserted SSL accept into fds, trying SSL_accept\n"); @@ -193,7 +194,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f * something to read... */ - n = recv(wsi->desc.sockfd, (char *)pt->serv_buf, + s = recv(wsi->desc.sockfd, (char *)pt->serv_buf, context->pt_serv_buf_size, MSG_PEEK); /* * We have LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT.. @@ -220,7 +221,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f * continue with that */ - if (n >= 1 && pt->serv_buf[0] >= ' ') { + if (s >= 1 && pt->serv_buf[0] >= ' ') { /* * TLS content-type for Handshake is 0x16, and * for ChangeCipherSpec Record, it's 0x14 @@ -270,7 +271,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f __func__, wsi->a.vhost->name); goto fail; } - if (!n) { + if (!s) { /* * POLLIN but nothing to read is supposed to * mean the connection is gone, we should @@ -294,7 +295,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f goto fail; } - if (n < 0 && (LWS_ERRNO == LWS_EAGAIN || + if (s < 0 && (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK)) { punt: @@ -353,8 +354,8 @@ punt: if (context->detailed_latency_cb) { wsi->detlat.type = LDLT_TLS_NEG_SERVER; wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = - lws_now_usecs() - - wsi->detlat.earliest_write_req_pre_write; + (uint32_t)(lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write); wsi->detlat.latencies[LAT_DUR_USERCB] = 0; lws_det_lat_cb(wsi->a.context, &wsi->detlat); } @@ -374,7 +375,7 @@ punt: /* OK, we are accepted... give him some time to negotiate */ lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, - context->timeout_secs); + (int)context->timeout_secs); lwsi_set_state(wsi, LRS_ESTABLISHED); if (lws_tls_server_conn_alpn(wsi)) { diff --git a/lib/tls/tls.c b/lib/tls/tls.c index 3021c0c21..b4b43f0e5 100644 --- a/lib/tls/tls.c +++ b/lib/tls/tls.c @@ -94,7 +94,7 @@ lws_context_init_alpn(struct lws_vhost *vhost) lwsl_info(" Server '%s' advertising ALPN: %s\n", vhost->name, alpn_comma); - vhost->tls.alpn_ctx.len = lws_alpn_comma_to_openssl(alpn_comma, + vhost->tls.alpn_ctx.len = (uint8_t)lws_alpn_comma_to_openssl(alpn_comma, vhost->tls.alpn_ctx.data, sizeof(vhost->tls.alpn_ctx.data) - 1); @@ -182,6 +182,7 @@ int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, { FILE *f; size_t s; + ssize_t m; int n = 0; f = fopen(filename, "rb"); @@ -195,11 +196,12 @@ int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, goto bail; } - s = ftell(f); - if (s == (size_t)-1) { + m = ftell(f); + if (m == -1l) { n = 1; goto bail; } + s = (size_t)m; if (fseek(f, 0, SEEK_SET) != 0) { n = 1; @@ -330,7 +332,7 @@ lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, if (filename) *q = '\0'; - *amount = lws_b64_decode_string_len((char *)p, lws_ptr_diff(q, p), + *amount = (unsigned int)lws_b64_decode_string_len((char *)p, lws_ptr_diff(q, p), (char *)pem, (int)(long long)len); *buf = (uint8_t *)pem; @@ -352,8 +354,9 @@ static int lws_tls_extant(const char *name) { /* it exists if we can open it... */ - int fd = open(name, O_RDONLY), n; + int fd = open(name, O_RDONLY); char buf[1]; + ssize_t n; if (fd < 0) return 1; diff --git a/lwsws/main.c b/lwsws/main.c index d62f6fe99..d2b70b71c 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -149,9 +149,9 @@ context_creation(void) info.external_baggage_free_on_destroy = config_strings; info.pt_serv_buf_size = 8192; - info.options = opts | LWS_SERVER_OPTION_VALIDATE_UTF8 | + info.options = (uint64_t)((uint64_t)opts | LWS_SERVER_OPTION_VALIDATE_UTF8 | LWS_SERVER_OPTION_EXPLICIT_VHOSTS | - LWS_SERVER_OPTION_LIBUV; + LWS_SERVER_OPTION_LIBUV); #if defined(LWS_WITH_PLUGINS) if (default_plugin_path) diff --git a/minimal-examples/api-tests/api-test-async-dns/main.c b/minimal-examples/api-tests/api-test-async-dns/main.c index 83b8931ca..49afe0f47 100644 --- a/minimal-examples/api-tests/api-test-async-dns/main.c +++ b/minimal-examples/api-tests/api-test-async-dns/main.c @@ -110,7 +110,7 @@ next_test_cb(lws_sorted_usec_list_t *sul) m = lws_async_dns_query(context, 0, adt[dtest].dns_name, - adt[dtest].recordtype, cb1, NULL, + (adns_query_type_t)adt[dtest].recordtype, cb1, NULL, context); if (m != LADNS_RET_CONTINUING && m != LADNS_RET_FOUND) { lwsl_err("%s: adns 1 failed: %d\n", __func__, m); @@ -169,7 +169,7 @@ cb1(struct lws *wsi_unused, const char *ads, const struct addrinfo *a, int n, #endif } if (alen == adt[dtest - 1].addrlen && - !memcmp(adt[dtest - 1].ads, addr, alen)) { + !memcmp(adt[dtest - 1].ads, addr, (unsigned int)alen)) { ok++; goto next; } @@ -247,10 +247,10 @@ main(int argc, const char **argv) } if (m > 0) { - if (memcmp(ipt[n].b, u, m)) { + if (memcmp(ipt[n].b, u, (unsigned int)m)) { lwsl_err("%s: fail %s compare\n", __func__, ipt[n].test); - lwsl_hexdump_notice(u, m); + lwsl_hexdump_notice(u, (unsigned int)m); fail++; continue; } @@ -281,7 +281,7 @@ main(int argc, const char **argv) if (strcmp(ipt[n].emit_test, buf)) { lwsl_err("%s: fail %s compare\n", __func__, ipt[n].test); - lwsl_hexdump_notice(buf, m); + lwsl_hexdump_notice(buf, (unsigned int)m); fail++; continue; } diff --git a/minimal-examples/api-tests/api-test-fts/main.c b/minimal-examples/api-tests/api-test-fts/main.c index 5003f8c43..d21a19b2f 100644 --- a/minimal-examples/api-tests/api-test-fts/main.c +++ b/minimal-examples/api-tests/api-test-fts/main.c @@ -106,7 +106,7 @@ int main(int argc, char **argv) while (optind < argc) { fi = lws_fts_file_index(t, argv[optind], - strlen(argv[optind]), 1); + (int)strlen(argv[optind]), 1); if (fi < 0) { lwsl_err("%s: Failed to get file idx for %s\n", __func__, argv[optind]); @@ -122,12 +122,12 @@ int main(int argc, char **argv) } do { - int n = read(fd, buf, sizeof(buf)); + int n = (int)read(fd, buf, sizeof(buf)); if (n <= 0) break; - if (lws_fts_fill(t, fi, buf, n)) { + if (lws_fts_fill(t, (uint32_t)fi, buf, (size_t)n)) { lwsl_err("%s: lws_fts_fill failed\n", __func__); close(fd); diff --git a/minimal-examples/api-tests/api-test-jose/jwe.c b/minimal-examples/api-tests/api-test-jose/jwe.c index 44f33f67b..e403b2d37 100644 --- a/minimal-examples/api-tests/api-test-jose/jwe.c +++ b/minimal-examples/api-tests/api-test-jose/jwe.c @@ -1,7 +1,7 @@ /* * lws-api-test-jose - RFC7516 jwe tests * - * Written in 2010-2018 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -134,9 +134,9 @@ test_jwe_a1(struct lws_context *context) /* we require a JOSE-formatted header to do the encryption */ jwe.jws.map.buf[LJWS_JOSE] = temp; - jwe.jws.map.len[LJWS_JOSE] = lws_snprintf(temp, temp_len, + jwe.jws.map.len[LJWS_JOSE] = (uint32_t)lws_snprintf(temp, (unsigned int)temp_len, "{\"alg\":\"%s\",\"enc\":\"%s\"}", "RSA-OAEP", "A256GCM"); - temp_len -= jwe.jws.map.len[LJWS_JOSE]; + temp_len -= (int)jwe.jws.map.len[LJWS_JOSE]; /* * dup the plaintext into the ciphertext element, it will be @@ -155,7 +155,7 @@ test_jwe_a1(struct lws_context *context) n = lws_gencrypto_bits_to_bytes(jwe.jose.enc_alg->keybits_fixed); if (lws_jws_randomize_element(context, &jwe.jws.map, LJWE_EKEY, lws_concat_temp(temp, temp_len), - &temp_len, n, + &temp_len, (unsigned int)n, LWS_JWE_LIMIT_KEY_ELEMENT_BYTES)) { lwsl_err("Problem getting random\n"); goto bail; @@ -500,7 +500,7 @@ test_jwe_ra_ptext_1024(struct lws_context *context, char *jwk_txt, int jwk_len) /* reuse the rsa private key from the JWE Appendix 2 test above */ - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -530,7 +530,7 @@ test_jwe_ra_ptext_1024(struct lws_context *context, char *jwk_txt, int jwk_len) jwe.jws.map.len[LJWE_JOSE] = (uint32_t)strlen(rsa256a128_jose); n = lws_jwe_parse_jose(&jwe.jose, jwe.jws.map.buf[LJWE_JOSE], - jwe.jws.map.len[LJWE_JOSE], + (int)jwe.jws.map.len[LJWE_JOSE], lws_concat_temp(temp, temp_len), &temp_len); if (n < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -559,7 +559,7 @@ test_jwe_ra_ptext_1024(struct lws_context *context, char *jwk_txt, int jwk_len) /* now we created the encrypted version, see if we can decrypt it */ - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -627,7 +627,7 @@ test_jwe_r256a192_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) /* reuse the rsa private key from the JWE Appendix 2 test above */ - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -660,7 +660,7 @@ test_jwe_r256a192_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) jwe.jws.map.len[LJWE_JOSE] = (uint32_t)strlen(rsa256a192_jose); n = lws_jwe_parse_jose(&jwe.jose, jwe.jws.map.buf[LJWE_JOSE], - jwe.jws.map.len[LJWE_JOSE], + (int)jwe.jws.map.len[LJWE_JOSE], lws_concat_temp(temp, temp_len), &temp_len); if (n < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -688,7 +688,7 @@ test_jwe_r256a192_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) lws_jwe_destroy(&jwe); lws_jwe_init(&jwe, context); - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -759,7 +759,7 @@ test_jwe_r256a256_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) /* reuse the rsa private key from the JWE Appendix 2 test above */ - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -789,7 +789,7 @@ test_jwe_r256a256_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) } jwe.jws.map.buf[LJWE_JOSE] = rsa256a256_jose; - jwe.jws.map.len[LJWE_JOSE] = (int)strlen(rsa256a256_jose); + jwe.jws.map.len[LJWE_JOSE] = (uint32_t)strlen(rsa256a256_jose); n = lws_jwe_parse_jose(&jwe.jose, rsa256a256_jose, (int)strlen(rsa256a256_jose), @@ -820,7 +820,7 @@ test_jwe_r256a256_ptext(struct lws_context *context, char *jwk_txt, int jwk_len) lws_jwe_destroy(&jwe); lws_jwe_init(&jwe, context); - if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, jwk_len) < 0) { + if (lws_jwk_import(&jwe.jwk, NULL, NULL, jwk_txt, (unsigned int)jwk_len) < 0) { lwsl_notice("%s: Failed to decode JWK test key\n", __func__); goto bail; } @@ -1993,7 +1993,7 @@ test_akw_decrypt(struct lws_context *context, const char *test_name, /* allowing for trailing padding, confirm the plaintext */ if (jwe.jws.map.len[LJWE_CTXT] < strlen(akw_ptext) || lws_timingsafe_bcmp(jwe.jws.map.buf[LJWE_CTXT], akw_ptext, - (int)strlen(akw_ptext))) { + (uint32_t)strlen(akw_ptext))) { lwsl_err("%s: plaintext AES decrypt wrong\n", __func__); lwsl_hexdump_notice(akw_ptext, strlen(akw_ptext)); lwsl_hexdump_notice(jwe.jws.map.buf[LJWE_CTXT], @@ -2042,9 +2042,9 @@ test_akw_encrypt(struct lws_context *context, const char *test_name, /* we require a JOSE-formatted header to do the encryption */ jwe.jws.map.buf[LJWS_JOSE] = temp; - jwe.jws.map.len[LJWS_JOSE] = lws_snprintf(temp, temp_len, + jwe.jws.map.len[LJWS_JOSE] = (uint32_t)lws_snprintf(temp, (unsigned int)temp_len, "{\"alg\":\"%s\", \"enc\":\"%s\"}", alg, enc); - temp_len -= jwe.jws.map.len[LJWS_JOSE]; + temp_len -= (int)jwe.jws.map.len[LJWS_JOSE]; /* * dup the plaintext into the ciphertext element, it will be @@ -2065,7 +2065,7 @@ test_akw_encrypt(struct lws_context *context, const char *test_name, n = lws_gencrypto_bits_to_bytes(jwe.jose.enc_alg->keybits_fixed); if (lws_jws_randomize_element(context, &jwe.jws.map, LJWE_EKEY, lws_concat_temp(temp, temp_len), - &temp_len, n, + &temp_len, (unsigned int)n, LWS_JWE_LIMIT_KEY_ELEMENT_BYTES)) { lwsl_err("Problem getting random\n"); goto bail; @@ -2078,7 +2078,7 @@ test_akw_encrypt(struct lws_context *context, const char *test_name, goto bail; } - n = lws_jwe_render_compact(&jwe, compact, compact_len); + n = lws_jwe_render_compact(&jwe, compact, (unsigned int)compact_len); if (n < 0) { lwsl_err("%s: lws_jwe_render_compact failed: %d\n", __func__, n); diff --git a/minimal-examples/api-tests/api-test-jose/jws.c b/minimal-examples/api-tests/api-test-jose/jws.c index cb1cb1e8b..d8e4a701f 100644 --- a/minimal-examples/api-tests/api-test-jose/jws.c +++ b/minimal-examples/api-tests/api-test-jose/jws.c @@ -1,7 +1,7 @@ /* * lws-api-test-jose - RFC7515 jws tests * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -61,7 +61,7 @@ test_jws_none(struct lws_context *context) /* parse the JOSE header */ if (lws_jws_parse_jose(&jose, map.buf[LJWS_JOSE], - map.len[LJWS_JOSE], + (int)map.len[LJWS_JOSE], (char *)lws_concat_temp(temp, temp_len), &temp_len) < 0 || !jose.alg) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -180,7 +180,7 @@ test_jws_HS256(struct lws_context *context) jwk.e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, jwk.e[LWS_GENCRYPTO_OCT_KEYEL_K].len)) goto bail; - if (lws_genhmac_update(&ctx, (uint8_t *)buf, p - buf)) + if (lws_genhmac_update(&ctx, (uint8_t *)buf, lws_ptr_diff_size_t(p, buf))) goto bail_destroy_hmac; lws_genhmac_destroy(&ctx, digest); @@ -198,7 +198,7 @@ test_jws_HS256(struct lws_context *context) /* 1.5: Check we can agree the signature matches the payload */ - if (lws_jws_sig_confirm_compact_b64(buf, p - buf, &map, &jwk, context, + if (lws_jws_sig_confirm_compact_b64(buf, lws_ptr_diff_size_t(p, buf), &map, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_notice("%s: confirm sig failed\n", __func__); goto bail; @@ -326,7 +326,7 @@ test_jws_RS256(struct lws_context *context) l = (int)strlen(rfc7515_rsa_a1); if (temp_len < l + 1) goto bail; - memcpy(in, rfc7515_rsa_a1, l + 1); + memcpy(in, rfc7515_rsa_a1, (unsigned int)l + 1); temp_len -= l + 1; if (lws_jws_b64_compact_map(in, l, &jws.map_b64) != 3) { @@ -342,12 +342,13 @@ test_jws_RS256(struct lws_context *context) lwsl_err("%s: failed signing test packet\n", __func__); goto bail; } - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (unsigned int)n; /* 2.4: confirm our signature can be verified */ in[l] = '\0'; - if (lws_jws_sig_confirm_compact_b64(in, l, &map, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { + if (lws_jws_sig_confirm_compact_b64(in, (unsigned int)l, &map, &jwk, + context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_notice("%s: 2.2: confirm rsa sig failed\n", __func__); goto bail; } @@ -446,7 +447,7 @@ test_jws_ES256(struct lws_context *context) /* parse the JOSE header */ if (lws_jws_parse_jose(&jose, jws.map.buf[LJWS_JOSE], - jws.map.len[LJWS_JOSE], + (int)jws.map.len[LJWS_JOSE], (char *)lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); goto bail; @@ -485,7 +486,7 @@ test_jws_ES256(struct lws_context *context) if (temp_len < l + 1) goto bail1; p = lws_concat_temp(temp, temp_len); - memcpy(p, es256_cser, l + 1); + memcpy(p, es256_cser, (unsigned int)l + 1); temp_len -= l + 1; /* scan the b64 compact serialization string to map the blocks */ @@ -515,7 +516,7 @@ test_jws_ES256(struct lws_context *context) lwsl_err("%s: failed signing test packet\n", __func__); goto bail1; } - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (unsigned int)n; lwsl_hexdump(jws.map_b64.buf[LJWS_SIG], jws.map_b64.len[LJWS_SIG]); @@ -523,7 +524,8 @@ test_jws_ES256(struct lws_context *context) // lwsl_err("p %p, l %d\n", p, (int)l); p[l] = '\0'; - if (lws_jws_sig_confirm_compact_b64(p, l, &map, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { + if (lws_jws_sig_confirm_compact_b64(p, (unsigned int)l, &map, &jwk, + context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_notice("%s: confirm our EC sig failed\n", __func__); goto bail1; } @@ -607,7 +609,7 @@ test_jws_ES512(struct lws_context *context) /* parse the JOSE header */ if (lws_jws_parse_jose(&jose, jws.map.buf[LJWS_JOSE], - jws.map.len[LJWS_JOSE], + (int)jws.map.len[LJWS_JOSE], lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); goto bail; @@ -646,7 +648,7 @@ test_jws_ES512(struct lws_context *context) if (temp_len < l) goto bail1; p = lws_concat_temp(temp, temp_len); - memcpy(p, es512_cser, l + 1); + memcpy(p, es512_cser, (unsigned int)l + 1); temp_len -= (l + 1); /* scan the b64 compact serialization string to map the blocks */ @@ -673,13 +675,13 @@ test_jws_ES512(struct lws_context *context) lwsl_err("%s: failed signing test packet\n", __func__); goto bail1; } - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (unsigned int)n; /* 2.4: confirm our generated signature can be verified */ p[l] = '\0'; - if (lws_jws_sig_confirm_compact_b64(p, l, &map, &jwk, context, + if (lws_jws_sig_confirm_compact_b64(p, (unsigned int)l, &map, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_notice("%s: confirm our ECDSA sig failed\n", __func__); goto bail1; diff --git a/minimal-examples/api-tests/api-test-lws_sequencer/main.c b/minimal-examples/api-tests/api-test-lws_sequencer/main.c index 2126e9942..5bedb283e 100644 --- a/minimal-examples/api-tests/api-test-lws_sequencer/main.c +++ b/minimal-examples/api-tests/api-test-lws_sequencer/main.c @@ -90,7 +90,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: if (!s) return 1; - s->http_resp = lws_http_client_http_response(wsi); + s->http_resp = (int)lws_http_client_http_response(wsi); lwsl_info("Connected with server response: %d\n", s->http_resp); break; diff --git a/minimal-examples/api-tests/api-test-lws_struct-json/main.c b/minimal-examples/api-tests/api-test-lws_struct-json/main.c index d6d06fa16..5f18af585 100644 --- a/minimal-examples/api-tests/api-test-lws_struct-json/main.c +++ b/minimal-examples/api-tests/api-test-lws_struct-json/main.c @@ -611,7 +611,7 @@ int main(int argc, const char **argv) } do { - n = lws_struct_json_serialize(ser, buf, sizeof(buf), + n = (int)lws_struct_json_serialize(ser, buf, sizeof(buf), &written); switch (n) { case LSJS_RESULT_FINISH: @@ -658,7 +658,7 @@ done: } do { - n = lws_struct_json_serialize(ser, buf, sizeof(buf), &written); + n = (int)lws_struct_json_serialize(ser, buf, sizeof(buf), &written); switch (n) { case LSJS_RESULT_CONTINUE: case LSJS_RESULT_FINISH: @@ -725,7 +725,7 @@ done: if (!js) goto bail; - n = lws_struct_json_serialize(js, buf, 2048, &w); + n = (int)lws_struct_json_serialize(js, buf, 2048, &w); lws_struct_json_serialize_destroy(&js); if (n != LSJS_RESULT_FINISH) goto bail; diff --git a/minimal-examples/api-tests/api-test-lws_struct-json/test2.c b/minimal-examples/api-tests/api-test-lws_struct-json/test2.c index 535adf933..e26dc3b42 100644 --- a/minimal-examples/api-tests/api-test-lws_struct-json/test2.c +++ b/minimal-examples/api-tests/api-test-lws_struct-json/test2.c @@ -207,7 +207,7 @@ test2(void) } do { - n = lws_struct_json_serialize(ser, buf, sizeof(buf), &written); + n = (int)lws_struct_json_serialize(ser, buf, sizeof(buf), &written); switch (n) { case LSJS_RESULT_FINISH: puts((const char *)buf); diff --git a/minimal-examples/api-tests/api-test-lws_tokenize/main.c b/minimal-examples/api-tests/api-test-lws_tokenize/main.c index 9accde82c..fb5938c0d 100644 --- a/minimal-examples/api-tests/api-test-lws_tokenize/main.c +++ b/minimal-examples/api-tests/api-test-lws_tokenize/main.c @@ -1,7 +1,7 @@ /* * lws-api-test-lws_tokenize * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -494,7 +494,7 @@ int main(int argc, const char **argv) memset(&ts, 0, sizeof(ts)); ts.start = tests[n].string; ts.len = strlen(ts.start); - ts.flags = tests[n].flags; + ts.flags = (uint16_t)tests[n].flags; do { e = lws_tokenize(&ts); @@ -543,7 +543,7 @@ int main(int argc, const char **argv) if (p) { ts.start = p; ts.len = strlen(p); - ts.flags = flags; + ts.flags = (uint16_t)flags; printf("\t{\n\t\t\"%s\",\n" "\t\texpected%d, LWS_ARRAY_SIZE(expected%d),\n\t\t", diff --git a/minimal-examples/api-tests/api-test-secure-streams/main.c b/minimal-examples/api-tests/api-test-secure-streams/main.c index 77c44dac5..8becb6764 100644 --- a/minimal-examples/api-tests/api-test-secure-streams/main.c +++ b/minimal-examples/api-tests/api-test-secure-streams/main.c @@ -196,7 +196,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, { myss_t *m = (myss_t *)userobj; - lwsl_notice("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_notice("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { diff --git a/minimal-examples/crypto/minimal-crypto-jwe/main.c b/minimal-examples/crypto/minimal-crypto-jwe/main.c index 384f49db7..883f0b6d0 100644 --- a/minimal-examples/crypto/minimal-crypto-jwe/main.c +++ b/minimal-examples/crypto/minimal-crypto-jwe/main.c @@ -1,7 +1,7 @@ /* * lws-crypto-jwe * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -142,15 +142,15 @@ int main(int argc, const char **argv) return 1; } - jwe.jws.map.len[LJWS_JOSE] = lws_snprintf( - (char *)jwe.jws.map.buf[LJWS_JOSE], temp_len, + jwe.jws.map.len[LJWS_JOSE] = (uint32_t)lws_snprintf( + (char *)jwe.jws.map.buf[LJWS_JOSE], (unsigned int)temp_len, "{\"alg\":\"%s\",\"enc\":\"%s\"}", p, sp + 1); enc = 1; } in = lws_concat_temp(temp, temp_len); - n = read(0, in, temp_len); + n = (int)read(0, in, (unsigned int)temp_len); if (n < 0) { lwsl_err("Problem reading from stdin\n"); return 1; @@ -158,7 +158,7 @@ int main(int argc, const char **argv) /* account for padding as well */ - temp_len -= (int)lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, n); + temp_len -= (int)lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, (unsigned int)n); /* grab the key */ @@ -179,7 +179,7 @@ int main(int argc, const char **argv) /* point CTXT to the plaintext we read from stdin */ jwe.jws.map.buf[LJWE_CTXT] = in; - jwe.jws.map.len[LJWE_CTXT] = n; + jwe.jws.map.len[LJWE_CTXT] = (uint32_t)n; /* * Create a random CEK and set EKEY to it @@ -189,7 +189,7 @@ int main(int argc, const char **argv) n = lws_gencrypto_bits_to_bytes(jwe.jose.enc_alg->keybits_fixed); if (lws_jws_randomize_element(context, &jwe.jws.map, LJWE_EKEY, lws_concat_temp(temp, temp_len), - &temp_len, n, + &temp_len, (unsigned int)n, LWS_JWE_LIMIT_KEY_ELEMENT_BYTES)) { lwsl_err("Problem getting random\n"); goto bail1; diff --git a/minimal-examples/crypto/minimal-crypto-jws/main.c b/minimal-examples/crypto/minimal-crypto-jws/main.c index e8d5b5d5a..d579aaba1 100644 --- a/minimal-examples/crypto/minimal-crypto-jws/main.c +++ b/minimal-examples/crypto/minimal-crypto-jws/main.c @@ -1,7 +1,7 @@ /* * lws-crypto-jws * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -69,14 +69,14 @@ int main(int argc, const char **argv) return 1; } - jws.map.len[LJWS_JOSE] = + jws.map.len[LJWS_JOSE] = (uint32_t) lws_snprintf((char *)jws.map.buf[LJWS_JOSE], - temp_len, "{\"alg\":\"%s\"}", p); + (unsigned int)temp_len, "{\"alg\":\"%s\"}", p); sign = 1; } in = lws_concat_temp(temp, temp_len); - n = read(0, in, temp_len); + n = (int)read(0, in, (unsigned int)temp_len); if (n < 0) { lwsl_err("Problem reading from stdin\n"); return 1; @@ -101,7 +101,7 @@ int main(int argc, const char **argv) /* add the plaintext from stdin to the map and a b64 version */ jws.map.buf[LJWS_PYLD] = in; - jws.map.len[LJWS_PYLD] = n; + jws.map.len[LJWS_PYLD] = (unsigned int)n; if (lws_jws_encode_b64_element(&jws.map_b64, LJWS_PYLD, lws_concat_temp(temp, temp_len), @@ -121,7 +121,7 @@ int main(int argc, const char **argv) if (lws_jws_alloc_element(&jws.map_b64, LJWS_SIG, lws_concat_temp(temp, temp_len), - &temp_len, lws_base64_size( + &temp_len, (unsigned int)lws_base64_size( LWS_JWE_LIMIT_KEY_ELEMENT_BYTES), 0)) { lwsl_err("%s: temp space too small\n", __func__); goto bail1; @@ -139,7 +139,7 @@ int main(int argc, const char **argv) goto bail1; } /* set the actual b64 signature size */ - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (uint32_t)n; if (lws_cmdline_option(argc, argv, "-f")) /* create the flattened representation */ @@ -167,7 +167,7 @@ int main(int argc, const char **argv) /* perform the verify directly on the compact representation */ if (lws_cmdline_option(argc, argv, "-f")) { - if (lws_jws_sig_confirm_json(in, n, &jws, &jwk, context, + if (lws_jws_sig_confirm_json(in, (unsigned int)n, &jws, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { lwsl_notice("%s: confirm rsa sig failed\n", @@ -183,7 +183,7 @@ int main(int argc, const char **argv) } } else { if (lws_jws_sig_confirm_compact_b64(in, - lws_concat_used(temp, temp_len), + lws_concat_used(temp, (unsigned int)temp_len), &map, &jwk, context, lws_concat_temp(temp, temp_len), &temp_len) < 0) { diff --git a/minimal-examples/crypto/minimal-crypto-x509/main.c b/minimal-examples/crypto/minimal-crypto-x509/main.c index a73ee2191..e6f210bc9 100644 --- a/minimal-examples/crypto/minimal-crypto-x509/main.c +++ b/minimal-examples/crypto/minimal-crypto-x509/main.c @@ -19,7 +19,7 @@ read_pem(const char *filename, char *pembuf, int pembuf_len) if (fd == -1) return -1; - n = read(fd, pembuf, pembuf_len - 1); + n = (int)read(fd, pembuf, (unsigned int)pembuf_len - 1); close(fd); pembuf[n++] = '\0'; @@ -43,7 +43,7 @@ read_pem_c509_cert(struct lws_x509_cert **x509, const char *filename, return -1; } - if (lws_x509_parse_from_pem(*x509, pembuf, n) < 0) { + if (lws_x509_parse_from_pem(*x509, pembuf, (unsigned int)n) < 0) { lwsl_err("%s: unable to parse PEM %s\n", __func__, filename); lws_x509_destroy(x509); @@ -166,7 +166,7 @@ int main(int argc, const char **argv) goto bail3; } - if (lws_x509_jwk_privkey_pem(&jwk, pembuf, n, NULL)) { + if (lws_x509_jwk_privkey_pem(&jwk, pembuf, (unsigned int)n, NULL)) { lwsl_err("%s: unable to parse privkey %s\n", __func__, p); diff --git a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c index e621c8e2a..3db1c4e0c 100644 --- a/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c +++ b/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c @@ -739,10 +739,10 @@ callback_minimal_dbus_wsproxy(struct lws *wsi, enum lws_callback_reasons reason, { char strbuf[256]; - int l = len; + size_t l = len; - if (l > (int)sizeof(strbuf) - 1) - l = sizeof(strbuf) - 1; + if (l > sizeof(strbuf) - 1u) + l = sizeof(strbuf) - 1u; memcpy(strbuf, in, l); strbuf[l] = '\0'; diff --git a/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c b/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c index 20a035233..3f7b25559 100644 --- a/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c +++ b/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c @@ -46,7 +46,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, char buf[128]; lws_get_peer_simple(wsi, buf, sizeof(buf)); - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected to %s, http response: %d\n", buf, status); diff --git a/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c b/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c index 38d1a7668..ffa1390d0 100644 --- a/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c +++ b/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c @@ -45,7 +45,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, char buf[128]; lws_get_peer_simple(wsi, buf, sizeof(buf)); - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected to %s, http response: %d\n", buf, status); @@ -114,7 +114,7 @@ callback_cpd_http(struct lws *wsi, enum lws_callback_reasons reason, switch (reason) { case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - resp = lws_http_client_http_response(wsi); + resp = (int)lws_http_client_http_response(wsi); if (!resp) break; lwsl_user("%s: established with resp %d\n", __func__, resp); diff --git a/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c b/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c index ffe484957..2eb8968f7 100644 --- a/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c +++ b/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c @@ -37,7 +37,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, break; case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_notice("lws_http_client_http_response %d\n", status); if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_COMMON_NAME, @@ -62,7 +62,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY, ci, sizeof(buf) - sizeof(*ci))) { lwsl_notice(" Peer Cert public key:\n"); - lwsl_hexdump_notice(ci->ns.name, ci->ns.len); + lwsl_hexdump_notice(ci->ns.name, (unsigned int)ci->ns.len); } break; diff --git a/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c b/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c index 2fd953e83..92f5326da 100644 --- a/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c +++ b/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c @@ -51,7 +51,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, } case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected with server response: %d\n", status); /* diff --git a/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c b/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c index 0f67de068..61baa6012 100644 --- a/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c +++ b/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c @@ -66,7 +66,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, char buf[128]; lws_get_peer_simple(wsi, buf, sizeof(buf)); - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected to %s, http response: %d\n", buf, status); diff --git a/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c b/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c index 99c98e49a..7b58f3e4c 100644 --- a/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c +++ b/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c @@ -77,7 +77,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, break; case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected with server response: %d\n", status); break; diff --git a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c index 4a77fb8fd..c9fb05540 100644 --- a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c +++ b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c @@ -150,13 +150,13 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, &p, end)) return -1; /* notice every usage of the boundary starts with -- */ - p += lws_snprintf(p, end - p, "my text field\xd\xa"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "my text field\xd\xa"); break; case 1: if (lws_client_http_multipart(wsi, "file", "myfile.txt", "text/plain", &p, end)) return -1; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "This is the contents of the " "uploaded file.\xd\xa" "\xd\xa"); @@ -179,7 +179,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, return 0; } - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), n) + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)n) != lws_ptr_diff(p, start)) return 1; @@ -266,7 +266,7 @@ unsigned long long us(void) gettimeofday(&t, NULL); - return (t.tv_sec * 1000000ull) + t.tv_usec; + return ((unsigned long long)t.tv_sec * 1000000ull) + (unsigned long long)t.tv_usec; } static void @@ -309,9 +309,9 @@ stagger_cb(lws_sorted_usec_list_t *sul) if (stagger_idx == count) return; - next = 300 * LWS_US_PER_MS; + next = 150 * LWS_US_PER_MS; if (stagger_idx == count - 1) - next += 700 * LWS_US_PER_MS; + next += 400 * LWS_US_PER_MS; lws_sul_schedule(context, 0, &sul_stagger, stagger_cb, next); } @@ -462,7 +462,7 @@ int main(int argc, const char **argv) * delay the connections slightly */ lws_sul_schedule(context, 0, &sul_stagger, stagger_cb, - 100 * LWS_US_PER_MS); + 50 * LWS_US_PER_MS); start = us(); while (!intr && !lws_service(context, 0)) diff --git a/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c b/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c index 2b74bf67b..2cd5d3d21 100644 --- a/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c +++ b/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c @@ -58,7 +58,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, /* ...callbacks related to receiving the result... */ case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected with server response: %d\n", status); break; @@ -123,13 +123,13 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, &p, end)) return -1; /* notice every usage of the boundary starts with -- */ - p += lws_snprintf(p, end - p, "my text field\xd\xa"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "my text field\xd\xa"); break; case 1: if (lws_client_http_multipart(wsi, "file", "myfile.txt", "text/plain", &p, end)) return -1; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "This is the contents of the " "uploaded file.\xd\xa" "\xd\xa"); @@ -152,7 +152,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, return 0; } - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), n) + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)n) != lws_ptr_diff(p, start)) return 1; @@ -211,7 +211,7 @@ int main(int argc, const char **argv) * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we * will use. */ - info.fd_limit_per_thread = 1 + count_clients + 1; + info.fd_limit_per_thread = (unsigned int)(1 + count_clients + 1); #if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* diff --git a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c index 29cb79ee3..46c949742 100644 --- a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c +++ b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c @@ -46,7 +46,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, char buf[128]; lws_get_peer_simple(wsi, buf, sizeof(buf)); - status = lws_http_client_http_response(wsi); + status = (int)lws_http_client_http_response(wsi); lwsl_user("Connected to %s, http response: %d\n", buf, status); diff --git a/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c b/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c index 6e4c9ad67..06f500d52 100644 --- a/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c +++ b/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c @@ -40,7 +40,8 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, *end = &buf[sizeof(buf) - LWS_PRE - 1]; struct pss *pss = (struct pss *)user; char value[32], *pr = &pss->result[LWS_PRE]; - int n, e = sizeof(pss->result) - LWS_PRE; + size_t e = sizeof(pss->result) - LWS_PRE; + int n; switch (reason) { case LWS_CALLBACK_HTTP: @@ -63,18 +64,18 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, "%s: DNT length %d
", __func__, n); n = lws_hdr_custom_copy(wsi, value, sizeof(value), "dnt:", 4); if (n < 0) - pss->len += lws_snprintf(pr + pss->len, e - pss->len, + pss->len += lws_snprintf(pr + pss->len, e - (unsigned int)pss->len, "%s: unable to get DNT value\n", __func__); else - pss->len += lws_snprintf(pr + pss->len , e - pss->len, + pss->len += lws_snprintf(pr + pss->len , e - (unsigned int)pss->len, "%s: DNT value '%s'\n", __func__, value); } lwsl_user("%s\n", pr); if (lws_add_http_common_headers(wsi, HTTP_STATUS_OK, - "text/html", pss->len, &p, end)) + "text/html", (lws_filepos_t)pss->len, &p, end)) return 1; if (lws_finalize_write_http_header(wsi, start, &p, end)) @@ -89,7 +90,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, strcpy((char *)start, "hello"); - if (lws_write(wsi, (uint8_t *)pr, pss->len, LWS_WRITE_HTTP_FINAL) != pss->len) + if (lws_write(wsi, (uint8_t *)pr, (unsigned int)pss->len, LWS_WRITE_HTTP_FINAL) != pss->len) return 1; if (lws_http_transaction_completed(wsi)) diff --git a/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c b/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c index 7d40abd21..3a9db09d9 100644 --- a/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c +++ b/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c @@ -1,7 +1,7 @@ /* * lws-minimal-http-server-deaddrop * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c index af0b220f3..9cf8ebe82 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c +++ b/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c @@ -145,7 +145,7 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason, * to work with http/2, we must take care about LWS_PRE * valid behind the buffer we will send. */ - p += lws_snprintf((char *)p, end - p, "" + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "" "" @@ -162,15 +162,15 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason, */ while (lws_ptr_diff(end, p) > 80) - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%d.%d: this is some content... ", pss->times, pss->content_lines++); - p += lws_snprintf((char *)p, end - p, "

"); + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "

"); } pss->times++; - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), n) != + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)n) != lws_ptr_diff(p, start)) return 1; diff --git a/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c b/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c index 4a3717003..7a7f3f7cf 100644 --- a/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c +++ b/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c @@ -116,7 +116,7 @@ int main(int argc, const char **argv) LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if ((p = lws_cmdline_option(argc, argv, "-t"))) { - info.count_threads = atoi(p); + info.count_threads = (unsigned int)atoi(p); if (info.count_threads < 1 || info.count_threads > LWS_MAX_SMP) return 1; } else diff --git a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c index 8d11aaae4..bdc6056f6 100644 --- a/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c +++ b/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c @@ -71,9 +71,9 @@ file_upload_cb(void *data, const char *name, const char *filename, if (len) { int n; - pss->file_length += len; + pss->file_length += (unsigned int)len; - n = write(pss->fd, buf, len); + n = (int)write(pss->fd, buf, (unsigned int)len); if (n < len) { lwsl_notice("Problem writing file %d\n", errno); } diff --git a/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c b/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c index 0d1e1d0d4..36c8e06c8 100644 --- a/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c +++ b/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c @@ -87,7 +87,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, break; n = lws_snprintf((char *)p, sizeof(buf) - LWS_PRE, "%llu", (unsigned long long)lws_now_usecs()); - m = lws_write(wsi, p, n, LWS_WRITE_HTTP); + m = lws_write(wsi, p, (unsigned int)n, LWS_WRITE_HTTP); if (m < n) { lwsl_err("ERROR %d writing to socket\n", n); return -1; diff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c index b7d2e6930..f32a48f07 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c +++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c @@ -100,7 +100,7 @@ int main(int argc, const char **argv) info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; if ((p = lws_cmdline_option(argc, argv, "-t"))) { - info.count_threads = atoi(p); + info.count_threads = (unsigned int)atoi(p); if (info.count_threads < 1 || info.count_threads > LWS_MAX_SMP) return 1; } else diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c index 1d4f210c4..41d2edd20 100644 --- a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c @@ -112,14 +112,14 @@ thread_spam(void *d) goto wait_unlock; } - amsg.payload = malloc(len); + amsg.payload = malloc((unsigned int)len); if (!amsg.payload) { lwsl_user("OOM: dropping\n"); goto wait_unlock; } - n = lws_snprintf((char *)amsg.payload, len, + n = lws_snprintf((char *)amsg.payload, (unsigned int)len, "%s: tid: %d, msg: %d", __func__, whoami, index++); - amsg.len = n; + amsg.len = (unsigned int)n; n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); @@ -136,7 +136,7 @@ wait_unlock: wait: /* rand() would make more sense but coverity shrieks */ - usleep(100000 + (time(NULL) & 0xffff)); + usleep((useconds_t)(100000 + (time(NULL) & 0xffff))); } while (!vhd->finished); @@ -262,11 +262,11 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (!pmsg) break; - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "data: %s\x0d\x0a\x0d\x0a", (const char *)pmsg->payload); - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP) != lws_ptr_diff(p, start)) return 1; diff --git a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c index adae1c054..da620dd8e 100644 --- a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c +++ b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c @@ -98,12 +98,12 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user, * own private data and timer. */ - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "data: %llu\x0d\x0a\x0d\x0a", - (unsigned long long)time(NULL) - - pss->established); + (unsigned long long)(time(NULL) - + pss->established)); - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP) != lws_ptr_diff(p, start)) return 1; diff --git a/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c b/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c index b907d73d9..4a23f832a 100644 --- a/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c +++ b/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c @@ -285,7 +285,7 @@ callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, (int)chunk, (int)pss->pos); if (lws_mqtt_client_send_publish(wsi, &pss->pub_param, - test_string + pss->pos, chunk, + test_string + pss->pos, (uint32_t)chunk, (pss->pos + chunk == TEST_STRING_LEN))) { lwsl_notice("%s: publish failed\n", __func__); return -1; diff --git a/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c b/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c index 891270fbe..c02ae813f 100644 --- a/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c +++ b/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c @@ -222,7 +222,7 @@ callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, chunk = TEST_STRING_LEN - pss->pos; if (lws_mqtt_client_send_publish(wsi, &pub_param, - test_string + pss->pos, chunk, + test_string + pss->pos, (uint32_t)chunk, (pss->pos + chunk == TEST_STRING_LEN))) return -1; diff --git a/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c b/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c index 9a98277de..5a3e4b749 100644 --- a/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c +++ b/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c @@ -73,7 +73,7 @@ callback_raw_echo(struct lws *wsi, enum lws_callback_reasons reason, void *user, case LWS_CALLBACK_RAW_WRITEABLE: lwsl_notice("LWS_CALLBACK_RAW_WRITEABLE\n"); - lws_write(wsi, pss->buf, pss->len, LWS_WRITE_HTTP); + lws_write(wsi, pss->buf, (unsigned int)pss->len, LWS_WRITE_HTTP); break; default: break; diff --git a/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c b/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c index 21c5c48eb..f9759e97b 100644 --- a/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c +++ b/minimal-examples/raw/minimal-raw-file/minimal-raw-file.c @@ -69,13 +69,13 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_RAW_RX_FILE: lwsl_notice("LWS_CALLBACK_RAW_RX_FILE\n"); - n = read(vhd->filefd, buf, sizeof(buf)); + n = (int)read(vhd->filefd, buf, sizeof(buf)); if (n < 0) { lwsl_err("Reading from %s failed\n", filepath); return 1; } - lwsl_hexdump_level(LLL_NOTICE, buf, n); + lwsl_hexdump_level(LLL_NOTICE, buf, (unsigned int)n); break; case LWS_CALLBACK_RAW_CLOSE_FILE: diff --git a/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c b/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c index ccdd5a54d..489c030cc 100644 --- a/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c +++ b/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c @@ -65,7 +65,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_RAW_RX_FILE: lwsl_user("LWS_CALLBACK_RAW_RX_FILE\n"); - waiting = read(0, buf, sizeof(buf)); + waiting = (int)read(0, buf, sizeof(buf)); lwsl_notice("raw file read %d\n", waiting); if (waiting < 0) return -1; @@ -107,7 +107,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, // lwsl_hexdump_info(buf, waiting); if (stdin_wsi) lws_rx_flow_control(stdin_wsi, 1); - if (lws_write(wsi, buf, waiting, LWS_WRITE_RAW) != waiting) { + if (lws_write(wsi, buf, (unsigned int)waiting, LWS_WRITE_RAW) != waiting) { lwsl_notice("%s: raw skt write failed\n", __func__); return -1; diff --git a/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c b/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c index f4e9d03df..4b15320be 100644 --- a/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c +++ b/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c @@ -89,12 +89,12 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, cfsetispeed(&tio, B115200); cfsetospeed(&tio, B115200); - tio.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | + tio.c_lflag &= (tcflag_t)~(ISIG | ICANON | IEXTEN | ECHO | #if defined(__linux__) XCASE | #endif ECHOE | ECHOK | ECHONL | ECHOCTL | ECHOKE); - tio.c_iflag &= ~(INLCR | IGNBRK | IGNPAR | IGNCR | ICRNL | + tio.c_iflag &= (tcflag_t)~(INLCR | IGNBRK | IGNPAR | IGNCR | ICRNL | IMAXBEL | IXON | IXOFF | IXANY #if defined(__linux__) | IUCLC @@ -105,7 +105,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; tio.c_cc[VEOF] = 1; - tio.c_cflag &= ~( + tio.c_cflag = tio.c_cflag & (unsigned long) ~( #if defined(__linux__) CBAUD | #endif @@ -142,13 +142,13 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_RAW_RX_FILE: lwsl_notice("LWS_CALLBACK_RAW_RX_FILE\n"); - n = read(vhd->filefd, buf, sizeof(buf)); + n = (int)read(vhd->filefd, buf, sizeof(buf)); if (n < 0) { lwsl_err("Reading from %s failed\n", filepath); return 1; } - lwsl_hexdump_level(LLL_NOTICE, buf, n); + lwsl_hexdump_level(LLL_NOTICE, buf, (unsigned int)n); break; case LWS_CALLBACK_RAW_CLOSE_FILE: diff --git a/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c b/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c index ddf0a8350..d0f9e2750 100644 --- a/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c +++ b/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c @@ -78,14 +78,14 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, vhd->len = (int)len; if (vhd->len > (int)sizeof(vhd->buf)) vhd->len = sizeof(vhd->buf); - memcpy(vhd->buf, in, vhd->len); + memcpy(vhd->buf, in, (unsigned int)vhd->len); lws_start_foreach_llp(struct raw_pss **, ppss, vhd->pss_list) { lws_callback_on_writable((*ppss)->wsi); } lws_end_foreach_llp(ppss, pss_list); break; case LWS_CALLBACK_RAW_WRITEABLE: - if (lws_write(wsi, vhd->buf, vhd->len, LWS_WRITE_RAW) != + if (lws_write(wsi, vhd->buf, (unsigned int)vhd->len, LWS_WRITE_RAW) != vhd->len) { lwsl_notice("%s: raw write failed\n", __func__); return 1; diff --git a/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c b/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c index c5a7fe4c8..5506db3d6 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c @@ -88,14 +88,14 @@ use_buffer_50ms(lws_sorted_usec_list_t *sul) */ /* remaining data in buffer */ - n = ((m->head - m->tail) % sizeof(m->buf)); + n = ((size_t)(m->head - m->tail) % sizeof(m->buf)); lwsl_info("%s: avail %d\n", __func__, (int)n); if (n < 401) lwsl_err("%s: underrun\n", __func__); - m->tail = (m->tail + 401) % sizeof(m->buf); - n = ((m->head - m->tail) % sizeof(m->buf)); + m->tail = ((size_t)m->tail + 401) % sizeof(m->buf); + n = ((size_t)(m->head - m->tail) % sizeof(m->buf)); e = lws_ss_get_est_peer_tx_credit(m->ss); @@ -103,8 +103,8 @@ use_buffer_50ms(lws_sorted_usec_list_t *sul) if (n < (sizeof(m->buf) * 2) / 3 && e < (int)(sizeof(m->buf) - 1 - n)) { lwsl_info("%s: requesting additional %d\n", __func__, - (int)(sizeof(m->buf) - 1 - e - n)); - lws_ss_add_peer_tx_credit(m->ss, (int32_t)(sizeof(m->buf) - 1 - e - n)); + (int)sizeof(m->buf) - 1 - e - (int)n); + lws_ss_add_peer_tx_credit(m->ss, (int32_t)((int)sizeof(m->buf) - 1 - e - (int)n)); } lws_sul_schedule(context, 0, &m->sul, use_buffer_50ms, @@ -124,7 +124,7 @@ ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags) lwsl_hexdump_warn(buf, len); #endif - n = sizeof(m->buf) - ((m->head - m->tail) % sizeof(m->buf)); + n = sizeof(m->buf) - ((size_t)(m->head - m->tail) % sizeof(m->buf)); lwsl_info("%s: len %d, buf h %d, t %d, space %d\n", __func__, (int)len, (int)m->head, (int)m->tail, (int)n); lws_ss_get_est_peer_tx_credit(m->ss); @@ -138,7 +138,7 @@ ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags) if (m->head < m->tail) /* |****h-------t**| */ memcpy(&m->buf[m->head], buf, len); else { /* |---t*****h-----| */ - n1 = sizeof(m->buf) - m->head; + n1 = sizeof(m->buf) - (size_t)m->head; if (len < n1) n1 = len; memcpy(&m->buf[m->head], buf, n1); @@ -146,7 +146,7 @@ ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags) memcpy(m->buf, buf, len - n1); } - m->head = (m->head + len) % sizeof(m->buf); + m->head = (((size_t)m->head) + len) % sizeof(m->buf); lws_sul_schedule(context, 0, &m->sul, use_buffer_50ms, 50 * LWS_US_PER_MS); @@ -185,7 +185,7 @@ ss_avs_metadata_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, if (m->pos == wav_len) { *flags |= LWSSS_FLAG_EOM; lwsl_info("%s: tx done\n", __func__); - m->pos = (long)-1l; /* ban subsequent until new stream */ + m->pos = (size_t)-1l; /* ban subsequent until new stream */ } else lws_ss_request_tx(m->ss); @@ -227,7 +227,7 @@ ss_avs_metadata_state(void *userobj, void *sh, ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; // struct lws_context *context = (struct lws_context *)m->opaque_data; - lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { @@ -296,7 +296,7 @@ ss_avs_event_state(void *userobj, void *sh, struct lws_context *context = (struct lws_context *)m->opaque_data; lws_ss_info_t ssi; - lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { @@ -382,7 +382,7 @@ avs_example_start(struct lws_context *context) goto bail; } - wav_len = stat.st_size; + wav_len = (size_t)stat.st_size; wav = malloc(wav_len); if (!wav) { lwsl_err("%s: failed to alloc wav buffer", __func__); diff --git a/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c b/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c index b3c2735e4..33920250b 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c @@ -102,7 +102,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, myss_t *m = (myss_t *)userobj; struct lws_context *context = lws_sspc_get_context(m->ss); - lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { diff --git a/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c b/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c index b3eddeafd..d5de7f8fe 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c @@ -219,7 +219,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, { myss_t *m = (myss_t *)userobj; - lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { @@ -326,7 +326,7 @@ int main(int argc, const char **argv) /* connect to ssproxy via UDS by default, else via * tcp connection to this port */ if ((p = lws_cmdline_option(argc, argv, "-p"))) - info.ss_proxy_port = atoi(p); + info.ss_proxy_port = (uint16_t)atoi(p); /* UDS "proxy.ss.lws" in abstract namespace, else this socket * path; when -p given this can specify the network interface diff --git a/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c b/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c index 4cd24fc25..8dc583678 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c @@ -106,7 +106,7 @@ int main(int argc, const char **argv) printf("/*\n * Autogenerated from the following JSON policy\n */\n\n#if 0\n"); do { - int m, n = read(0, buf, sizeof(buf)); + int m, n = (int)read(0, buf, sizeof(buf)); if (n < 1) break; @@ -114,7 +114,7 @@ int main(int argc, const char **argv) m = lws_ss_policy_parse(context, (uint8_t *)buf, (size_t)n); printf("%.*s", n, buf); - json_size += n; + json_size += (unsigned int)n; if (m < 0 && m != LEJP_CONTINUE) { lwsl_err("%s: policy parse failed... lws has WITH_ROLEs" @@ -224,7 +224,7 @@ int main(int argc, const char **argv) if (!a) goto bail; a->next = rbomap; - a->offset = unique_rbo++; + a->offset = (unsigned int)unique_rbo++; a->orig = (const char *)pol->retry_bo; rbomap = a; diff --git a/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c b/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c index e0211b903..a1d60030d 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c @@ -379,7 +379,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, myss_t *m = (myss_t *)userobj; lwsl_user("%s: h %p, %s, ord 0x%x\n", __func__, m->ss, - lws_ss_state_name(state), (unsigned int)ack); + lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { case LWSSSCS_CREATING: @@ -515,7 +515,7 @@ int main(int argc, const char **argv) force_cpd_fail_no_internet = 1; if ((p = lws_cmdline_option(argc, argv, "--timeout_ms"))) - timeout_ms = atoi(p); + timeout_ms = (unsigned int)atoi(p); info.fd_limit_per_thread = 1 + 6 + 1; info.port = CONTEXT_PORT_NO_LISTEN; @@ -527,7 +527,7 @@ int main(int argc, const char **argv) /* connect to ssproxy via UDS by default, else via * tcp connection to this port */ if ((p = lws_cmdline_option(argc, argv, "-p"))) - info.ss_proxy_port = atoi(p); + info.ss_proxy_port = (uint16_t)atoi(p); /* UDS "proxy.ss.lws" in abstract namespace, else this socket * path; when -p given this can specify the network interface diff --git a/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c b/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c index 6fbaf9936..7ad0b84ee 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c @@ -68,7 +68,7 @@ myss_raw_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; - *len = lws_snprintf((char *)buf, *len, "hello from raw %d\n", m->count++); + *len = (unsigned int)lws_snprintf((char *)buf, *len, "hello from raw %d\n", m->count++); lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, 100 * LWS_US_PER_MS); @@ -83,7 +83,7 @@ myss_raw_state(void *userobj, void *sh, lws_ss_constate_t state, myss_srv_t *m = (myss_srv_t *)userobj; lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, - lws_ss_state_name(state), (unsigned int)ack); + lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { case LWSSSCS_DISCONNECTED: diff --git a/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c b/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c index 77f7ec118..64834c377 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c @@ -58,7 +58,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, myss_t *m = (myss_t *)userobj; lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, - lws_ss_state_name(state), (unsigned int)ack); + lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { case LWSSSCS_CREATING: diff --git a/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c b/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c index 85609fba2..295250149 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c @@ -148,7 +148,7 @@ myss_ws_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; - *len = lws_snprintf((char *)buf, *len, "hello from ws %d", m->count++); + *len = (unsigned int)lws_snprintf((char *)buf, *len, "hello from ws %d", m->count++); lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, 100 * LWS_US_PER_MS); @@ -163,7 +163,7 @@ myss_srv_state(void *userobj, void *sh, lws_ss_constate_t state, myss_srv_t *m = (myss_srv_t *)userobj; lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, - lws_ss_state_name(state), (unsigned int)ack); + lws_ss_state_name((int)state), (unsigned int)ack); switch (state) { case LWSSSCS_DISCONNECTED: diff --git a/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt b/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt index 3d0762c28..9d14c00c0 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt +++ b/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt @@ -15,9 +15,19 @@ require_lws_config(LWS_WITH_SYS_STATE 1 requirements) if (requirements) add_executable(${PROJECT_NAME} minimal-secure-streams-smd.c) + + find_program(VALGRIND "valgrind") - if (LWS_CTEST_INTERNET_AVAILABLE) - add_test(NAME ss-smd COMMAND lws-minimal-secure-streams-smd) + if (LWS_CTEST_INTERNET_AVAILABLE AND NOT WIN32) + + if (VALGRIND) + add_test(NAME ss-smd COMMAND + ${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20 + $) + else() + + add_test(NAME ss-smd COMMAND lws-minimal-secure-streams-smd) + endif() set_tests_properties(ss-smd PROPERTIES WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams-smd diff --git a/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c b/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c index 61c516700..b772b0c3a 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c +++ b/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c @@ -117,12 +117,12 @@ myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, /* * after a few, let's request a CPD check */ - *len = LWS_SMD_SS_RX_HEADER_LEN + + *len = LWS_SMD_SS_RX_HEADER_LEN + (unsigned int) lws_snprintf((char *)buf + LWS_SMD_SS_RX_HEADER_LEN, *len, "{\"trigger\": \"cpdcheck\", \"src\":\"SS-test\"}"); } else - *len = LWS_SMD_SS_RX_HEADER_LEN + + *len = LWS_SMD_SS_RX_HEADER_LEN + (unsigned int) lws_snprintf((char *)buf + LWS_SMD_SS_RX_HEADER_LEN, *len, (m->alternate & 1) ? "{\"class\":\"NETWORK\"}" : "{\"class\":\"INTERACTION\"}"); diff --git a/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c b/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c index cbf7bf3b0..fbd5f949f 100644 --- a/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c +++ b/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c @@ -272,7 +272,7 @@ myss_state(void *userobj, void *sh, lws_ss_constate_t state, myss_t *m = (myss_t *)userobj; lwsl_user("%s: %s (%d), ord 0x%x\n", __func__, - lws_ss_state_name(state), state, (unsigned int)ack); + lws_ss_state_name((int)state), state, (unsigned int)ack); switch (state) { case LWSSSCS_CREATING: @@ -439,7 +439,7 @@ int main(int argc, const char **argv) test_respmap = 1; if ((p = lws_cmdline_option(argc, argv, "--timeout_ms"))) - timeout_ms = atoi(p); + timeout_ms = (unsigned int)atoi(p); info.fd_limit_per_thread = 1 + 6 + 1; info.port = CONTEXT_PORT_NO_LISTEN; @@ -451,7 +451,7 @@ int main(int argc, const char **argv) /* connect to ssproxy via UDS by default, else via * tcp connection to this port */ if ((p = lws_cmdline_option(argc, argv, "-p"))) - info.ss_proxy_port = atoi(p); + info.ss_proxy_port = (uint16_t)atoi(p); /* UDS "proxy.ss.lws" in abstract namespace, else this socket * path; when -p given this can specify the network interface diff --git a/minimal-examples/ws-client/minimal-ws-client-binance/main.c b/minimal-examples/ws-client/minimal-ws-client-binance/main.c index 842547960..a8ecadf80 100644 --- a/minimal-examples/ws-client/minimal-ws-client-binance/main.c +++ b/minimal-examples/ws-client/minimal-ws-client-binance/main.c @@ -16,11 +16,11 @@ #include typedef struct range { - lws_usec_t sum; - lws_usec_t lowest; - lws_usec_t highest; + uint64_t sum; + uint64_t lowest; + uint64_t highest; - int samples; + unsigned int samples; } range_t; /* @@ -167,7 +167,7 @@ get_us_timeofday(void) gettimeofday(&tv, NULL); - return ((lws_usec_t)tv.tv_sec * LWS_US_PER_SEC) + tv.tv_usec; + return (uint64_t)((lws_usec_t)tv.tv_sec * LWS_US_PER_SEC) + (uint64_t)tv.tv_usec; } static void @@ -211,7 +211,7 @@ pennies(const char *s) s = strchr(s, '.'); if (s && isdigit(s[1]) && isdigit(s[2])) - price += (10 * (s[1] - '0')) + (s[2] - '0'); + price = price + (uint64_t)((10 * (s[1] - '0')) + (s[2] - '0')); return price; } @@ -221,7 +221,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { struct my_conn *mco = (struct my_conn *)user; - lws_usec_t latency_us, now_us, price; + uint64_t latency_us, now_us; + uint64_t price; char numbuf[16]; const char *p; size_t alen; @@ -241,7 +242,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, // lwsl_hexdump_notice(in, len); - now_us = get_us_timeofday(); + now_us = (uint64_t)get_us_timeofday(); p = lws_json_simple_find((const char *)in, len, "\"depthUpdate\"", &alen); @@ -259,7 +260,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, } lws_strnncpy(numbuf, p, alen, sizeof(numbuf)); latency_us = now_us - - ((lws_usec_t)atoll(numbuf) * LWS_US_PER_MS); + ((uint64_t)atoll(numbuf) * LWS_US_PER_MS); if (latency_us < mco->e_lat_range.lowest) mco->e_lat_range.lowest = latency_us; @@ -357,7 +358,7 @@ int main(int argc, const char **argv) * told which CA to trust explicitly. */ info.client_ssl_ca_mem = ca_pem_digicert_global_root; - info.client_ssl_ca_mem_len = strlen(ca_pem_digicert_global_root); + info.client_ssl_ca_mem_len = (unsigned int)strlen(ca_pem_digicert_global_root); #endif context = lws_create_context(&info); diff --git a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c index 60014951d..629ad7094 100644 --- a/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c +++ b/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c @@ -178,7 +178,7 @@ callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason, /* notice we allowed for LWS_PRE in the payload already */ m = lws_write(wsi, ((unsigned char *)pmsg->payload) + - LWS_PRE, pmsg->len, flags); + LWS_PRE, pmsg->len, (enum lws_write_protocol)flags); if (m < (int)pmsg->len) { lwsl_err("ERROR %d writing to ws socket\n", m); return -1; @@ -217,9 +217,9 @@ callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason, // lwsl_hexdump_notice(in, len); - amsg.first = lws_is_first_fragment(wsi); - amsg.final = lws_is_final_fragment(wsi); - amsg.binary = lws_frame_is_binary(wsi); + amsg.first = (char)lws_is_first_fragment(wsi); + amsg.final = (char)lws_is_final_fragment(wsi); + amsg.binary = (char)lws_frame_is_binary(wsi); n = (int)lws_ring_get_count_free_elements(pss->ring); if (!n) { lwsl_user("dropping!\n"); diff --git a/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c b/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c index c7564ac50..b7f7697ba 100644 --- a/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c +++ b/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c @@ -179,9 +179,9 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, size_t s; m = pss->position_tx % REPEAT_STRING_LEN; - s = REPEAT_STRING_LEN - m; + s = (unsigned int)(REPEAT_STRING_LEN - m); if (s > (size_t)n) - s = n; + s = (unsigned int)n; memcpy(p, &redundant_string[m], s); pss->position_tx += (int)s; p += s; @@ -194,7 +194,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, } n = lws_ptr_diff(p, start); - m = lws_write(wsi, start, n, flags); + m = lws_write(wsi, start, (unsigned int)n, (enum lws_write_protocol)flags); if (m < n) { lwsl_err("ERROR %d writing ws\n", m); return -1; @@ -222,7 +222,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, size_t s; m = pss->position_rx % REPEAT_STRING_LEN; - s = REPEAT_STRING_LEN - m; + s = (unsigned int)(REPEAT_STRING_LEN - m); if (s > len) s = len; if (memcmp(in, &redundant_string[m], s)) { diff --git a/minimal-examples/ws-client/minimal-ws-client-spam-tx-rx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-spam-tx-rx/minimal-ws-client.c index f611e4661..2b9b26058 100644 --- a/minimal-examples/ws-client/minimal-ws-client-spam-tx-rx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-spam-tx-rx/minimal-ws-client.c @@ -144,7 +144,7 @@ int main(int argc, const char **argv) int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; #ifndef WIN32 - srandom(time(0)); + srandom((unsigned int)time(0)); #endif memset(msg, 'x', sizeof(msg)); @@ -201,7 +201,7 @@ int main(int argc, const char **argv) lwsl_notice("Message delay: %d\n", connection_delay); } - info.fd_limit_per_thread = 1 + nclients + 1; + info.fd_limit_per_thread = (unsigned int)(1 + nclients + 1); context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c b/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c index 4989aac50..20b89df2a 100644 --- a/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c +++ b/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c @@ -150,7 +150,7 @@ callback_minimal_spam(struct lws *wsi, enum lws_callback_reasons reason, n = lws_snprintf((char *)ping + LWS_PRE, sizeof(ping) - LWS_PRE, "hello %d", pss->conn); - m = lws_write(wsi, ping + LWS_PRE, n, LWS_WRITE_TEXT); + m = lws_write(wsi, ping + LWS_PRE, (unsigned int)n, LWS_WRITE_TEXT); if (m < n) { lwsl_err("sending ping failed: %d\n", m); @@ -248,7 +248,7 @@ int main(int argc, const char **argv) * It will just allocate for 1 internal and n (+ 1 http2 nwsi) that we * will use. */ - info.fd_limit_per_thread = 1 + concurrent + 1; + info.fd_limit_per_thread = (unsigned int)(1 + concurrent + 1); context = lws_create_context(&info); if (!context) { diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c index 2e78a19e6..d31beb133 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c +++ b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c @@ -98,14 +98,14 @@ thread_spam(void *d) goto wait_unlock; } - amsg.payload = malloc(LWS_PRE + len); + amsg.payload = malloc((unsigned int)(LWS_PRE + len)); if (!amsg.payload) { lwsl_user("OOM: dropping\n"); goto wait_unlock; } - n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, + n = lws_snprintf((char *)amsg.payload + LWS_PRE, (unsigned int)len, "tid: %d, msg: %d", whoami, index++); - amsg.len = n; + amsg.len = (unsigned int)n; n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); diff --git a/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c b/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c index 5b5683373..84c67f1e0 100644 --- a/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c +++ b/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c @@ -124,7 +124,7 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason, /* notice we allowed for LWS_PRE in the payload already */ m = lws_write(wsi, ((unsigned char *)pmsg->payload) + - LWS_PRE, pmsg->len, flags); + LWS_PRE, pmsg->len, (enum lws_write_protocol)flags); if (m < (int)pmsg->len) { lwsl_err("ERROR %d writing to ws socket\n", m); return -1; @@ -168,9 +168,9 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason, //lwsl_hexdump_notice(in, len); } - amsg.first = lws_is_first_fragment(wsi); - amsg.final = lws_is_final_fragment(wsi); - amsg.binary = lws_frame_is_binary(wsi); + amsg.first = (char)lws_is_first_fragment(wsi); + amsg.final = (char)lws_is_final_fragment(wsi); + amsg.binary = (char)lws_frame_is_binary(wsi); n = (int)lws_ring_get_count_free_elements(pss->ring); if (!n) { lwsl_user("dropping!\n"); @@ -180,7 +180,7 @@ callback_minimal_server_echo(struct lws *wsi, enum lws_callback_reasons reason, if (amsg.final) pss->msglen = 0; else - pss->msglen += len; + pss->msglen += (uint32_t)len; amsg.len = len; /* notice we over-allocate by LWS_PRE */ diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c index 301996dae..22b99a19d 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c @@ -143,9 +143,9 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, size_t s; m = pss->position_tx % REPEAT_STRING_LEN; - s = REPEAT_STRING_LEN - m; + s = (unsigned int)(REPEAT_STRING_LEN - m); if (s > (size_t)n) - s = n; + s = (unsigned int)n; memcpy(p, &redundant_string[m], s); pss->position_tx += (int)s; p += s; @@ -158,7 +158,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, } n = lws_ptr_diff(p, start); - m = lws_write(wsi, start, n, flags); + m = lws_write(wsi, start, (unsigned int)n, (enum lws_write_protocol)flags); lwsl_user("LWS_CALLBACK_SERVER_WRITEABLE: wrote %d\n", n); if (m < n) { lwsl_err("ERROR %d / %d writing ws\n", m, n); @@ -178,7 +178,7 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, while (len) { size_t s; m = pss->position_rx % REPEAT_STRING_LEN; - s = REPEAT_STRING_LEN - m; + s = (unsigned int)(REPEAT_STRING_LEN - m); if (s > len) s = len; if (memcmp(in, &redundant_string[m], s)) { @@ -196,8 +196,8 @@ callback_minimal_pmd_bulk(struct lws *wsi, enum lws_callback_reasons reason, if (*p++ != (uint8_t)rng(&pss->rng_rx)) { lwsl_user("echo'd data doesn't match: 0x%02X 0x%02X (%d)\n", *(p - 1), (int)(0x40 + (pss->rng_rx & 0x3f)), - (int)((pss->position_rx - olen) + olen - len)); - lwsl_hexdump_notice(in, olen); + (int)((pss->position_rx - olen) + olen - (int)len)); + lwsl_hexdump_notice(in, (unsigned int)olen); return -1; } } diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c index 90ab25d66..785fec35b 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c @@ -241,10 +241,10 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, corner_lengths[pss->last - 1]); memcpy(buf + LWS_PRE, uncompressible, - corner_lengths[pss->last - 1]); + (unsigned int)corner_lengths[pss->last - 1]); /* notice we allowed for LWS_PRE in the payload already */ - m = lws_write(wsi, buf + LWS_PRE, corner_lengths[pss->last - 1], + m = lws_write(wsi, buf + LWS_PRE, (unsigned int)corner_lengths[pss->last - 1], LWS_WRITE_BINARY); if (m < corner_lengths[pss->last - 1]) { lwsl_err("ERROR %d writing to ws socket\n", m); diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c index c809c5e72..4b6e87ecf 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c @@ -129,7 +129,7 @@ cull_lagging_clients(struct per_vhost_data__minimal *vhd) */ lws_ring_consume_and_update_oldest_tail(vhd->ring, - struct per_session_data__minimal, &old_pss->tail, before - most, + struct per_session_data__minimal, &old_pss->tail, (size_t)(before - most), vhd->pss_list, tail, pss_list); lwsl_user("%s: shrunk ring from %d to %d\n", __func__, before, most); diff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c index 67b5049f1..c93d742b0 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c +++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c @@ -267,7 +267,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, task = lws_threadpool_get_task_wsi(wsi); if (!task) break; - n = lws_threadpool_task_status(task, &_user); + n = (int)lws_threadpool_task_status(task, &_user); lwsl_debug("%s: LWS_CALLBACK_SERVER_WRITEABLE: status %d\n", __func__, n); switch(n) { @@ -292,7 +292,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, n = (int)strlen(priv->result + LWS_PRE); m = lws_write(wsi, (unsigned char *)priv->result + LWS_PRE, - n, LWS_WRITE_TEXT); + (unsigned int)n, LWS_WRITE_TEXT); if (m < n) { lwsl_err("ERROR %d writing to ws socket\n", m); lws_threadpool_task_sync(task, 1); diff --git a/minimal-examples/ws-server/minimal-ws-server-threads-foreign-libuv-smp/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads-foreign-libuv-smp/protocol_lws_minimal.c index 2818c1e7b..7feaaca75 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads-foreign-libuv-smp/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads-foreign-libuv-smp/protocol_lws_minimal.c @@ -107,15 +107,15 @@ thread_spam(void *d) goto wait_unlock; } - amsg.payload = malloc(LWS_PRE + len); + amsg.payload = malloc((unsigned int)(LWS_PRE + len)); if (!amsg.payload) { lwsl_user("OOM: dropping\n"); goto wait_unlock; } - n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, + n = lws_snprintf((char *)amsg.payload + LWS_PRE, (unsigned int)len, "%s: spam tid: %d, msg: %d", vhd->config, whoami, index++); - amsg.len = n; + amsg.len = (unsigned int)n; n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); @@ -249,7 +249,7 @@ init_fail: (char *)pmsg->payload + LWS_PRE); /* notice we allowed for LWS_PRE in the payload already */ - m = lws_write(wsi, (unsigned char *)temp + LWS_PRE, n, + m = lws_write(wsi, (unsigned char *)temp + LWS_PRE, (unsigned int)n, LWS_WRITE_TEXT); if (m < n) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ diff --git a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c index 2bc3284b6..8c085aa8d 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c @@ -103,15 +103,15 @@ thread_spam(void *d) goto wait_unlock; } - amsg.payload = malloc(LWS_PRE + len); + amsg.payload = malloc((unsigned int)(LWS_PRE + len)); if (!amsg.payload) { lwsl_user("OOM: dropping\n"); goto wait_unlock; } - n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, + n = lws_snprintf((char *)amsg.payload + LWS_PRE, (unsigned int)len, "%s: spam tid: %d, msg: %d", vhd->config, whoami, index++); - amsg.len = n; + amsg.len = (unsigned int)n; n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); @@ -238,7 +238,7 @@ init_fail: (char *)pmsg->payload + LWS_PRE); /* notice we allowed for LWS_PRE in the payload already */ - m = lws_write(wsi, (unsigned char *)temp + LWS_PRE, n, + m = lws_write(wsi, (unsigned char *)temp + LWS_PRE, (unsigned int)n, LWS_WRITE_TEXT); if (m < n) { pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c index 2b9c09a51..e01f64d69 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c @@ -103,16 +103,16 @@ thread_spam(void *d) goto wait_unlock; } - amsg.payload = malloc(LWS_PRE + len); + amsg.payload = malloc((unsigned int)(LWS_PRE + len)); if (!amsg.payload) { lwsl_user("OOM: dropping\n"); goto wait_unlock; } - n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, + n = lws_snprintf((char *)amsg.payload + LWS_PRE, (unsigned int)len, "%s: tid: %d, msg: %d", vhd->config, whoami, index++); - amsg.len = n; - n = lws_ring_insert(vhd->ring, &amsg, 1); + amsg.len = (unsigned int)n; + n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); lwsl_user("dropping!\n"); diff --git a/plugins/acme-client/protocol_lws_acme_client.c b/plugins/acme-client/protocol_lws_acme_client.c index 12b204778..bdb52b1ef 100644 --- a/plugins/acme-client/protocol_lws_acme_client.c +++ b/plugins/acme-client/protocol_lws_acme_client.c @@ -157,8 +157,8 @@ callback_chall_http01(struct lws *wsi, enum lws_callback_reasons reason, return -1; } - n = strlen(ac->key_auth); - if (lws_add_http_header_content_length(wsi, n, &p, end)) { + n = (int)strlen(ac->key_auth); + if (lws_add_http_header_content_length(wsi, (lws_filepos_t)n, &p, end)) { lwsl_notice("%s: add content_length failed\n", __func__); return -1; @@ -182,9 +182,9 @@ callback_chall_http01(struct lws *wsi, enum lws_callback_reasons reason, return 0; case LWS_CALLBACK_HTTP_WRITEABLE: - p += lws_snprintf((char *)p, end - p, "%s", ac->key_auth); + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%s", ac->key_auth); lwsl_notice("%s: len %d\n", __func__, lws_ptr_diff(p, start)); - if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_FINAL) != lws_ptr_diff(p, start)) { lwsl_err("_write content failed\n"); return 1; @@ -225,7 +225,7 @@ jws_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, * here temporarily. */ n = LWS_PRE + 2048; - buf = malloc(n); + buf = malloc((unsigned int)n); if (!buf) { lwsl_notice("%s: malloc %d failed\n", __func__, n); return -1; @@ -240,12 +240,12 @@ jws_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, if (!jwe->jose.alg || !jwe->jose.alg->alg) goto bail; - p += lws_snprintf(p, end - p, "{\"alg\":\"RS256\""); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"alg\":\"RS256\""); if (kid) - p += lws_snprintf(p, end - p, ",\"kid\":\"%s\"", kid); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ",\"kid\":\"%s\"", kid); else { - p += lws_snprintf(p, end - p, ",\"jwk\":"); - m = end - p; + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ",\"jwk\":"); + m = lws_ptr_diff(end, p); n = lws_jwk_export(&jwe->jwk, 0, p, &m); if (n < 0) { lwsl_notice("failed to export jwk\n"); @@ -253,8 +253,8 @@ jws_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, } p += n; } - p += lws_snprintf(p, end - p, ",\"url\":\"%s\"", url); - p += lws_snprintf(p, end - p, ",\"nonce\":\"%s\"}", nonce); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ",\"url\":\"%s\"", url); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ",\"nonce\":\"%s\"}", nonce); /* * prepare the signed outer JSON with all the parts in @@ -262,47 +262,47 @@ jws_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, p1 = out; end1 = out + out_len - 1; - p1 += lws_snprintf(p1, end1 - p1, "{\"protected\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "{\"protected\":\""); jws.map_b64.buf[LJWS_JOSE] = p1; - n = lws_jws_base64_enc(start, p - start, p1, end1 - p1); + n = lws_jws_base64_enc(start, lws_ptr_diff_size_t(p, start), p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode protected\n", __func__); goto bail; } - jws.map_b64.len[LJWS_JOSE] = n; + jws.map_b64.len[LJWS_JOSE] = (uint32_t)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\",\"payload\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\"payload\":\""); jws.map_b64.buf[LJWS_PYLD] = p1; - n = lws_jws_base64_enc(payload, len, p1, end1 - p1); + n = lws_jws_base64_enc(payload, len, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("%s: failed to encode payload\n", __func__); goto bail; } - jws.map_b64.len[LJWS_PYLD] = n; + jws.map_b64.len[LJWS_PYLD] = (uint32_t)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\",\"signature\":\""); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\",\"signature\":\""); /* * taking the b64 protected header and the b64 payload, sign them * and place the signature into the packet */ - n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, end1 - p1); + n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, lws_ptr_diff_size_t(end1, p1)); if (n < 0) { lwsl_notice("sig gen failed\n"); goto bail; } jws.map_b64.buf[LJWS_SIG] = p1; - jws.map_b64.len[LJWS_SIG] = n; + jws.map_b64.len[LJWS_SIG] = (uint32_t)n; p1 += n; - p1 += lws_snprintf(p1, end1 - p1, "\"}"); + p1 += lws_snprintf(p1, lws_ptr_diff_size_t(end1, p1), "\"}"); free(buf); - return p1 - out; + return lws_ptr_diff(p1, out); bail: lws_jws_destroy(&jws); @@ -570,7 +570,7 @@ static int lws_acme_report_status(struct lws_vhost *v, int state, const char *json) { lws_callback_vhost_protocols_vhost(v, LWS_CALLBACK_VHOST_CERT_UPDATE, - (void *)json, state); + (void *)json, (unsigned int)state); return 0; } @@ -799,18 +799,18 @@ callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, m = 0; pvo = (const struct lws_protocol_vhost_options *)in; while (pvo) { - m += strlen(pvo->value) + 1; + m += (int)strlen(pvo->value) + 1; pvo = pvo->next; } - p = vhd->pvo_data = malloc(m); + p = vhd->pvo_data = malloc((unsigned int)m); if (!p) return -1; pvo = (const struct lws_protocol_vhost_options *)in; while (pvo) { start = p; - n = strlen(pvo->value) + 1; - memcpy(start, pvo->value, n); + n = (int)strlen(pvo->value) + 1; + memcpy(start, pvo->value, (unsigned int)n); p += n; for (m = 0; m < (int)LWS_ARRAY_SIZE(pvo_names); m++) @@ -941,7 +941,7 @@ callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, ac->state, lws_http_client_http_response(wsi)); if (!ac) break; - ac->resp = lws_http_client_http_response(wsi); + ac->resp = (int)lws_http_client_http_response(wsi); /* we get a new nonce each time */ if (lws_hdr_total_length(wsi, WSI_TOKEN_REPLAY_NONCE) && lws_hdr_copy(wsi, ac->replay_nonce, @@ -1046,7 +1046,7 @@ callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, break; case ACME_STATE_NEW_ACCOUNT: - p += lws_snprintf(p, end - p, "{" + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{" "\"termsOfServiceAgreed\":true" ",\"contact\": [\"mailto:%s\"]}", vhd->pvop_active[LWS_TLS_REQ_ELEMENT_EMAIL]); @@ -1063,7 +1063,7 @@ pkt_add_hdrs: jwe.jwk = vhd->jwk; ac->len = jws_create_packet(&jwe, - start, p - start, + start, lws_ptr_diff_size_t(p, start), ac->replay_nonce, ac->active_url, ac->kid, @@ -1103,7 +1103,7 @@ pkt_add_hdrs: break; case ACME_STATE_NEW_ORDER: - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{" "\"identifiers\":[{" "\"type\":\"dns\"," @@ -1125,7 +1125,7 @@ pkt_add_hdrs: p = start; end = &buf[sizeof(buf) - 1]; - p += lws_snprintf(p, end - p, "{}"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{}"); puts(start); strcpy(ac->active_url, ac->challenge_uri); goto pkt_add_hdrs; @@ -1138,10 +1138,10 @@ pkt_add_hdrs: if (ac->goes_around) break; - p += lws_snprintf(p, end - p, "{\"csr\":\""); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"csr\":\""); n = lws_tls_acme_sni_csr_create(vhd->context, &vhd->pvop_active[0], - (uint8_t *)p, end - p, + (uint8_t *)p, lws_ptr_diff_size_t(end, p), &ac->alloc_privkey_pem, &ac->len_privkey_pem); if (n < 0) { @@ -1149,7 +1149,7 @@ pkt_add_hdrs: goto failed; } p += n; - p += lws_snprintf(p, end - p, "\"}"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "\"}"); puts(start); strcpy(ac->active_url, ac->finalize_url); goto pkt_add_hdrs; @@ -1175,7 +1175,7 @@ pkt_add_hdrs: ac->buf[LWS_PRE + ac->len] = '\0'; if (lws_write(wsi, (uint8_t *)ac->buf + LWS_PRE, - ac->len, LWS_WRITE_HTTP_FINAL) < 0) + (size_t)ac->len, LWS_WRITE_HTTP_FINAL) < 0) return -1; lwsl_notice("wrote %d\n", ac->len); ac->pos = ac->len; @@ -1196,7 +1196,7 @@ pkt_add_hdrs: case ACME_STATE_DIRECTORY: ((char *)in)[len] = '\0'; puts(in); - m = lejp_parse(&ac->jctx, (uint8_t *)in, len); + m = lejp_parse(&ac->jctx, (uint8_t *)in, (int)len); if (m < 0 && m != LEJP_CONTINUE) { lwsl_notice("lejp parse failed %d\n", m); goto failed; @@ -1210,12 +1210,12 @@ pkt_add_hdrs: ((char *)in)[len] = '\0'; puts(in); /* it should be the DER cert! */ - if (ac->cpos + len > sizeof(ac->buf)) { + if ((unsigned int)ac->cpos + len > sizeof(ac->buf)) { lwsl_notice("Incoming cert is too large!\n"); goto failed; } memcpy(&ac->buf[ac->cpos], in, len); - ac->cpos += len; + ac->cpos += (int)len; break; default: break; @@ -1346,9 +1346,9 @@ pkt_add_hdrs: p = ac->key_auth; end = p + sizeof(ac->key_auth) - 1; - p += lws_snprintf(p, end - p, "%s.", ac->chall_token); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%s.", ac->chall_token); lws_jwk_rfc7638_fingerprint(&vhd->jwk, digest); - n = lws_jws_base64_enc(digest, 32, p, end - p); + n = lws_jws_base64_enc(digest, 32, p, lws_ptr_diff_size_t(end, p)); if (n < 0) goto failed; @@ -1362,7 +1362,7 @@ pkt_add_hdrs: memset(&ac->mount, 0, sizeof (struct lws_http_mount)); ac->mount.protocol = "http"; ac->mount.mountpoint = ac->http01_mountpoint; - ac->mount.mountpoint_len = + ac->mount.mountpoint_len = (unsigned char) strlen(ac->http01_mountpoint); ac->mount.origin_protocol = LWSMPRO_CALLBACK; @@ -1548,7 +1548,7 @@ poll_again: n = lws_plat_write_cert(vhd->vhost, 0, vhd->fd_updated_cert, ac->buf, - ac->cpos); + (size_t)ac->cpos); if (n) { lwsl_err("unable to write ACME cert! %d\n", n); goto failed; @@ -1580,7 +1580,7 @@ poll_again: if (lws_tls_cert_updated(vhd->context, vhd->pvop_active[LWS_TLS_SET_CERT_PATH], vhd->pvop_active[LWS_TLS_SET_KEY_PATH], - ac->buf, ac->cpos, + ac->buf, (size_t)ac->cpos, ac->alloc_privkey_pem, ac->len_privkey_pem)) { lwsl_notice("problem setting certs\n"); diff --git a/plugins/deaddrop/protocol_lws_deaddrop.c b/plugins/deaddrop/protocol_lws_deaddrop.c index 2885706a9..713f82bb7 100644 --- a/plugins/deaddrop/protocol_lws_deaddrop.c +++ b/plugins/deaddrop/protocol_lws_deaddrop.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -129,11 +129,12 @@ static int scan_upload_dir(struct vhd_deaddrop *vhd) { char filepath[256], subdir[3][128], *p; - int m, sp = 0, initial, found = 0; struct lwsac *lwsac_head = NULL; lws_list_ptr sorted_head = NULL; + int i, sp = 0, found = 0; struct dir_entry *dire; struct dirent *de; + size_t initial, m; struct stat s; DIR *dir[3]; @@ -162,11 +163,11 @@ scan_upload_dir(struct vhd_deaddrop *vhd) p = filepath; - for (m = 0; m <= sp; m++) - p += lws_snprintf(p, (filepath + sizeof(filepath)) - p, - "%s/", subdir[m]); + for (i = 0; i <= sp; i++) + p += lws_snprintf(p, lws_ptr_diff_size_t((filepath + sizeof(filepath)), p), + "%s/", subdir[i]); - lws_snprintf(p, (filepath + sizeof(filepath)) - p, "%s", + lws_snprintf(p, lws_ptr_diff_size_t((filepath + sizeof(filepath)), p), "%s", de->d_name); /* ignore temp files */ @@ -211,7 +212,7 @@ scan_upload_dir(struct vhd_deaddrop *vhd) } dire->next = NULL; - dire->size = s.st_size; + dire->size = (unsigned long long)s.st_size; dire->mtime = s.st_mtime; dire->user[0] = '\0'; #if !defined(__COVERITY__) @@ -257,10 +258,11 @@ bail: static int file_upload_cb(void *data, const char *name, const char *filename, - char *buf, int len, enum lws_spa_fileupload_states state) + char *buf, int _len, enum lws_spa_fileupload_states state) { struct pss_deaddrop *pss = (struct pss_deaddrop *)data; char filename2[256]; + size_t len = (size_t)_len; int n; (void)n; @@ -300,7 +302,7 @@ file_upload_cb(void *data, const char *name, const char *filename, case LWS_UFS_FINAL_CONTENT: case LWS_UFS_CONTENT: if (len) { - pss->file_length += len; + pss->file_length += (unsigned int)len; /* if the file length is too big, drop it */ if (pss->file_length > pss->vhd->max_size) { @@ -314,9 +316,9 @@ file_upload_cb(void *data, const char *name, const char *filename, } if (pss->fd != LWS_INVALID_FILE) { - n = write((int)(lws_intptr_t)pss->fd, buf, len); + n = (int)write((int)(lws_intptr_t)pss->fd, buf, (unsigned int)len); lwsl_debug("%s: write %d says %d\n", __func__, - len, n); + (int)len, n); lws_set_timeout(pss->wsi, PENDING_TIMEOUT_HTTP_CONTENT, 30); } } @@ -357,12 +359,12 @@ format_result(struct pss_deaddrop *pss) start = p; end = p + sizeof(pss->result) - LWS_PRE - 1; - p += lws_snprintf((char *)p, end -p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "" "" ""); - p += lws_snprintf((char *)p, end - p, ""); + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), ""); return (int)lws_ptr_diff(p, start); } @@ -399,7 +401,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, vhd->max_size = 20 * 1024 * 1024; /* default without pvo */ if (!lws_pvo_get_str(in, "max-size", &cp)) - vhd->max_size = atoll(cp); + vhd->max_size = (unsigned long long)atoll(cp); if (lws_pvo_get_str(in, "upload-dir", &vhd->upload_dir)) { lwsl_err("%s: requires 'upload-dir' pvo\n", __func__); return -1; @@ -460,10 +462,10 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, cp = strchr((const char *)in, '/'); if (cp) { - n = ((void *)cp - in) - 8; + n = (int)(((void *)cp - in)) - 8; if ((int)strlen(pss->user) != n || - memcmp(pss->user, ((const char *)in) + 8, n)) { + memcmp(pss->user, ((const char *)in) + 8, (unsigned int)n)) { lwsl_notice("%s: del: auth mismatch " " '%s' '%s' (%d)\n", __func__, pss->user, @@ -496,7 +498,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, was = 0; if (pss->first) { - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "{\"max_size\":%llu, \"files\": [", vhd->max_size); was = 1; @@ -504,7 +506,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, m = 5; while (m-- && pss->dire) { - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%c{\"name\":\"%s\", " "\"size\":%llu," "\"mtime\":%llu," @@ -520,7 +522,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, } if (!pss->dire) { - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}"); if (pss->lwsac_head) { lwsac_unreference(&pss->lwsac_head); @@ -528,8 +530,8 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, } } - n = lws_write(wsi, start, lws_ptr_diff(p, start), - lws_write_ws_flags(LWS_WRITE_TEXT, was, + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), + (enum lws_write_protocol)lws_write_ws_flags(LWS_WRITE_TEXT, was, !pss->dire)); if (n < 0) { lwsl_notice("%s: ws write failed\n", __func__); @@ -609,7 +611,8 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, if (!pss->sent_headers) { n = format_result(pss); - if (lws_add_http_header_status(wsi, pss->response_code, + if (lws_add_http_header_status(wsi, + (unsigned int)pss->response_code, &p, end)) goto bail; @@ -618,13 +621,13 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, (unsigned char *)"text/html", 9, &p, end)) goto bail; - if (lws_add_http_header_content_length(wsi, n, &p, end)) + if (lws_add_http_header_content_length(wsi, (lws_filepos_t)n, &p, end)) goto bail; if (lws_finalize_http_header(wsi, &p, end)) goto bail; /* first send the headers ... */ - n = lws_write(wsi, start, lws_ptr_diff(p, start), + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); if (n < 0) @@ -637,7 +640,7 @@ callback_deaddrop(struct lws *wsi, enum lws_callback_reasons reason, if (!pss->sent_body) { n = format_result(pss); - n = lws_write(wsi, (unsigned char *)start, n, + n = lws_write(wsi, (unsigned char *)start, (unsigned int)n, LWS_WRITE_HTTP_FINAL); pss->sent_body = 1; diff --git a/plugins/protocol_dumb_increment.c b/plugins/protocol_dumb_increment.c index fafe26dcb..fa7326380 100644 --- a/plugins/protocol_dumb_increment.c +++ b/plugins/protocol_dumb_increment.c @@ -71,7 +71,7 @@ callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_SERVER_WRITEABLE: n = lws_snprintf((char *)p, sizeof(buf) - LWS_PRE, "%d", pss->number++); - m = lws_write(wsi, p, n, LWS_WRITE_TEXT); + m = lws_write(wsi, p, (unsigned int)n, LWS_WRITE_TEXT); if (m < n) { lwsl_err("ERROR %d writing to di socket\n", n); return -1; diff --git a/plugins/protocol_fulltext_demo.c b/plugins/protocol_fulltext_demo.c index aaec4a461..1fe167c38 100644 --- a/plugins/protocol_fulltext_demo.c +++ b/plugins/protocol_fulltext_demo.c @@ -158,11 +158,11 @@ reply_404: n = LWS_WRITE_HTTP; if (pss->first) - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "{\"indexed\": %d, \"ac\": [", !!pss->result); while (pss->ac && lws_ptr_diff(end, p) > 256) { - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%c{\"ac\": \"%s\",\"matches\": %d," "\"agg\": %d, \"elided\": %d}", pss->first ? ' ' : ',', (char *)(pss->ac + 1), @@ -176,14 +176,14 @@ reply_404: if (!pss->ac_done && !pss->ac && pss->fp) { pss->ac_done = 1; - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "], \"fp\": ["); } - while (pss->fp && lws_ptr_diff(end, p) > 256) { + while (pss->fp && lws_ptr_diff_size_t(end, p) > 256) { if (!pss->fp_init_done) { p += lws_snprintf((char *)p, - lws_ptr_diff(end, p), + lws_ptr_diff_size_t(end, p), "%c{\"path\": \"%s\",\"matches\": %d," "\"origlines\": %d," "\"hits\": [", pss->first ? ' ' : ',', @@ -201,7 +201,7 @@ reply_404: lws_ptr_diff(end, p) > 256) { p += lws_snprintf((char *)p, - lws_ptr_diff(end, p), + lws_ptr_diff_size_t(end, p), "%c\n{\"l\":%d,\"o\":%d," "\"s\":\"%s\"}", !pss->done ? ' ' : ',', @@ -224,12 +224,12 @@ reply_404: if (!pss->ac && !pss->fp) { n = LWS_WRITE_HTTP_FINAL; - p += lws_snprintf((char *)p, lws_ptr_diff(end, p), + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}"); } if (lws_write(wsi, (uint8_t *)start, - lws_ptr_diff(p, start), n) != + lws_ptr_diff_size_t(p, start), (enum lws_write_protocol)n) != lws_ptr_diff(p, start)) return 1; diff --git a/plugins/protocol_lws_mirror.c b/plugins/protocol_lws_mirror.c index 8ba111de8..249f82f55 100644 --- a/plugins/protocol_lws_mirror.c +++ b/plugins/protocol_lws_mirror.c @@ -82,7 +82,7 @@ __mirror_rxflow_instance(struct mirror_instance *mi, int enable) lws_rx_flow_control(pss->wsi, enable); } lws_end_foreach_ll(pss, same_mi_pss_list); - mi->rx_enabled = enable; + mi->rx_enabled = (char)enable; } /* diff --git a/plugins/protocol_lws_raw_test.c b/plugins/protocol_lws_raw_test.c index 3f970eef5..ed65d1703 100644 --- a/plugins/protocol_lws_raw_test.c +++ b/plugins/protocol_lws_raw_test.c @@ -178,7 +178,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, void *user, char buf[256]; int n; - n = read(vhd->fifo, buf, sizeof(buf) - 1); + n = (int)read(vhd->fifo, buf, sizeof(buf) - 1); if (n < 0) { lwsl_err("FIFO read failed\n"); return 1; @@ -247,7 +247,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, void *user, if (len > sizeof(pss->buf)) len = sizeof(pss->buf); memcpy(pss->buf, in, len); - pss->len = len; + pss->len = (int)len; lws_callback_on_writable(wsi); break; @@ -257,7 +257,7 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, void *user, case LWS_CALLBACK_RAW_WRITEABLE: lwsl_notice("LWS_CALLBACK_RAW_WRITEABLE\n"); - lws_write(wsi, pss->buf, pss->len, LWS_WRITE_HTTP); + lws_write(wsi, pss->buf, (size_t)pss->len, LWS_WRITE_HTTP); break; default: diff --git a/plugins/protocol_lws_server_status.c b/plugins/protocol_lws_server_status.c index 18a92e2f2..497f59efd 100644 --- a/plugins/protocol_lws_server_status.c +++ b/plugins/protocol_lws_server_status.c @@ -67,20 +67,20 @@ update(struct lws_sorted_usec_list *sul) *end = v->d.buf + sizeof(v->d.buf) - LWS_PRE - 1; int n, first = 1, fd; - p += lws_snprintf(p, lws_ptr_diff(end, p), "{\"i\":"); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"i\":"); p += lws_json_dump_context(v->context, p, lws_ptr_diff(end, p), v->hide_vhosts); - p += lws_snprintf(p, lws_ptr_diff(end, p), ", \"files\": ["); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ", \"files\": ["); fp = v->fp; while (fp) { if (!first) - p += lws_snprintf(p, lws_ptr_diff(end, p), ","); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ","); strcpy(pure, "(unknown)"); fd = lws_open(fp->filepath, LWS_O_RDONLY); if (fd >= 0) { - n = read(fd, contents, sizeof(contents) - 1); + n = (int)read(fd, contents, sizeof(contents) - 1); close(fd); if (n >= 0) { contents[n] = '\0'; @@ -88,15 +88,15 @@ update(struct lws_sorted_usec_list *sul) } } - p += lws_snprintf(p, lws_ptr_diff(end, p), + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"path\":\"%s\",\"val\":\"%s\"}", fp->filepath, pure); first = 0; fp = fp->next; } - p += lws_snprintf(p, lws_ptr_diff(end, p), "]}"); - v->d.length = p - (v->d.buf + LWS_PRE); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "]}"); + v->d.length = lws_ptr_diff(p, (v->d.buf + LWS_PRE)); lws_callback_on_writable_all_protocol(v->context, &protocols[0]); @@ -183,7 +183,7 @@ callback_lws_server_status(struct lws *wsi, enum lws_callback_reasons reason, case LWS_CALLBACK_SERVER_WRITEABLE: m = lws_write(wsi, (unsigned char *)v->d.buf + LWS_PRE, - v->d.length, LWS_WRITE_TEXT); + (size_t)v->d.length, LWS_WRITE_TEXT); if (m < 0) return -1; break; diff --git a/plugins/protocol_lws_sshd_demo.c b/plugins/protocol_lws_sshd_demo.c index 3ff9147ef..277085459 100644 --- a/plugins/protocol_lws_sshd_demo.c +++ b/plugins/protocol_lws_sshd_demo.c @@ -164,7 +164,7 @@ ssh_ops_tx(void *_priv, int stdch, uint8_t *buf, size_t len) return 0; if ((size_t)(priv->len - priv->pos) < chunk) - chunk = priv->len - priv->pos; + chunk = (size_t)(priv->len - priv->pos); if (!chunk) return 0; @@ -211,13 +211,13 @@ ssh_ops_get_server_key(struct lws *wsi, uint8_t *buf, size_t len) if (lseek(vhd->privileged_fd, 0, SEEK_SET) < 0) return 0; - n = read(vhd->privileged_fd, buf, (int)len); + n = (int)read(vhd->privileged_fd, buf, len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, n); n = 0; } - return n; + return (size_t)n; } static size_t @@ -229,13 +229,13 @@ ssh_ops_set_server_key(struct lws *wsi, uint8_t *buf, size_t len) lws_get_protocol(wsi)); int n; - n = write(vhd->privileged_fd, buf, (int)len); + n = (int)write(vhd->privileged_fd, buf, len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, errno); n = 0; } - return n; + return (size_t)n; } /* ops: auth */ @@ -266,7 +266,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, } p = aps; - if (strncmp(p, type, n)) { + if (strncmp(p, type, (unsigned int)n)) { lwsl_notice("lead-in string does not match %s\n", type); goto bail_p1; } @@ -278,7 +278,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, } p++; - ps = malloc(alen); + ps = malloc((unsigned int)alen); if (!ps) { lwsl_notice("OOM 2\n"); free(aps); @@ -301,7 +301,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, * once we are past that, it's the same name * EN that the peer sends us */ - if (memcmp(peer, ps, peer_len)) { + if (memcmp(peer, ps, (unsigned int)peer_len)) { lwsl_info("%s: factors mismatch, rejecting key\n", __func__); goto bail; } @@ -345,7 +345,7 @@ ssh_ops_banner(char *buf, size_t max_len, char *lang, size_t max_lang_len) lws_snprintf(lang, max_lang_len, "en/US"); - return n; + return (size_t)n; } static void diff --git a/plugins/protocol_lws_status.c b/plugins/protocol_lws_status.c index b2f7f0c99..520cb18ae 100644 --- a/plugins/protocol_lws_status.c +++ b/plugins/protocol_lws_status.c @@ -132,7 +132,7 @@ callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason, switch (pss->walk) { case WALK_INITIAL: n = LWS_WRITE_TEXT | LWS_WRITE_NO_FIN; - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{ \"version\":\"%s\"," " \"wss_over_h2\":\"%d\"," " \"hostname\":\"%s\"," @@ -171,7 +171,7 @@ callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason, strcpy(ip, "unknown"); lws_get_peer_simple(pss->walk_next->wsi, ip, sizeof(ip)); - p += lws_snprintf(p, end - p, + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "{\"peer\":\"%s\",\"time\":\"%ld\"," "\"ua\":\"%s\"}", ip, (unsigned long)pss->walk_next->time_est, @@ -196,7 +196,7 @@ walk_final: return 0; } - m = lws_write(wsi, (unsigned char *)start, p - start, n); + m = lws_write(wsi, (unsigned char *)start, lws_ptr_diff_size_t(p, start), (unsigned int)n); if (m < 0) { lwsl_err("ERROR %d writing to di socket\n", m); return -1; diff --git a/plugins/protocol_post_demo.c b/plugins/protocol_post_demo.c index 39c599ce8..b6c6b9317 100644 --- a/plugins/protocol_post_demo.c +++ b/plugins/protocol_post_demo.c @@ -94,7 +94,7 @@ file_upload_cb(void *data, const char *name, const char *filename, return 1; #if !defined(LWS_WITH_ESP32) - n = write((int)(lws_intptr_t)pss->fd, buf, len); + n = (int)write((int)(lws_intptr_t)pss->fd, buf, (unsigned int)len); lwsl_info("%s: write %d says %d\n", __func__, len, n); #else lwsl_notice("%s: Received chunk size %d\n", __func__, len); @@ -128,7 +128,7 @@ format_result(struct per_session_data__post_demo *pss) start = p; end = p + sizeof(pss->result) - LWS_PRE - 1; - p += lws_snprintf((char *)p, end -p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "" "" @@ -138,12 +138,12 @@ format_result(struct per_session_data__post_demo *pss) for (n = 0; n < (int)LWS_ARRAY_SIZE(param_names); n++) { if (!lws_spa_get_string(pss->spa, n)) - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%s0" "NULL", param_names[n]); else - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%s%d" "%s", param_names[n], @@ -151,12 +151,12 @@ format_result(struct per_session_data__post_demo *pss) lws_spa_get_string(pss->spa, n)); } - p += lws_snprintf((char *)p, end - p, + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "
filename: %s, " "length %ld", pss->filename, pss->file_length); - p += lws_snprintf((char *)p, end - p, ""); + p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), ""); return (int)lws_ptr_diff(p, start); } @@ -218,13 +218,13 @@ callback_post_demo(struct lws *wsi, enum lws_callback_reasons reason, (unsigned char *)"text/html", 9, &p, end)) goto bail; - if (lws_add_http_header_content_length(wsi, n, &p, end)) + if (lws_add_http_header_content_length(wsi, (unsigned int)n, &p, end)) goto bail; if (lws_finalize_http_header(wsi, &p, end)) goto bail; /* first send the headers ... */ - n = lws_write(wsi, start, lws_ptr_diff(p, start), + n = lws_write(wsi, start, lws_ptr_diff_size_t(p, start), LWS_WRITE_HTTP_HEADERS); if (n < 0) goto bail; @@ -237,7 +237,7 @@ callback_post_demo(struct lws *wsi, enum lws_callback_reasons reason, if (!pss->sent_body) { n = format_result(pss); - n = lws_write(wsi, (unsigned char *)start, n, + n = lws_write(wsi, (unsigned char *)start, (unsigned int)n, LWS_WRITE_HTTP_FINAL); pss->sent_body = 1; diff --git a/plugins/raw-proxy/protocol_lws_raw_proxy.c b/plugins/raw-proxy/protocol_lws_raw_proxy.c index 7cd729172..cef5f9363 100644 --- a/plugins/raw-proxy/protocol_lws_raw_proxy.c +++ b/plugins/raw-proxy/protocol_lws_raw_proxy.c @@ -158,7 +158,7 @@ flow_control(struct conn *conn, int side, int enable) if (lws_rx_flow_control(conn->wsi[side], enable)) return 1; - conn->rx_enabled[side] = enable; + conn->rx_enabled[side] = (char)enable; lwsl_info("%s: %s side: %s\n", __func__, side ? "ONW" : "ACC", enable ? "rx enabled" : "rx flow controlled"); @@ -223,7 +223,7 @@ callback_raw_proxy(struct lws *wsi, enum lws_callback_reasons reason, e = lws_tokenize(&ts); if (e != LWS_TOKZE_INTEGER) goto bad_onward; - vhd->port = atoi(ts.token); + vhd->port = (uint16_t)atoi(ts.token); e = lws_tokenize(&ts); } if (e != LWS_TOKZE_ENDED) @@ -298,7 +298,7 @@ bad_onward: lwsl_notice("OOM: dropping\n"); return -1; } - pkt.len = len; + pkt.len = (uint32_t)len; pkt.ticket = conn->ticket_next++; memcpy(pkt.payload, in, len); @@ -455,7 +455,7 @@ bad_onward: lwsl_notice("OOM: dropping\n"); return -1; } - pkt.len = len; + pkt.len = (uint32_t)len; pkt.ticket = conn->ticket_next++; memcpy(pkt.payload, in, len); diff --git a/plugins/ssh-base/crypto/ed25519.c b/plugins/ssh-base/crypto/ed25519.c index 72b3ae7c5..98055910b 100644 --- a/plugins/ssh-base/crypto/ed25519.c +++ b/plugins/ssh-base/crypto/ed25519.c @@ -166,7 +166,7 @@ int crypto_verify_32(const unsigned char *x,const unsigned char *y) F(29) F(30) F(31) - return (1 & ((differentbits - 1) >> 8)) - 1; + return (int)((1 & ((differentbits - 1) >> 8)) - 1); } int crypto_sign_ed25519_open( diff --git a/plugins/ssh-base/crypto/fe25519.c b/plugins/ssh-base/crypto/fe25519.c index fdc2e2a7c..1f9e7a004 100644 --- a/plugins/ssh-base/crypto/fe25519.c +++ b/plugins/ssh-base/crypto/fe25519.c @@ -90,7 +90,7 @@ void fe25519_freeze(fe25519 *r) m &= fe_equal(r->v[i],255); m &= ge(r->v[0],237); - m = -(int32_t)m; + m = (uint32_t)-(int32_t)m; r->v[31] -= m&127; for(i=30;i>0;i--) @@ -112,7 +112,7 @@ void fe25519_pack(unsigned char r[32], const fe25519 *x) fe25519 y = *x; fe25519_freeze(&y); for(i=0;i<32;i++) - r[i] = y.v[i]; + r[i] = (unsigned char)y.v[i]; } int fe25519_iszero(const fe25519 *x) @@ -121,9 +121,9 @@ int fe25519_iszero(const fe25519 *x) int r; fe25519 t = *x; fe25519_freeze(&t); - r = fe_equal(t.v[0],0); + r = (int)fe_equal(t.v[0],0); for(i=1;i<32;i++) - r &= fe_equal(t.v[i],0); + r &= (int)fe_equal(t.v[i],0); return r; } @@ -143,7 +143,7 @@ void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b) { int i; uint32_t mask = b; - mask = -(int32_t)mask; + mask = (uint32_t)-(int32_t)mask; for(i=0;i<32;i++) r->v[i] ^= mask & (x->v[i] ^ r->v[i]); } diff --git a/plugins/ssh-base/crypto/ge25519.c b/plugins/ssh-base/crypto/ge25519.c index 0c6273bbc..e14195d95 100644 --- a/plugins/ssh-base/crypto/ge25519.c +++ b/plugins/ssh-base/crypto/ge25519.c @@ -151,18 +151,18 @@ static void cmov_aff(ge25519_aff *r, const ge25519_aff *p, unsigned char b) static unsigned char ge_equal(signed char b,signed char c) { - unsigned char ub = b; - unsigned char uc = c; + unsigned char ub = (unsigned char)b; + unsigned char uc = (unsigned char)c; unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ uint32_t y = x; /* 0: yes; 1..255: no */ y -= 1; /* 4294967295: yes; 0..254: no */ y >>= 31; /* 1: yes; 0: no */ - return y; + return (unsigned char)y; } static unsigned char negative(signed char b) { - unsigned long long x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ + unsigned long long x = (unsigned long long)b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ x >>= 63; /* 1: yes; 0: no */ return (unsigned char)x; } @@ -247,7 +247,7 @@ void ge25519_pack(unsigned char r[32], const ge25519_p3 *p) fe25519_mul(&tx, &p->x, &zi); fe25519_mul(&ty, &p->y, &zi); fe25519_pack(r, &ty); - r[31] ^= fe25519_getparity(&tx) << 7; + r[31] ^= (unsigned char)(fe25519_getparity(&tx) << 7); } int ge25519_isneutral_vartime(const ge25519_p3 *p) diff --git a/plugins/ssh-base/crypto/poly1305.c b/plugins/ssh-base/crypto/poly1305.c index 65426673c..75657a39d 100644 --- a/plugins/ssh-base/crypto/poly1305.c +++ b/plugins/ssh-base/crypto/poly1305.c @@ -80,10 +80,10 @@ poly1305_donna_16bytes: t3 = U8TO32_LE(m - 4); h0 += t0 & 0x3ffffff; - h1 += ((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff; - h2 += ((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff; - h3 += ((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff; - h4 += (t3 >> 8) | (1 << 24); + h1 += (uint32_t)(((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff); + h2 += (uint32_t)(((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff); + h3 += (uint32_t)(((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff); + h4 += (uint32_t)((t3 >> 8) | (1 << 24)); poly1305_donna_mul: t[0] = mul32x32_64(h0,r0) + mul32x32_64(h1,s4) + @@ -130,10 +130,10 @@ poly1305_donna_atmost15bytes: t3 = U8TO32_LE(mp + 12); h0 += t0 & 0x3ffffff; - h1 += ((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff; - h2 += ((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff; - h3 += ((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff; - h4 += (t3 >> 8); + h1 += (uint32_t)(((((uint64_t)t1 << 32) | t0) >> 26) & 0x3ffffff); + h2 += (uint32_t)(((((uint64_t)t2 << 32) | t1) >> 20) & 0x3ffffff); + h3 += (uint32_t)(((((uint64_t)t3 << 32) | t2) >> 14) & 0x3ffffff); + h4 += (uint32_t)(t3 >> 8); goto poly1305_donna_mul; diff --git a/plugins/ssh-base/crypto/sc25519.c b/plugins/ssh-base/crypto/sc25519.c index 7983d8e6c..a12995bc4 100644 --- a/plugins/ssh-base/crypto/sc25519.c +++ b/plugins/ssh-base/crypto/sc25519.c @@ -39,7 +39,7 @@ static void sc_reduce_add_sub(sc25519 *r) { pb += m[i]; b = lt(r->v[i],pb); - t[i] = r->v[i]-pb+(b<<8); + t[i] = (unsigned char)(r->v[i]-pb+(b<<8)); pb = b; } mask = b - 1; @@ -134,7 +134,7 @@ void sc25519_from_shortsc(sc25519 *r, const shortsc25519 *x) void sc25519_to32bytes(unsigned char r[32], const sc25519 *x) { int i; - for(i=0;i<32;i++) r[i] = x->v[i]; + for(i=0;i<32;i++) r[i] = (unsigned char)x->v[i]; } int sc25519_iszero_vartime(const sc25519 *x) @@ -170,8 +170,8 @@ void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y) for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i]; for(i=0;i<31;i++) { - carry = r->v[i] >> 8; - r->v[i+1] += carry; + carry = (int)r->v[i] >> 8; + r->v[i+1] += (uint32_t)carry; r->v[i] &= 0xff; } sc_reduce_add_sub(r); @@ -202,8 +202,8 @@ void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y) /* Reduce coefficients */ for(i=0;i<63;i++) { - carry = t[i] >> 8; - t[i+1] += carry; + carry = (int)t[i] >> 8; + t[i+1] += (uint32_t)carry; t[i] &= 0xff; } @@ -226,18 +226,18 @@ void sc25519_window3(signed char r[85], const sc25519 *s) r[8*i+0] = s->v[3*i+0] & 7; r[8*i+1] = (s->v[3*i+0] >> 3) & 7; r[8*i+2] = (s->v[3*i+0] >> 6) & 7; - r[8*i+2] ^= (s->v[3*i+1] << 2) & 7; + r[8*i+2] = (signed char)(r[8*i+2] ^ (int)((s->v[3*i+1] << 2) & 7)); r[8*i+3] = (s->v[3*i+1] >> 1) & 7; r[8*i+4] = (s->v[3*i+1] >> 4) & 7; r[8*i+5] = (s->v[3*i+1] >> 7) & 7; - r[8*i+5] ^= (s->v[3*i+2] << 1) & 7; + r[8*i+5] = (signed char)(r[8*i+5] ^ (int)((s->v[3*i+2] << 1) & 7)); r[8*i+6] = (s->v[3*i+2] >> 2) & 7; r[8*i+7] = (s->v[3*i+2] >> 5) & 7; } r[8*i+0] = s->v[3*i+0] & 7; r[8*i+1] = (s->v[3*i+0] >> 3) & 7; r[8*i+2] = (s->v[3*i+0] >> 6) & 7; - r[8*i+2] ^= (s->v[3*i+1] << 2) & 7; + r[8*i+2] = (signed char)(r[8*i+2] ^ (int)((s->v[3*i+1] << 2) & 7)); r[8*i+3] = (s->v[3*i+1] >> 1) & 7; r[8*i+4] = (s->v[3*i+1] >> 4) & 7; @@ -245,13 +245,13 @@ void sc25519_window3(signed char r[85], const sc25519 *s) carry = 0; for(i=0;i<84;i++) { - r[i] += carry; - r[i+1] += r[i] >> 3; + r[i] = (signed char)(r[i] + carry); + r[i+1] = (signed char)(r[i + 1] + (r[i] >> 3)); r[i] &= 7; - carry = r[i] >> 2; - r[i] -= carry<<3; + carry = (char)(r[i] >> 2); + r[i] = (signed char)(r[i] - (carry<<3)); } - r[84] += carry; + r[84] = (signed char)(r[84] + (signed char)carry); } void sc25519_window5(signed char r[51], const sc25519 *s) @@ -262,33 +262,33 @@ void sc25519_window5(signed char r[51], const sc25519 *s) { r[8*i+0] = s->v[5*i+0] & 31; r[8*i+1] = (s->v[5*i+0] >> 5) & 31; - r[8*i+1] ^= (s->v[5*i+1] << 3) & 31; + r[8*i+1] = (signed char)(r[8*i+1] ^ (int)((s->v[5*i+1] << 3) & 31)); r[8*i+2] = (s->v[5*i+1] >> 2) & 31; r[8*i+3] = (s->v[5*i+1] >> 7) & 31; - r[8*i+3] ^= (s->v[5*i+2] << 1) & 31; + r[8*i+3] = (signed char)(r[8*i+3] ^ (int)((s->v[5*i+2] << 1) & 31)); r[8*i+4] = (s->v[5*i+2] >> 4) & 31; - r[8*i+4] ^= (s->v[5*i+3] << 4) & 31; + r[8*i+4] = (signed char)(r[8*i+4] ^ (int)((s->v[5*i+3] << 4) & 31)); r[8*i+5] = (s->v[5*i+3] >> 1) & 31; r[8*i+6] = (s->v[5*i+3] >> 6) & 31; - r[8*i+6] ^= (s->v[5*i+4] << 2) & 31; + r[8*i+6] = (signed char)(r[8*i+6] ^ (int)((s->v[5*i+4] << 2) & 31)); r[8*i+7] = (s->v[5*i+4] >> 3) & 31; } r[8*i+0] = s->v[5*i+0] & 31; r[8*i+1] = (s->v[5*i+0] >> 5) & 31; - r[8*i+1] ^= (s->v[5*i+1] << 3) & 31; + r[8*i+1] = (signed char)(r[8*i+1] ^ (int)((s->v[5*i+1] << 3) & 31)); r[8*i+2] = (s->v[5*i+1] >> 2) & 31; /* Making it signed */ carry = 0; for(i=0;i<50;i++) { - r[i] += carry; - r[i+1] += r[i] >> 5; + r[i] = (signed char)(r[i] + (signed char)carry); + r[i+1] = (signed char)(r[i + 1] + (r[i] >> 5)); r[i] &= 31; - carry = r[i] >> 4; - r[i] -= carry<<5; + carry = (char)(r[i] >> 4); + r[i] = (signed char)(r[i] - (carry<<5)); } - r[50] += carry; + r[50] = (signed char)(r[50] + carry); } void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2) @@ -296,12 +296,12 @@ void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 int i; for(i=0;i<31;i++) { - r[4*i] = ( s1->v[i] & 3) ^ (( s2->v[i] & 3) << 2); - r[4*i+1] = ((s1->v[i] >> 2) & 3) ^ (((s2->v[i] >> 2) & 3) << 2); - r[4*i+2] = ((s1->v[i] >> 4) & 3) ^ (((s2->v[i] >> 4) & 3) << 2); - r[4*i+3] = ((s1->v[i] >> 6) & 3) ^ (((s2->v[i] >> 6) & 3) << 2); + r[4*i] = (unsigned char)(( s1->v[i] & 3) ^ (( s2->v[i] & 3) << 2)); + r[4*i+1] = (unsigned char)(((s1->v[i] >> 2) & 3) ^ (((s2->v[i] >> 2) & 3) << 2)); + r[4*i+2] = (unsigned char)(((s1->v[i] >> 4) & 3) ^ (((s2->v[i] >> 4) & 3) << 2)); + r[4*i+3] = (unsigned char)(((s1->v[i] >> 6) & 3) ^ (((s2->v[i] >> 6) & 3) << 2)); } - r[124] = ( s1->v[31] & 3) ^ (( s2->v[31] & 3) << 2); - r[125] = ((s1->v[31] >> 2) & 3) ^ (((s2->v[31] >> 2) & 3) << 2); - r[126] = ((s1->v[31] >> 4) & 3) ^ (((s2->v[31] >> 4) & 3) << 2); + r[124] = (unsigned char)(( s1->v[31] & 3) ^ (( s2->v[31] & 3) << 2)); + r[125] = (unsigned char)(((s1->v[31] >> 2) & 3) ^ (((s2->v[31] >> 2) & 3) << 2)); + r[126] = (unsigned char)(((s1->v[31] >> 4) & 3) ^ (((s2->v[31] >> 4) & 3) << 2)); } diff --git a/plugins/ssh-base/crypto/smult_curve25519_ref.c b/plugins/ssh-base/crypto/smult_curve25519_ref.c index bd5250ff5..d3cd8ec3e 100644 --- a/plugins/ssh-base/crypto/smult_curve25519_ref.c +++ b/plugins/ssh-base/crypto/smult_curve25519_ref.c @@ -53,7 +53,7 @@ static void freeze(unsigned int a[32]) for (j = 0;j < 32;++j) aorig[j] = a[j]; add(a,a,minusp); - negative = -(int)((a[31] >> 7) & 1); + negative = (unsigned int)-(int)((a[31] >> 7) & 1); for (j = 0;j < 32;++j) a[j] ^= negative & (aorig[j] ^ a[j]); } @@ -150,7 +150,7 @@ static void mainloop(unsigned int work[64],const unsigned char e[32]) for (j = 1;j < 64;++j) xzm[j] = 0; for (pos = 254;pos >= 0;--pos) { - b = e[pos / 8] >> (pos & 7); + b = (unsigned int)(e[pos / 8] >> (pos & 7)); b &= 1; smc_select(xzmb,xzm1b,xzm,xzm1,b); add(a0,xzmb,xzmb + 32); @@ -260,6 +260,6 @@ int crypto_scalarmult_curve25519(unsigned char *q, recip(work + 32,work + 32); mult(work + 64,work,work + 32); freeze(work + 64); - for (i = 0;i < 32;++i) q[i] = work[64 + i]; + for (i = 0;i < 32;++i) q[i] = (unsigned char)work[64 + i]; return 0; } diff --git a/plugins/ssh-base/include/lws-ssh.h b/plugins/ssh-base/include/lws-ssh.h index 0b1e2b3da..029d2fc06 100644 --- a/plugins/ssh-base/include/lws-ssh.h +++ b/plugins/ssh-base/include/lws-ssh.h @@ -73,22 +73,22 @@ #define POKE_U64(p, v) \ do { \ const uint64_t __v = (v); \ - ((uint8_t *)(p))[0] = (__v >> 56) & 0xff; \ - ((uint8_t *)(p))[1] = (__v >> 48) & 0xff; \ - ((uint8_t *)(p))[2] = (__v >> 40) & 0xff; \ - ((uint8_t *)(p))[3] = (__v >> 32) & 0xff; \ - ((uint8_t *)(p))[4] = (__v >> 24) & 0xff; \ - ((uint8_t *)(p))[5] = (__v >> 16) & 0xff; \ - ((uint8_t *)(p))[6] = (__v >> 8) & 0xff; \ - ((uint8_t *)(p))[7] = __v & 0xff; \ + ((uint8_t *)(p))[0] = (uint8_t)((__v >> 56) & 0xff); \ + ((uint8_t *)(p))[1] = (uint8_t)((__v >> 48) & 0xff); \ + ((uint8_t *)(p))[2] = (uint8_t)((__v >> 40) & 0xff); \ + ((uint8_t *)(p))[3] = (uint8_t)((__v >> 32) & 0xff); \ + ((uint8_t *)(p))[4] = (uint8_t)((__v >> 24) & 0xff); \ + ((uint8_t *)(p))[5] = (uint8_t)((__v >> 16) & 0xff); \ + ((uint8_t *)(p))[6] = (uint8_t)((__v >> 8) & 0xff); \ + ((uint8_t *)(p))[7] = (uint8_t)(__v & 0xff); \ } while (0) #define POKE_U32(p, v) \ do { \ const uint32_t __v = (v); \ - ((uint8_t *)(p))[0] = (__v >> 24) & 0xff; \ - ((uint8_t *)(p))[1] = (__v >> 16) & 0xff; \ - ((uint8_t *)(p))[2] = (__v >> 8) & 0xff; \ - ((uint8_t *)(p))[3] = __v & 0xff; \ + ((uint8_t *)(p))[0] = (uint8_t)((__v >> 24) & 0xff); \ + ((uint8_t *)(p))[1] = (uint8_t)((__v >> 16) & 0xff); \ + ((uint8_t *)(p))[2] = (uint8_t)((__v >> 8) & 0xff); \ + ((uint8_t *)(p))[3] = (uint8_t)(__v & 0xff); \ } while (0) #define POKE_U16(p, v) \ do { \ diff --git a/plugins/ssh-base/kex-25519.c b/plugins/ssh-base/kex-25519.c index 4300dbd67..a7bac40e4 100644 --- a/plugins/ssh-base/kex-25519.c +++ b/plugins/ssh-base/kex-25519.c @@ -75,7 +75,7 @@ lws_gen_server_key_ed25519(struct lws_context *context, uint8_t *buf256, lwsl_notice("%s: Generated key len %ld\n", __func__, (long)(p - buf256)); - return p - buf256; + return (size_t)(p - buf256); } static int @@ -100,10 +100,10 @@ lws_mpint_rfc4251(uint8_t *dest, const uint8_t *src, int bytes, int uns) if (uns && (*src) & 0x80) bytes++; - *dest++ = bytes >> 24; - *dest++ = bytes >> 16; - *dest++ = bytes >> 8; - *dest++ = bytes; + *dest++ = (uint8_t)(bytes >> 24); + *dest++ = (uint8_t)(bytes >> 16); + *dest++ = (uint8_t)(bytes >> 8); + *dest++ = (uint8_t)(bytes); if (uns && (*src) & 0x80) { *dest++ = 0; @@ -150,7 +150,7 @@ ed25519_key_parse(uint8_t *p, size_t len, char *type, size_t type_len, return 6; publ = lws_g32(&p); /* length of pubkey block */ - if ((size_t)((p - op) + publ) >= len) + if ((size_t)((uint32_t)(p - op) + publ) >= len) return 7; l = lws_g32(&p); /* key type length */ @@ -169,7 +169,7 @@ ed25519_key_parse(uint8_t *p, size_t len, char *type, size_t type_len, p += l; publ = lws_g32(&p); /* length of private key block */ - if ((size_t)((p - op) + publ) != len) + if ((size_t)((uint32_t)(p - op) + publ) != len) return 11; l = lws_g32(&p); /* checkint 1 */ @@ -243,7 +243,7 @@ kex_ecdh_dv(uint8_t *dest, int dest_len, const uint8_t *kbi, int kbi_len, if (lws_genhash_init(&ctx, LWS_GENHASH_TYPE_SHA256)) return 1; - if (lws_genhash_update(&ctx, kbi, kbi_len)) + if (lws_genhash_update(&ctx, kbi, (unsigned int)kbi_len)) goto hash_failed; if (lws_genhash_update(&ctx, H, LWS_SIZE_SHA256)) goto hash_failed; @@ -264,7 +264,7 @@ kex_ecdh_dv(uint8_t *dest, int dest_len, const uint8_t *kbi, int kbi_len, if (m > (dest_len - n)) m = dest_len - n; - memcpy(dest, pool, m); + memcpy(dest, pool, (unsigned int)m); n += m; dest += m; } @@ -325,7 +325,7 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) return 1; } - r = ed25519_key_parse(servkey, r, keyt, sizeof(keyt), + r = ed25519_key_parse(servkey, (unsigned int)r, keyt, sizeof(keyt), pss->K_S /* public key */, pri_key); if (r) { lwsl_notice("%s: server key parse failed: %d\n", __func__, r); @@ -387,7 +387,7 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) * integer k. This conversion follows the network byte order. This * step differs from RFC5656. */ - kbi_len = lws_mpint_rfc4251(kbi, pss->K, LWS_SIZE_EC25519, 1); + kbi_len = (uint32_t)lws_mpint_rfc4251(kbi, pss->K, LWS_SIZE_EC25519, 1); /* * The exchange hash H is computed as the hash of the concatenation of @@ -429,7 +429,7 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) * name length: name * key length: key * ---> */ - lws_p32((uint8_t *)&be, 8 + (int)strlen(keyt) + LWS_SIZE_EC25519); + lws_p32((uint8_t *)&be, (uint32_t)(8 + (int)strlen(keyt) + LWS_SIZE_EC25519)); if (lws_genhash_update(&ctx, (void *)&be, 4)) goto hash_probs; @@ -484,9 +484,9 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) lp = p; p +=4; - lws_sized_blob(&p, keyt, (int)strlen(keyt)); + lws_sized_blob(&p, keyt, (uint32_t)strlen(keyt)); lws_sized_blob(&p, pss->K_S, LWS_SIZE_EC25519); - lws_p32(lp, lws_ptr_diff(p, lp) - 4); + lws_p32(lp, (uint32_t)(lws_ptr_diff(p, lp) - 4)); /* Q_S (exchange value sent by the server) */ @@ -496,14 +496,14 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) lp = p; p +=4; - lws_sized_blob(&p, keyt, (int)strlen(keyt)); + lws_sized_blob(&p, keyt, (uint32_t)strlen(keyt)); lws_sized_blob(&p, payload_sig, 64); - lws_p32(lp, lws_ptr_diff(p, lp) - 4); + lws_p32(lp, (uint32_t)(lws_ptr_diff(p, lp) - 4)); /* end of message */ lws_pad_set_length(pss, reply, &p, &pss->active_keys_stc); - *plen = lws_ptr_diff(p, reply); + *plen = (uint32_t)lws_ptr_diff(p, reply); if (!pss->active_keys_stc.valid) memcpy(pss->session_id, temp, LWS_SIZE_EC25519); @@ -533,9 +533,11 @@ kex_ecdh(struct per_session_data__sshd *pss, uint8_t *reply, uint32_t *plen) */ for (c = 0; c < 3; c++) { kex_ecdh_dv(kex->keys_next_cts.key[c], LWS_SIZE_CHACHA256_KEY, - kbi, kbi_len, temp, 'A' + (c * 2), pss->session_id); + kbi, (int)kbi_len, temp, (char)('A' + (c * 2)), + pss->session_id); kex_ecdh_dv(kex->keys_next_stc.key[c], LWS_SIZE_CHACHA256_KEY, - kbi, kbi_len, temp, 'B' + (c * 2), pss->session_id); + kbi, (int)kbi_len, temp, (char)('B' + (c * 2)), + pss->session_id); } lws_explicit_bzero(temp, sizeof(temp)); diff --git a/plugins/ssh-base/sshd.c b/plugins/ssh-base/sshd.c index b4c2cdc17..a4a0a3a0a 100644 --- a/plugins/ssh-base/sshd.c +++ b/plugins/ssh-base/sshd.c @@ -54,10 +54,10 @@ lws_g32(uint8_t **p) uint32_t lws_p32(uint8_t *p, uint32_t v) { - *p++ = v >> 24; - *p++ = v >> 16; - *p++ = v >> 8; - *p++ = v; + *p++ = (uint8_t)(v >> 24); + *p++ = (uint8_t)(v >> 16); + *p++ = (uint8_t)(v >> 8); + *p++ = (uint8_t)v; return v; } @@ -93,7 +93,7 @@ void write_task(struct per_session_data__sshd *pss, struct lws_ssh_channel *ch, int task) { - pss->write_task[pss->wt_head] = task; + pss->write_task[pss->wt_head] = (uint8_t)task; pss->write_channel[pss->wt_head] = ch; pss->wt_head = (pss->wt_head + 1) & 7; lws_callback_on_writable(pss->wsi); @@ -104,7 +104,7 @@ write_task_insert(struct per_session_data__sshd *pss, struct lws_ssh_channel *ch int task) { pss->wt_tail = (pss->wt_tail - 1) & 7; - pss->write_task[pss->wt_tail] = task; + pss->write_task[pss->wt_tail] = (uint8_t)task; pss->write_channel[pss->wt_tail] = ch; lws_callback_on_writable(pss->wsi); } @@ -114,15 +114,15 @@ void lws_pad_set_length(struct per_session_data__sshd *pss, void *start, uint8_t **p, struct lws_ssh_keys *keys) { - uint32_t len = lws_ptr_diff(*p, start); + uint32_t len = (uint32_t)lws_ptr_diff(*p, start); uint8_t padc = 4, *bs = start; if (keys->full_length) len -= 4; - if ((len + padc) & (keys->padding_alignment - 1)) - padc += keys->padding_alignment - - ((len + padc) & (keys->padding_alignment - 1)); + if ((len + padc) & (uint32_t)(keys->padding_alignment - 1)) + padc = (uint8_t)((uint8_t)padc + (uint8_t)(keys->padding_alignment - + ((len + padc) & (uint32_t)(keys->padding_alignment - 1)))); bs[4] = padc; len += padc; @@ -155,7 +155,7 @@ offer(struct per_session_data__sshd *pss, uint8_t *p, uint32_t len, int first, return 1; } lwsl_info("keylen %d\n", keylen); - n = ed25519_key_parse(keybuf, keylen, + n = ed25519_key_parse(keybuf, (unsigned int)keylen, keyt, sizeof(keyt), NULL, NULL); if (n) { lwsl_notice("unable to parse server key: %d\n", n); @@ -189,61 +189,61 @@ offer(struct per_session_data__sshd *pss, uint8_t *p, uint32_t len, int first, lp = p; p += 4; - n = lws_snprintf((char *)p, end - p, "curve25519-sha256@libssh.org"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "curve25519-sha256@libssh.org"); + p += lws_p32(lp, (uint32_t)n); /* Server Host Key Algorithms */ lp = p; p += 4; - n = lws_snprintf((char *)p, end - p, "%s", keyt); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "%s", keyt); + p += lws_p32(lp, (uint32_t)n); /* Encryption Algorithms: C -> S */ lp = p; p += 4; // n = lws_snprintf((char *)p, end - p, "aes256-gcm@openssh.com"); - n = lws_snprintf((char *)p, end - p, "chacha20-poly1305@openssh.com"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "chacha20-poly1305@openssh.com"); + p += lws_p32(lp, (uint32_t)n); /* Encryption Algorithms: S -> C */ lp = p; p += 4; // n = lws_snprintf((char *)p, end - p, "aes256-gcm@openssh.com"); - n = lws_snprintf((char *)p, end - p, "chacha20-poly1305@openssh.com"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "chacha20-poly1305@openssh.com"); + p += lws_p32(lp, (uint32_t)n); /* MAC Algorithms: C -> S */ lp = p; p += 4; /* bogus: chacha20 does not use MACs, but 'none' is not offered */ - n = lws_snprintf((char *)p, end - p, "hmac-sha2-256"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "hmac-sha2-256"); + p += lws_p32(lp, (uint32_t)n); /* MAC Algorithms: S -> C */ lp = p; p += 4; /* bogus: chacha20 does not use MACs, but 'none' is not offered */ - n = lws_snprintf((char *)p, end - p, "hmac-sha2-256"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "hmac-sha2-256"); + p += lws_p32(lp, (uint32_t)n); /* Compression Algorithms: C -> S */ lp = p; p += 4; - n = lws_snprintf((char *)p, end - p, "none"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "none"); + p += lws_p32(lp, (uint32_t)n); /* Compression Algorithms: S -> C */ lp = p; p += 4; - n = lws_snprintf((char *)p, end - p, "none"); - p += lws_p32(lp, n); + n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "none"); + p += lws_p32(lp, (uint32_t)n); if (p - op < 13 + padc + 8) return 0; @@ -273,18 +273,18 @@ offer(struct per_session_data__sshd *pss, uint8_t *p, uint32_t len, int first, *p++ = 0; *p++ = 0; - len = lws_ptr_diff(p, op); + len = (uint32_t)lws_ptr_diff(p, op); if (payload_len) /* starts at buf + 5 and excludes padding */ - *payload_len = len - 5; + *payload_len = (int)(len - 5); /* we must give at least 4 bytes of 00 padding */ - if ((len + padc) & 7) - padc += 8 - ((len + padc) & 7); + if (((int)len + padc) & 7) + padc += 8 - (((int)len + padc) & 7); - op[4] = padc; - len += padc; + op[4] = (uint8_t)padc; + len += (uint32_t)padc; while (padc--) *p++ = 0; @@ -312,7 +312,7 @@ handle_name(struct per_session_data__sshd *pss) len = (int)get_gen_server_key_25519(pss, keybuf, (int)sizeof(keybuf)); if (!len) break; - if (ed25519_key_parse(keybuf, len, + if (ed25519_key_parse(keybuf, (unsigned int)len, keyt, sizeof(keyt), NULL, NULL)) { lwsl_err("Unable to parse host key %d\n", n); @@ -445,21 +445,21 @@ static void state_get_string_alloc(struct per_session_data__sshd *pss, int next) { pss->parser_state = SSHS_GET_STRING_LEN_ALLOC; - pss->state_after_string = next; + pss->state_after_string = (char)next; } static void state_get_string(struct per_session_data__sshd *pss, int next) { pss->parser_state = SSHS_GET_STRING_LEN; - pss->state_after_string = next; + pss->state_after_string = (char)next; } static void state_get_u32(struct per_session_data__sshd *pss, int next) { pss->parser_state = SSHS_GET_U32; - pss->state_after_string = next; + pss->state_after_string = (char)next; } static struct lws_ssh_channel * @@ -556,7 +556,7 @@ again: break; } if (pss->npos < sizeof(pss->V_C) - 1) - pss->V_C[pss->npos++] = *p; + pss->V_C[pss->npos++] = (char)*p; p++; break; @@ -577,7 +577,7 @@ again: if (pss->active_keys_cts.valid) { uint8_t b[4]; - POKE_U32(b, pss->msg_len); + POKE_U32(b, (uint32_t)pss->msg_len); pss->msg_len = lws_chachapoly_get_length( &pss->active_keys_cts, pss->ssh_sequence_ctr_cts, b); @@ -868,7 +868,7 @@ again: case SSH_KEX_NL_LSTC_ALGS: if (*p != ',') { if (pss->npos < sizeof(pss->name) - 1) - pss->name[pss->npos++] = *p; + pss->name[pss->npos++] = (char)*p; } else { pss->name[pss->npos] = '\0'; pss->npos = 0; @@ -968,7 +968,7 @@ again: lwsl_notice("non-alloc string too big\n"); goto bail; } - pss->name[pss->npos++] = *p++; + pss->name[pss->npos++] = (char)*p++; if (pss->npos != pss->len) break; @@ -1080,7 +1080,7 @@ again: case SSHS_DO_UAR_SIG_PRESENT: lwsl_info("SSHS_DO_UAR_SIG_PRESENT\n"); - pss->ua->sig_present = *p++; + pss->ua->sig_present = (char)*p++; state_get_string_alloc(pss, SSHS_NVC_DO_UAR_ALG); /* destroyed with UA struct */ break; @@ -1117,7 +1117,7 @@ again: if (pss->vhd->ops && pss->vhd->ops->is_pubkey_authorized) n = pss->vhd->ops->is_pubkey_authorized( pss->ua->username, pss->ua->alg, - pss->ua->pubkey, pss->ua->pubkey_len); + pss->ua->pubkey, (int)pss->ua->pubkey_len); if (n) { lwsl_info("rejecting peer pubkey\n"); goto ua_fail; @@ -1193,7 +1193,7 @@ again: 4 + (int)strlen(pss->ua->alg) + 4 + (int)pss->ua->pubkey_len; - ps = sshd_zalloc(n); + ps = sshd_zalloc((unsigned int)n); if (!ps) { lwsl_notice("OOM 4\n"); goto ua_fail; @@ -1212,13 +1212,13 @@ again: /* Next hash the plaintext */ if (lws_genhash_init(&pss->ua->hash_ctx, - rsa_hash_alg_from_ident(pss->ua->alg))) { + (enum lws_genhash_types)rsa_hash_alg_from_ident(pss->ua->alg))) { lwsl_notice("genhash init failed\n"); free(ps); goto ua_fail; } - if (lws_genhash_update(&pss->ua->hash_ctx, ps, pp - ps)) { + if (lws_genhash_update(&pss->ua->hash_ctx, ps, lws_ptr_diff_size_t(pp, ps))) { lwsl_notice("genhash update failed\n"); free(ps); goto ua_fail; @@ -1275,8 +1275,8 @@ again: if (otmp[m] == 0x04 && otmp[m + 1] == lws_genhash_size( pss->ua->hash_ctx.type)) { - m = memcmp(&otmp[m + 2], hash, - lws_genhash_size(pss->ua->hash_ctx.type)); + m = (uint32_t)memcmp(&otmp[m + 2], hash, + (unsigned int)lws_genhash_size(pss->ua->hash_ctx.type)); break; } /* go into these */ @@ -1285,7 +1285,7 @@ again: continue; } /* otherwise skip payloads */ - m += otmp[m + 1] + 2; + m += (uint32_t)(otmp[m + 1] + 2); } } @@ -1380,13 +1380,13 @@ again: break; case SSHS_NVC_CHOPEN_WINSIZE: lwsl_info("Initial window set to %d\n", pss->len); - pss->ch_temp->window = pss->len; + pss->ch_temp->window = (int32_t)pss->len; state_get_u32(pss, SSHS_NVC_CHOPEN_PKTSIZE); break; case SSHS_NVC_CHOPEN_PKTSIZE: pss->ch_temp->max_pkt = pss->len; pss->ch_temp->peer_window_est = LWS_SSH_INITIAL_WINDOW; - pss->ch_temp->server_ch = pss->next_ch_num++; + pss->ch_temp->server_ch = (uint32_t)pss->next_ch_num++; /* * add us to channel list... leave as ch_temp * as write task needs it and will NULL down @@ -1635,7 +1635,7 @@ again: pss->ch_recip = pss->len; ch = ssh_get_server_ch(pss, pss->ch_recip); - ch->peer_window_est -= pss->msg_len; + ch->peer_window_est -= (int32_t)pss->msg_len; if (pss->msg_len < sizeof(pss->name)) state_get_string(pss, SSHS_NVC_CD_DATA); @@ -1676,7 +1676,7 @@ again: pss->parser_state = SSHS_MSG_EAT_PADDING; break; } - scp->len = atoll((const char *)pp); + scp->len = (uint64_t)atoll((const char *)pp); lwsl_notice("scp payload %llu expected\n", (unsigned long long)scp->len); scp->ips = SSHS_SCP_PAYLOADIN; @@ -1729,7 +1729,7 @@ again: case SSHS_NVC_WA_ADD: ch = ssh_get_server_ch(pss, pss->ch_recip); if (ch) { - ch->window += pss->len; + ch->window += (int32_t)pss->len; lwsl_notice("got additional window %d (now %d)\n", pss->len, ch->window); } @@ -1904,7 +1904,7 @@ parse(struct per_session_data__sshd *pss, uint8_t *p, size_t len) return 0; /* decrypt it */ - cp = lws_chacha_decrypt(&pss->active_keys_cts, + cp = (uint32_t)lws_chacha_decrypt(&pss->active_keys_cts, pss->ssh_sequence_ctr_cts++, pss->packet_assembly, pss->pa_pos, pt); @@ -1944,7 +1944,7 @@ pad_and_encrypt(uint8_t *dest, void *ps, uint8_t *pp, if (!skip_pad) lws_pad_set_length(pss, ps, &pp, &pss->active_keys_stc); - n = lws_ptr_diff(pp, ps); + n = (uint32_t)lws_ptr_diff(pp, ps); if (!pss->active_keys_stc.valid) { memcpy(dest, ps, n); @@ -2126,7 +2126,7 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, if (!pss->vhd) break; m = 0; - n = offer(pss, buf + LWS_PRE, + n = (int)offer(pss, buf + LWS_PRE, sizeof(buf) - LWS_PRE, 0, &m); if (n == 0) { lwsl_notice("Too small\n"); @@ -2143,20 +2143,20 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, /* we need a copy of it to generate the hash later */ if (pss->kex->I_S) free(pss->kex->I_S); - pss->kex->I_S = sshd_zalloc(m); + pss->kex->I_S = sshd_zalloc((unsigned int)m); if (!pss->kex->I_S) { lwsl_notice("OOM 5: %d\n", m); return -1; } /* without length + padcount part */ - memcpy(pss->kex->I_S, buf + LWS_PRE + 5, m); - pss->kex->I_S_payload_len = m; /* without padding */ + memcpy(pss->kex->I_S, buf + LWS_PRE + 5, (unsigned int)m); + pss->kex->I_S_payload_len = (uint32_t)m; /* without padding */ break; case SSH_WT_OFFER_REPLY: memcpy(ps, pss->kex->kex_r, pss->kex->kex_r_len); - n = pad_and_encrypt(&buf[LWS_PRE], ps, + n = (int)pad_and_encrypt(&buf[LWS_PRE], ps, ps + pss->kex->kex_r_len, pss, 1); pss->kex_state = KEX_STATE_REPLIED_TO_OFFER; /* afterwards, must do newkeys */ @@ -2202,7 +2202,7 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, n = (int)pss->vhd->ops->banner((char *)&buf[650], 150 - 1, lang, (int)sizeof(lang)); - lws_p32(pp, n); + lws_p32(pp, (uint32_t)n); pp += 4; strcpy((char *)pp, (char *)&buf[650]); pp += n; @@ -2220,12 +2220,12 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, * string public key alg name from the request * string public key blob from the request */ - n = 74 + pss->ua->pubkey_len; + n = 74 + (int)pss->ua->pubkey_len; if (n > (int)sizeof(buf) - LWS_PRE) { lwsl_notice("pubkey too large\n"); goto bail; } - ps1 = sshd_zalloc(n); + ps1 = sshd_zalloc((unsigned int)n); if (!ps1) goto bail; ps = ps1; @@ -2351,7 +2351,7 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, strcpy((char *)pp, "exit-status"); pp += 11; *pp++ = 0; - lws_p32(pp, ch->retcode); + lws_p32(pp, (uint32_t)ch->retcode); pp += 4; lwsl_info("send SSH_MSG_CHANNEL_EXIT_STATUS\n"); goto pac; @@ -2404,9 +2404,10 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, /* ps + 14 / + 18 */ pp += pss->vhd->ops->tx(ch->priv, n, pp, - &buf[sizeof(buf) - 1] - pp); + lws_ptr_diff_size_t( + &buf[sizeof(buf) - 1], pp)); - lws_p32(ps + m - 4, lws_ptr_diff(pp, (ps + m))); + lws_p32(ps + m - 4, (uint32_t)lws_ptr_diff(pp, (ps + m))); if (pss->vhd->ops->tx_waiting(ch->priv) > 0) lws_callback_on_writable(wsi); @@ -2418,7 +2419,7 @@ lws_callback_raw_sshd(struct lws *wsi, enum lws_callback_reasons reason, pac: if (!pss->vhd) break; - n = pad_and_encrypt(&buf[LWS_PRE], ps, pp, pss, 0); + n = (int)pad_and_encrypt(&buf[LWS_PRE], ps, pp, pss, 0); break; bail: @@ -2430,7 +2431,7 @@ bail: } if (n > 0) { - m = lws_write(wsi, (unsigned char *)buf + LWS_PRE, n, + m = lws_write(wsi, (unsigned char *)buf + LWS_PRE, (unsigned int)n, LWS_WRITE_HTTP); switch(o) { @@ -2513,7 +2514,7 @@ bail: break; ch = ssh_get_server_ch(pss, pss->channel_doing_spawn); if (ch) { - ch->spawn_pid = (int)len; /* child process PID */ + ch->spawn_pid = (uint32_t)len; /* child process PID */ lwsl_notice("associated PID %d to ch %d\n", (int)len, pss->channel_doing_spawn); } diff --git a/plugins/ssh-base/telnet.c b/plugins/ssh-base/telnet.c index 0064147ca..04b2e6be3 100644 --- a/plugins/ssh-base/telnet.c +++ b/plugins/ssh-base/telnet.c @@ -187,7 +187,7 @@ lws_callback_raw_telnet(struct lws *wsi, enum lws_callback_reasons reason, pu++; if (n > 100 || !len) - pss->vhd->ops->rx(pss->priv, wsi, buf, n); + pss->vhd->ops->rx(pss->priv, wsi, buf, (uint32_t)n); } break; @@ -206,7 +206,7 @@ lws_callback_raw_telnet(struct lws *wsi, enum lws_callback_reasons reason, */ pu = buf + LWS_PRE + 400; m = (int)pss->vhd->ops->tx(pss->priv, LWS_STDOUT, pu, - ((int)sizeof(buf) - LWS_PRE - n - 401) / 2); + (size_t)((int)sizeof(buf) - LWS_PRE - n - 401) / 2); /* * apply telnet line discipline and copy into place @@ -219,7 +219,7 @@ lws_callback_raw_telnet(struct lws *wsi, enum lws_callback_reasons reason, } } if (n > 0) { - m = lws_write(wsi, (unsigned char *)buf + LWS_PRE, n, + m = lws_write(wsi, (unsigned char *)buf + LWS_PRE, (unsigned int)n, LWS_WRITE_HTTP); if (m < 0) { lwsl_err("ERROR %d writing to di socket\n", m); diff --git a/test-apps/test-client.c b/test-apps/test-client.c index d8021c2ca..1115c882b 100644 --- a/test-apps/test-client.c +++ b/test-apps/test-client.c @@ -92,7 +92,7 @@ lws_poly_rand(struct lws_poly_gen *p) p->cyc[1] = (p->cyc[1] & 1) ? (p->cyc[1] >> 1) ^ 0x7a5bc2e3 : p->cyc[1] >> 1; - return p->cyc[0] ^ p->cyc[1]; + return (uint8_t)(p->cyc[0] ^ p->cyc[1]); } static void show_http_content(const char *p, size_t l) @@ -293,10 +293,18 @@ callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason, X509_VERIFY_PARAM_free(param); if (n != 1) { char errbuf[256]; - n = ERR_get_error(); + const char *es; + + n = (int)ERR_get_error(); + es = ERR_error_string( +#if defined(LWS_WITH_BORINGSSL) + (uint32_t) +#else + (unsigned long) +#endif + n, errbuf); lwsl_err("EXTRA_CLIENT_VERIFY_CERTS: " - "SSL error: %s (%d)\n", - ERR_error_string(n, errbuf), n); + "SSL error: %s (%d)\n", es, n); return 1; } } @@ -339,7 +347,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, } lws_get_random(lws_get_context(wsi), rands, sizeof(rands[0])); - mirror_lifetime = 16384 + (rands[0] & 65535); + mirror_lifetime = (int)(16384 + (rands[0] & 65535)); /* useful to test single connection stability */ if (longlived) mirror_lifetime += 500000; @@ -406,7 +414,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, (rands[3] & 31) + 1); /* radius */ } - n = lws_write(wsi, &buf[LWS_PRE], l, + n = (int)lws_write(wsi, &buf[LWS_PRE], (unsigned int)l, opts | LWS_WRITE_TEXT); if (n < 0) return -1; @@ -433,7 +441,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, p = (unsigned char *)in; for (n = 0; n < (int)len; n++) if (*p++ != lws_poly_rand(&rx)) { - lwsl_err("mismatch at rxb %d offset %d\n", rxb + (n / block_size), n % block_size); + lwsl_err("mismatch at rxb %d offset %d\n", (int)rxb + (n / block_size), n % block_size); errs++; force_exit = 1; return -1; @@ -564,10 +572,10 @@ static int ratelimit_connects(unsigned int *last, unsigned int secs) gettimeofday(&tv, NULL); - if (tv.tv_sec - (*last) < secs) + if ((unsigned long)tv.tv_sec - (unsigned long)(*last) < (unsigned long)secs) return 0; - *last = tv.tv_sec; + *last = (unsigned int)tv.tv_sec; return 1; } @@ -702,8 +710,8 @@ int main(int argc, char **argv) info.port = CONTEXT_PORT_NO_LISTEN; info.protocols = protocols; - info.gid = -1; - info.uid = -1; + info.gid = (gid_t)-1; + info.uid = (uid_t)-1; #if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) info.extensions = exts; #endif diff --git a/test-apps/test-lejp.c b/test-apps/test-lejp.c index 37b32508f..b583f77b9 100644 --- a/test-apps/test-lejp.c +++ b/test-apps/test-lejp.c @@ -52,14 +52,14 @@ cb(struct lejp_ctx *ctx, char reason) *p = '\0'; if (reason & LEJP_FLAG_CB_IS_VALUE) { - p += lws_snprintf(p, p - end, " value '%s' ", ctx->buf); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), " value '%s' ", ctx->buf); if (ctx->ipos) { int n; - p += lws_snprintf(p, p - end, "(array indexes: "); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "(array indexes: "); for (n = 0; n < ctx->ipos; n++) - p += lws_snprintf(p, p - end, "%d ", ctx->i[n]); - p += lws_snprintf(p, p - end, ") "); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "%d ", ctx->i[n]); + p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), ") "); } lwsl_notice("%s (%s)\r\n", buf, reason_names[(unsigned int) @@ -102,7 +102,7 @@ main(int argc, char *argv[]) fd = 0; while (n > 0) { - n = read(fd, buf, sizeof(buf)); + n = (int)read(fd, buf, sizeof(buf)); if (n <= 0) continue; diff --git a/test-apps/test-server.c b/test-apps/test-server.c index af55f9fd2..872c0a8b7 100644 --- a/test-apps/test-server.c +++ b/test-apps/test-server.c @@ -138,19 +138,19 @@ lws_callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, /* dump the headers */ do { - c = lws_token_to_string(n); + c = lws_token_to_string((enum lws_token_indexes)n); if (!c) { n++; continue; } - hlen = lws_hdr_total_length(wsi, n); + hlen = lws_hdr_total_length(wsi, (enum lws_token_indexes)n); if (!hlen || hlen > (int)sizeof(buf) - 1) { n++; continue; } - if (lws_hdr_copy(wsi, buf, sizeof buf, n) < 0) + if (lws_hdr_copy(wsi, buf, sizeof buf, (enum lws_token_indexes)n) < 0) fprintf(stderr, " %s (too big)\n", (char *)c); else { buf[sizeof(buf) - 1] = '\0'; @@ -399,13 +399,14 @@ int main(int argc, char **argv) char cert_path[1024] = ""; char key_path[1024] = ""; char ca_path[1024] = ""; - int uid = -1, gid = -1; - int use_ssl = 0; - int opts = 0; - int n = 0; #ifndef LWS_NO_DAEMONIZE int daemonize = 0; #endif + uint64_t opts = 0; + int use_ssl = 0; + uid_t uid = (uid_t)-1; + gid_t gid = (gid_t)-1; + int n = 0; /* * take care to zero down the info struct, he contains random garbaage @@ -432,10 +433,10 @@ int main(int argc, char **argv) break; #endif case 'u': - uid = atoi(optarg); + uid = (uid_t)atoi(optarg); break; case 'g': - gid = atoi(optarg); + gid = (gid_t)atoi(optarg); break; case 'd': debug_level = atoi(optarg); diff --git a/test-apps/test-sshd.c b/test-apps/test-sshd.c index 6d68b41ea..17aa5e175 100644 --- a/test-apps/test-sshd.c +++ b/test-apps/test-sshd.c @@ -241,7 +241,7 @@ ssh_ops_get_server_key(struct lws *wsi, uint8_t *buf, size_t len) return 0; } - n = read(fd, buf, len); + n = (int)read(fd, buf, len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, n); n = 0; @@ -249,7 +249,7 @@ ssh_ops_get_server_key(struct lws *wsi, uint8_t *buf, size_t len) close(fd); - return n; + return (size_t)n; } static size_t @@ -266,7 +266,7 @@ ssh_ops_set_server_key(struct lws *wsi, uint8_t *buf, size_t len) return 0; } - n = write(fd, buf, len); + n = (int)write(fd, buf, len); if (n < 0) { lwsl_err("%s: read failed: %d\n", __func__, errno); n = 0; @@ -274,7 +274,7 @@ ssh_ops_set_server_key(struct lws *wsi, uint8_t *buf, size_t len) close(fd); - return n; + return (size_t)n; } /* ops: auth */ @@ -284,7 +284,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, const uint8_t *peer, int peer_len) { char *aps, *p, *ps; - int n = strlen(type), alen = 2048, ret = 2, len; + int n = (int)strlen(type), alen = 2048, ret = 2, len; size_t s = 0; lwsl_info("%s: checking pubkey for %s\n", __func__, username); @@ -305,7 +305,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, } p = aps; - if (strncmp(p, type, n)) { + if (strncmp(p, type, (unsigned int)n)) { lwsl_notice("lead-in string does not match %s\n", type); goto bail_p1; } @@ -318,7 +318,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, p++; - ps = malloc(alen); + ps = malloc((unsigned int)alen); if (!ps) { lwsl_notice("OOM 2\n"); free(aps); @@ -342,7 +342,7 @@ ssh_ops_is_pubkey_authorized(const char *username, const char *type, * EN that the peer sends us */ - if (lws_timingsafe_bcmp(peer, ps, peer_len)) { + if (lws_timingsafe_bcmp(peer, ps, (uint32_t)peer_len)) { lwsl_info("factors mismatch\n"); goto bail; } @@ -425,10 +425,10 @@ ssh_ops_pty_req(void *_priv, struct lws_ssh_pty *pty) break; opc = *p++; - arg = *p++ << 24; - arg |= *p++ << 16; - arg |= *p++ << 8; - arg |= *p++; + arg = (uint32_t)(*p++ << 24); + arg |= (uint32_t)(*p++ << 16); + arg |= (uint32_t)(*p++ << 8); + arg |= (uint32_t)(*p++); lwsl_debug("pty opc %d: 0x%x\n", opc, arg); @@ -483,7 +483,7 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi, uint8_t buf[256], *p, *d; if (bytes != 1) - n = bytes / 2; + n = (int)(bytes / 2); else n = 1; if (n > (int)sizeof(buf)) @@ -495,7 +495,7 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi, m = lws_get_socket_fd(args->stdwsi[args->ch]); if (m < 0) return -1; - n = read(m, buf, n); + n = (int)read(m, buf, (unsigned int)n); if (n < 0) return -1; if (n == 0) { @@ -515,7 +515,7 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi, *p++ = *d++; } - n = (void *)p - rp; + n = lws_ptr_diff((void *)p, rp); if (n < (int)bytes && priv->insert_lf) { priv->insert_lf = 0; *p++ = 0x0d; @@ -525,14 +525,14 @@ ssh_ops_child_process_io(void *_priv, struct lws *wsi, n = lws_get_socket_fd(args->stdwsi[args->ch]); if (n < 0) return -1; - n = read(n, rp, bytes); + n = (int)read(n, rp, bytes); if (n < 0) return -1; } lws_rx_flow_control(args->stdwsi[args->ch], 0); - lws_ring_bump_head(r, n); + lws_ring_bump_head(r, (unsigned int)n); lws_callback_on_writable(wsi); break; } @@ -584,11 +584,11 @@ ssh_ops_banner(char *buf, size_t max_len, char *lang, size_t max_lang_len) int n = lws_snprintf(buf, max_len, "\n" " |\\---/| lws-ssh Test Server\n" " | o_o | SSH Terminal Server\n" - " \\_^_/ Copyright (C) 2017 Crash Barrier Ltd\n\n"); + " \\_^_/ Copyright (C) 2017-2020 Crash Barrier Ltd\n\n"); lws_snprintf(lang, max_lang_len, "en/US"); - return n; + return (size_t)n; } static void