1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

type comparisons: fixes

This is a huge patch that should be a global NOP.

For unix type platforms it enables -Wconversion to issue warnings (-> error)
for all automatic casts that seem less than ideal but are normally concealed
by the toolchain.

This is things like passing an int to a size_t argument.  Once enabled, I
went through all args on my default build (which build most things) and
tried to make the removed default cast explicit.

With that approach it neither change nor bloat the code, since it compiles
to whatever it was doing before, just with the casts made explicit... in a
few cases I changed some length args from int to size_t but largely left
the causes alone.

From now on, new code that is relying on less than ideal casting
will complain and nudge me to improve it by warnings.
This commit is contained in:
Andy Green 2020-12-12 06:21:40 +00:00
parent 2d6b9a06a7
commit c9731c5f17
259 changed files with 2748 additions and 2485 deletions

View file

@ -657,6 +657,12 @@ CHECK_C_SOURCE_COMPILES("#include <linux/rtnetlink.h>
return 0;
}" LWS_HAVE_RTA_PREF)
CHECK_C_SOURCE_COMPILES("#include <sys/types.h>
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()

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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);
/**

View file

@ -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__)

View file

@ -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 */

View file

@ -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

View file

@ -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);

View file

@ -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;
/**

View file

@ -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

View file

@ -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,

View file

@ -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;
}
/*

View file

@ -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 {

View file

@ -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 =

View file

@ -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));

View file

@ -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));

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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];

View file

@ -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;

View file

@ -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);

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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 */

View file

@ -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

View file

@ -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)
/*

View file

@ -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);

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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 */

View file

@ -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

View file

@ -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++;

View file

@ -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++ = '.';
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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 */

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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];
}

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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];
}

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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];
}

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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;
}

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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];
}

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* 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];
}

View file

@ -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);

View file

@ -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)

View file

@ -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++;
}

View file

@ -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))

View file

@ -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

View file

@ -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;

View file

@ -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';

View file

@ -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

View file

@ -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);

View file

@ -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(&lt_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(&lt_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 */

View file

@ -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;

View file

@ -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:

View file

@ -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 *

View file

@ -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;

View file

@ -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,

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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__);

View file

@ -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;
}

View file

@ -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";

View file

@ -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);

View file

@ -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)) {

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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__);

View file

@ -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");
}

View file

@ -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);

View file

@ -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);

View file

@ -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 */
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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);

View file

@ -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] = '/';

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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 */

View file

@ -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",

View file

@ -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;
}

Some files were not shown because too many files have changed in this diff Show more