diff --git a/CMakeLists.txt b/CMakeLists.txt
index d16a2c8..2233ed0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
project(sai C)
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8.12)
find_package(libwebsockets CONFIG REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
include(CheckCSourceCompiles)
@@ -136,7 +136,7 @@ if (requirements)
CMAKE_COMPILER_IS_GNUCXX OR
(CMAKE_C_COMPILER_ID MATCHES "Clang") OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
- set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Werror -Wundef ${CMAKE_C_FLAGS}" )
+ set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wignored-qualifiers -Wtype-limits -Wuninitialized -Wconversion -Werror -Wundef ${CMAKE_C_FLAGS}" )
endif()
if (SAI_SERVER)
diff --git a/READMEs/README-systemd-nspawn.md b/READMEs/README-systemd-nspawn.md
index d379926..37fcedb 100644
--- a/READMEs/README-systemd-nspawn.md
+++ b/READMEs/README-systemd-nspawn.md
@@ -373,7 +373,7 @@ Container # systemctl enable sai-builder
```
$ git clone https://warmcat.com/repo/sai
$ cd sai && mkdir build && cd build
-$ cmake .. -DSAI_MASTER=0 -DSAI_LWS_INC_PATH="C:/Program Files (x86)/libwebsockets/include" -DSAI_LWS_LIB_PATH="C:/Program Files (x86)/libwebsockets/lib/websockets.lib" -DSAI_EXT_PTHREAD_INCLUDE_DIR="C:\Program Files (x86)\pthreads\include" -DSAI_EXT_PTHREAD_LIBRARIES="C:\Program Files (x86)\pthreads\lib\x64\libpthreadGC2.a" -DLWS_OPENSSL_INCLUDE_DIRS="C:\Program Files\OpenSSL\include" -DLWS_OPENSSL_LIBRARIES="C:\Program Files\OpenSSL\lib\libssl.lib;C:\Program Files\OpenSSL\lib\libcrypto.lib" -DSAI_GIT2_LIB_PATH="C:\Program Files (x86)\libgit2\lib\git2.lib" -DSAI_GIT2_INC_PATH="C:\Program Files (x86)\libgit2\include"
+$ cmake .. -DSAI_SERVER=0 -DSAI_LWS_INC_PATH="C:/Program Files (x86)/libwebsockets/include" -DSAI_LWS_LIB_PATH="C:/Program Files (x86)/libwebsockets/lib/websockets.lib" -DSAI_EXT_PTHREAD_INCLUDE_DIR="C:\Program Files (x86)\pthreads\include" -DSAI_EXT_PTHREAD_LIBRARIES="C:\Program Files (x86)\pthreads\lib\x64\libpthreadGC2.a" -DLWS_OPENSSL_INCLUDE_DIRS="C:\Program Files\OpenSSL\include" -DLWS_OPENSSL_LIBRARIES="C:\Program Files\OpenSSL\lib\libssl.lib;C:\Program Files\OpenSSL\lib\libcrypto.lib" -DSAI_GIT2_LIB_PATH="C:\Program Files (x86)\libgit2\lib\git2.lib" -DSAI_GIT2_INC_PATH="C:\Program Files (x86)\libgit2\include"
$ cmake --build . --config DEBUG
```
diff --git a/src/builder/b-artifacts.c b/src/builder/b-artifacts.c
index 99613a3..a51f299 100644
--- a/src/builder/b-artifacts.c
+++ b/src/builder/b-artifacts.c
@@ -80,7 +80,7 @@ saib_artifact_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf,
return LWSSSSRET_OK;
}
- n = read(ap->fd, buf,
+ n = (int)read(ap->fd, buf,
#if defined(WIN32)
(unsigned int)
#endif
@@ -98,7 +98,7 @@ saib_artifact_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf,
return LWSSSSRET_TX_DONT_SEND; /* nothing to send */
}
- ap->ofs += n;
+ ap->ofs = ap->ofs + (unsigned int)n;
lwsl_info("%s: %p: writing %d at +%llu / %llu (0x%02X)\n", __func__, ap->ss, n,
(unsigned long long)ap->ofs, (unsigned long long)ap->len, buf[0]);
*len = (size_t)n;
@@ -122,7 +122,7 @@ saib_artifact_state(void *userobj, void *sh, lws_ss_constate_t state,
sai_artifact_t *ap = (sai_artifact_t *)userobj;
struct stat s;
- lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state),
+ lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state),
(unsigned int)ack);
switch (state) {
@@ -141,7 +141,7 @@ saib_artifact_state(void *userobj, void *sh, lws_ss_constate_t state,
ap->fd = -1;
return -1;
}
- ap->len = s.st_size;
+ ap->len = (size_t)s.st_size;
break;
case LWSSSCS_DESTROYING:
diff --git a/src/builder/b-comms.c b/src/builder/b-comms.c
index e6b04ba..3bbe0aa 100644
--- a/src/builder/b-comms.c
+++ b/src/builder/b-comms.c
@@ -100,7 +100,7 @@ tp_sync_check(struct lws_dll2 *d, void *user)
// soe == NSSTATE_CHECKOUT ||
// soe == NSSTATE_CHECKEDOUT) &&
- n = lws_threadpool_task_status(ns->tp_task, &vp);
+ n = (int)lws_threadpool_task_status(ns->tp_task, &vp);
lwsl_info("%s: WRITEABLE: ss=%p: "
"task %p, priv %p, status %d\n", __func__, spm->ss,
ns->tp_task, vp, n);
@@ -242,8 +242,8 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
if (!js)
return -1;
- n = lws_struct_json_serialize(js, start,
- lws_ptr_diff(end, start), &w);
+ n = (int)lws_struct_json_serialize(js, start,
+ lws_ptr_diff_size_t(end, start), &w);
lws_struct_json_serialize_destroy(&js);
lwsl_hexdump_notice(start, w);
@@ -274,15 +274,15 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
if (!js)
return -1;
- n = lws_struct_json_serialize(js, start,
- lws_ptr_diff(end, start), &w);
+ n = (int)lws_struct_json_serialize(js, start,
+ lws_ptr_diff_size_t(end, start), &w);
lws_struct_json_serialize_destroy(&js);
sp = (sai_plat_t *)builder.sai_plat_owner.head;
lwsl_hexdump_warn(sp, sizeof(*sp));
lwsl_hexdump_notice(start, w);
- *len = (int)w;
+ *len = w;
spm->phase = PHASE_IDLE;
*flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM;
@@ -379,7 +379,7 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
if (ns->task) {
- n = lws_snprintf((char *)p, lws_ptr_diff(end, p),
+ n = lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p),
"{\"schema\":\"com-warmcat-sai-logs\","
"\"task_uuid\":\"%s\", \"timestamp\": %llu,"
"\"channel\": %d, \"len\": %d, ",
@@ -390,10 +390,10 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
/*
* Let the last guy report the finished state
*/
- n += lws_snprintf((char *)p + n, lws_ptr_diff(end, p) - n,
+ n += lws_snprintf((char *)p + n, lws_ptr_diff_size_t(end, p) - (unsigned int)n,
"\"finished\":%d,", ns->retcode);
- n += lws_snprintf((char *)p + n, lws_ptr_diff(end, p) - n,
+ n += lws_snprintf((char *)p + n, lws_ptr_diff_size_t(end, p) - (unsigned int)n,
"\"log\":\"");
// puts((const char *)&chunk[1]);
@@ -434,7 +434,7 @@ saib_m_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len,
sendify:
*flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM;
- *len = n;
+ *len = (unsigned int)n;
if (spm->phase != PHASE_IDLE || spm->logs_in_flight)
lws_ss_request_tx(spm->ss);
@@ -514,7 +514,7 @@ saib_m_state(void *userobj, void *sh, lws_ss_constate_t state,
{
struct sai_plat_server *spm = (struct sai_plat_server *)userobj;
- lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state),
+ lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state),
(unsigned int)ack);
switch (state) {
diff --git a/src/builder/b-conf.c b/src/builder/b-conf.c
index eac3467..a88ffdb 100644
--- a/src/builder/b-conf.c
+++ b/src/builder/b-conf.c
@@ -167,8 +167,8 @@ saib_conf_cb(struct lejp_ctx *ctx, char reason)
case LEJPM_PLATFORMS_NAME:
n = lws_snprintf(temp, sizeof(temp), "%s.%.*s",
builder.host, ctx->npos, ctx->buf);
- a->sai_plat->name = lwsac_use(&a->builder->conf_head, n + 1, 512);
- memcpy((char *)a->sai_plat->name, temp, n + 1);
+ a->sai_plat->name = lwsac_use(&a->builder->conf_head, (unsigned int)n + 1, 512);
+ memcpy((char *)a->sai_plat->name, temp, (unsigned int)n + 1);
lwsl_notice("%s: platform: %.*s, name %s\n", __func__,
ctx->npos, ctx->buf, a->sai_plat->name);
pp = &a->sai_plat->platform;
@@ -226,7 +226,7 @@ saib_conf_cb(struct lejp_ctx *ctx, char reason)
/* hook the ss up to the server url */
cm->url = lwsac_use(&a->builder->conf_head,
- 2 *(ctx->npos + 1), 512);
+ 2 *((unsigned int)ctx->npos + 1), 512);
memcpy((char *)cm->url, ctx->buf, ctx->npos);
((char *)cm->url)[ctx->npos] = '\0';
@@ -248,7 +248,7 @@ saib_conf_cb(struct lejp_ctx *ctx, char reason)
}
cm->name = cm->url + ctx->npos + 1;
- memcpy((char *)cm->name, pq, n);
+ memcpy((char *)cm->name, pq, (unsigned int)n);
((char *)cm->name)[n] = '\0';
while (strchr(cm->name, '.'))
@@ -272,7 +272,7 @@ saib_conf_cb(struct lejp_ctx *ctx, char reason)
return 0;
}
- *pp = lwsac_use(&a->builder->conf_head, ctx->npos + 1, 512);
+ *pp = lwsac_use(&a->builder->conf_head, ctx->npos + 1u, 512);
if (!*pp)
return 1;
memcpy((char *)(*pp), ctx->buf, ctx->npos);
@@ -322,7 +322,7 @@ saib_conf_global_cb(struct lejp_ctx *ctx, char reason)
return 0;
}
- *pp = lwsac_use(&a->builder->conf_head, ctx->npos + 1, 512);
+ *pp = lwsac_use(&a->builder->conf_head, ctx->npos + 1u, 512);
if (!*pp)
return 1;
memcpy((char *)(*pp), ctx->buf, ctx->npos);
@@ -358,7 +358,7 @@ saib_config_global(struct sai_builder *builder, const char *d)
paths_global, LWS_ARRAY_SIZE(paths_global));
do {
- n = read(fd, buf, sizeof(buf));
+ n = (int)read(fd, buf, sizeof(buf));
if (!n)
break;
@@ -366,7 +366,7 @@ saib_config_global(struct sai_builder *builder, const char *d)
} while (m == LEJP_CONTINUE);
close(fd);
- n = ctx.line;
+ n = (int)ctx.line;
lejp_destruct(&ctx);
return 0;
@@ -398,7 +398,7 @@ saib_config(struct sai_builder *builder, const char *d)
lejp_construct(&ctx, saib_conf_cb, &a, paths, LWS_ARRAY_SIZE(paths));
do {
- n = read(fd, buf, sizeof(buf));
+ n = (int)read(fd, buf, sizeof(buf));
if (!n)
break;
@@ -406,7 +406,7 @@ saib_config(struct sai_builder *builder, const char *d)
} while (m == LEJP_CONTINUE);
close(fd);
- n = ctx.line;
+ n = (int)ctx.line;
lejp_destruct(&ctx);
if (m < 0) {
diff --git a/src/builder/b-mirror.c b/src/builder/b-mirror.c
index a9ba28d..9426c2e 100644
--- a/src/builder/b-mirror.c
+++ b/src/builder/b-mirror.c
@@ -91,7 +91,8 @@ sai_mirror_local_checkout(struct sai_nspawn *ns)
* credentials since we have dropped root long ago
*/
- mkdir(ns->inp, 0755);
+ if (mkdir(ns->inp, 0755))
+ lwsl_notice("%s: mkdir %s failed\n", __func__, ns->inp);
/*
* Create the build-specific git dir and init it
@@ -278,7 +279,8 @@ saib_mirror_task(void *user, enum lws_threadpool_task_status s)
* Make sure the dir itself is left standing in there
*/
- mkdir(ns->inp, 0755);
+ if (mkdir(ns->inp, 0755))
+ lwsl_notice("%s: mkdir %s failed\n", __func__, ns->inp);
/*
* Form a request, kick the remoting thread and then
@@ -478,7 +480,7 @@ fail:
saib_task_grace(ns);
if (saib_queue_task_status_update(ns->sp, ns->spm, NULL))
- return -1;
+ return LWS_TP_RETURN_SYNC;
return LWS_TP_RETURN_SYNC;
}
diff --git a/src/builder/b-nspawn.c b/src/builder/b-nspawn.c
index fd99352..e937517 100644
--- a/src/builder/b-nspawn.c
+++ b/src/builder/b-nspawn.c
@@ -47,15 +47,20 @@ extern struct lws_vhost *builder_vhost;
struct ws_capture_chunk *
saib_log_chunk_create(struct sai_nspawn *ns, void *buf, size_t len, int channel)
{
- struct ws_capture_chunk *chunk = malloc(sizeof(*chunk) + len);
+ struct ws_capture_chunk *chunk;
- if (!chunk || !ns->spm)
+ if (!ns->spm)
+ return NULL;
+
+ chunk = malloc(sizeof(*chunk) + len);
+
+ if (!chunk)
return NULL;
memset(chunk, 0, sizeof(*chunk));
chunk->us = lws_now_usecs();
chunk->len = len;
- chunk->stdfd = channel;
+ chunk->stdfd = (uint8_t)channel;
if (len)
memcpy(&chunk[1], buf, len);
@@ -102,14 +107,14 @@ callback_sai_stdwsi(struct lws *wsi, enum lws_callback_reasons reason,
ilen = (int)rb;
}
#else
- ilen = read((int)(intptr_t)lws_get_socket_fd(wsi), buf, sizeof(buf));
+ ilen = (int)read((int)(intptr_t)lws_get_socket_fd(wsi), buf, sizeof(buf));
if (ilen < 1) {
lwsl_debug("%s: read on stdwsi failed\n", __func__);
return -1;
}
#endif
- len = ilen;
+ len = (unsigned int)ilen;
// printf("(%d) %.*s\n", (int)len, (int)len, buf);
@@ -288,7 +293,7 @@ saib_spawn(struct sai_nspawn *ns)
/* but from the script's pov, it's chrooted at /home/sai */
- if (write(fd, st, n) != n) {
+ if (write(fd, st, (unsigned int)n) != n) {
close(fd);
lwsl_err("%s: failed to write runscript to %s\n", __func__, args);
return 1;
@@ -337,11 +342,12 @@ saib_prepare_mount(struct sai_builder *b, struct sai_nspawn *ns)
n = lws_snprintf(ns->fsm.mp, sizeof(ns->fsm.mp), "%s%coverlays",
b->home, csep);
- mkdir(ns->fsm.mp, 0770);
+ if (mkdir(ns->fsm.mp, 0770))
+ lwsl_notice("%s: mkdir %s failed\n", __func__, ns->fsm.mp);
/* create a subdir for our overlay pieces */
- n += lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%c%s", csep,
+ n += lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%c%s", csep,
ns->fsm.ovname);
m = mkdir(ns->fsm.mp, 0777);
if (m && errno != EEXIST)
@@ -352,23 +358,23 @@ saib_prepare_mount(struct sai_builder *b, struct sai_nspawn *ns)
#if defined(__linux__) && 0
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%cwork", csep);
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%cwork", csep);
m = mkdir(ns->fsm.mp, 0770);
if (m && errno != EEXIST)
goto bail_dir;
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%csession", csep);
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%csession", csep);
m = mkdir(ns->fsm.mp, 0777);
if (m && errno != EEXIST)
goto bail_dir;
- n += lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%cmountpoint",
+ n += lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%cmountpoint",
csep);
m = mkdir(ns->fsm.mp, 0777);
if (m && errno != EEXIST)
goto bail_dir;
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%chome%csai",
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%chome%csai",
csep, csep);
lws_strncpy(homedir, ns->fsm.mp, sizeof(homedir));
ns->fsm.mp[n] = '\0';
@@ -383,13 +389,13 @@ saib_prepare_mount(struct sai_builder *b, struct sai_nspawn *ns)
* them off later */
n = (int)strlen(ns->fsm.mp);
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n, "%chome",
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n, "%chome",
csep);
m = mkdir(ns->fsm.mp, 0700);
if (m && errno != EEXIST)
goto bail_dir;
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n,
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n,
"%chome%csai", csep, csep);
lws_strncpy(homedir, ns->fsm.mp, sizeof(homedir));
@@ -397,7 +403,7 @@ saib_prepare_mount(struct sai_builder *b, struct sai_nspawn *ns)
if (m && errno != EEXIST)
goto bail_dir;
- lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - n,
+ lws_snprintf(ns->fsm.mp + n, sizeof(ns->fsm.mp) - (unsigned int)n,
"%chome%csai%cgit-mirror", csep, csep, csep);
m = mkdir(ns->fsm.mp, 0755);
ns->fsm.mp[n] = '\0';
diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c
index 8143123..839211d 100644
--- a/src/builder/b-sai.c
+++ b/src/builder/b-sai.c
@@ -134,7 +134,7 @@ saib_create_listen_uds(struct lws_context *context, struct saib_logproxy *lp)
memset(&info, 0, sizeof(info));
info.vhost_name = pv;
- pv += lws_snprintf(pv, sizeof(vhnames) - (pv - vhnames), "logproxy.%d", lpidx++) + 1;
+ pv += lws_snprintf(pv, sizeof(vhnames) - (size_t)(pv - vhnames), "logproxy.%d", lpidx++) + 1;
info.options = LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG |
LWS_SERVER_OPTION_UNIX_SOCK;
info.iface = lp->sockpath;
diff --git a/src/builder/b-task.c b/src/builder/b-task.c
index 1635f79..817a9f6 100644
--- a/src/builder/b-task.c
+++ b/src/builder/b-task.c
@@ -62,12 +62,12 @@ saib_set_ns_state(struct sai_nspawn *ns, int state)
char log[100];
int n;
- ns->state = state;
+ ns->state = (uint8_t)state;
ns->state_changed = 1;
n = lws_snprintf(log, sizeof(log), ">saib> %s\n", nsstates[state]);
- saib_log_chunk_create(ns, log, n, 3);
+ saib_log_chunk_create(ns, log, (unsigned int)n, 3);
if (state == NSSTATE_FAILED) {
ns->retcode = SAISPRF_EXIT | 254;
@@ -93,14 +93,14 @@ saib_queue_task_status_update(sai_plat_t *sp, struct sai_plat_server *spm,
if (!spm)
return -1;
+ if (!spm->ss)
+ return 0;
+
rej = malloc(sizeof(*rej));
if (!rej)
return -1;
- if (!spm->ss)
- return 0;
-
memset(rej, 0, sizeof(*rej));
/*
@@ -252,7 +252,7 @@ artifact_glob_cb(void *data, const char *path)
lws_strncpy(ap->artifact_up_nonce, ns->task->art_up_nonce,
sizeof(ap->artifact_up_nonce));
lws_strncpy(ap->blob_filename, ph, sizeof(ap->blob_filename));
- ap->timestamp = lws_now_usecs();
+ ap->timestamp = (uint64_t)lws_now_usecs();
lwsl_notice("%s: artifact ss created '%s'\n", __func__, ap->path);
@@ -316,7 +316,7 @@ saib_task_grace(struct sai_nspawn *ns)
m = 0;
filt[0] = '\0';
- while ((ts.e = lws_tokenize(&ts)) >= 0) {
+ while ((ts.e = (int8_t)lws_tokenize(&ts)) >= 0) {
switch (ts.e) {
case LWS_TOKZE_ENDED:
if (filt[0])
@@ -330,7 +330,7 @@ saib_task_grace(struct sai_nspawn *ns)
break;
case LWS_TOKZE_TOKEN:
lws_strnncpy(&filt[m], ts.token, ts.token_len,
- sizeof(filt) - 1 - m);
+ sizeof(filt) - 1u - (unsigned int)m);
m = (int)strlen(filt);
break;
}
@@ -352,7 +352,7 @@ scan:
if (lws_ptr_diff(p, p1) + 2 <
(int)sizeof(scandir) - m) {
memcpy(scandir + m, p1,
- lws_ptr_diff(p, p1));
+ lws_ptr_diff_size_t(p, p1));
m += lws_ptr_diff(p, p1);
scandir[m] = '\0';
} else
@@ -562,7 +562,7 @@ saib_ws_json_rx_builder(struct sai_plat_server *spm, const void *in, size_t len)
ml = lws_snprintf(mb, sizeof(mb),
">saib> Sai Builder Version: %s, lws: %s\n",
BUILD_INFO, LWS_BUILD_HASH);
- saib_log_chunk_create(ns, mb, ml, 3);
+ saib_log_chunk_create(ns, mb, (unsigned int)ml, 3);
}
saib_set_ns_state(ns, NSSTATE_INIT);
@@ -587,19 +587,19 @@ saib_ws_json_rx_builder(struct sai_plat_server *spm, const void *in, size_t len)
n = lws_snprintf(ns->inp, sizeof(ns->inp), "%s%c",
builder.home, csep);
- n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - n, "jobs%c",
+ n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - (unsigned int)n, "jobs%c",
csep);
lws_filename_purify_inplace(ns->inp);
if (mkdir(ns->inp, 0755) && errno != EEXIST)
goto ebail;
- n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - n, "%s%c",
+ n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - (unsigned int)n, "%s%c",
ns->fsm.ovname, csep);
lws_filename_purify_inplace(ns->inp);
if (mkdir(ns->inp, 0755) && errno != EEXIST)
goto ebail;
- n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - n, "%s%c",
+ n += lws_snprintf(ns->inp + n, sizeof(ns->inp) - (unsigned int)n, "%s%c",
ns->project_name, csep);
lws_filename_purify_inplace(ns->inp);
if (mkdir(ns->inp, 0755) && errno != EEXIST)
@@ -609,7 +609,7 @@ saib_ws_json_rx_builder(struct sai_plat_server *spm, const void *in, size_t len)
* Create a pending upload dir to mv artifacts into while
* we get on with the next job.
*/
- lws_snprintf(ns->inp + n, sizeof(ns->inp) - n, "../.sai-uploads");
+ lws_snprintf(ns->inp + n, sizeof(ns->inp) - (unsigned int)n, "../.sai-uploads");
if (mkdir(ns->inp, 0755) && errno != EEXIST)
goto ebail;
/*
@@ -645,7 +645,7 @@ saib_ws_json_rx_builder(struct sai_plat_server *spm, const void *in, size_t len)
q++;
}
}
- m += lws_snprintf(ns->path + m, sizeof(ns->path) - m, "%c%s",
+ m += lws_snprintf(ns->path + m, sizeof(ns->path) - (unsigned int)m, "%c%s",
csep, url);
if (mkdir(ns->path, 0755) && errno != EEXIST) {
lwsl_err("%s: unable to create %s\n", __func__,
diff --git a/src/common/ss-client-logproxy.c b/src/common/ss-client-logproxy.c
index 9d1d30f..40c550c 100644
--- a/src/common/ss-client-logproxy.c
+++ b/src/common/ss-client-logproxy.c
@@ -168,7 +168,7 @@ saicom_lp_state(void *userobj, void *sh, lws_ss_constate_t state,
{
said_logproxy_t *lp = (said_logproxy_t *)userobj;
- lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state),
+ lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name((int)state),
(unsigned int)ack);
switch (state) {
diff --git a/src/device/d-conf.c b/src/device/d-conf.c
index 078a25c..e57fa4b 100644
--- a/src/device/d-conf.c
+++ b/src/device/d-conf.c
@@ -116,7 +116,7 @@ said_conf_global_cb(struct lejp_ctx *ctx, char reason)
return -1;
a->tty->initial_monitor = 1;
- a->tty->index = a->dev->ttys_owner.count;
+ a->tty->index = (int)a->dev->ttys_owner.count;
lws_dll2_add_tail(&a->tty->list, &a->dev->ttys_owner);
return 0;
}
@@ -170,7 +170,7 @@ said_conf_global_cb(struct lejp_ctx *ctx, char reason)
return 0;
}
- *pp = lwsac_use(&a->devices->conf_head, ctx->npos + 1, 512);
+ *pp = lwsac_use(&a->devices->conf_head, ctx->npos + 1u, 512);
if (!*pp)
return 1;
memcpy((char *)(*pp), ctx->buf, ctx->npos);
@@ -191,9 +191,9 @@ said_config_global(struct sai_devices *devices, const char *d)
a.devices = devices;
#if defined(WIN32)
- lws_snprintf((char *)buf, sizeof(buf) - 1, "%s\\conf", d);
+ lws_snprintf((char *)buf, sizeof(buf) - 1u, "%s\\conf", d);
#else
- lws_snprintf((char *)buf, sizeof(buf) - 1, "%s/conf", d);
+ lws_snprintf((char *)buf, sizeof(buf) - 1u, "%s/conf", d);
#endif
fd = lws_open((char *)buf, O_RDONLY);
@@ -206,7 +206,7 @@ said_config_global(struct sai_devices *devices, const char *d)
paths_global, LWS_ARRAY_SIZE(paths_global));
do {
- n = read(fd, buf, sizeof(buf));
+ n = (int)read(fd, buf, sizeof(buf));
if (!n)
break;
@@ -214,7 +214,7 @@ said_config_global(struct sai_devices *devices, const char *d)
} while (m == LEJP_CONTINUE);
close(fd);
- n = ctx.line;
+ n = (int)ctx.line;
lejp_destruct(&ctx);
lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1,
diff --git a/src/device/d-sai.c b/src/device/d-sai.c
index 99237b3..95097e8 100644
--- a/src/device/d-sai.c
+++ b/src/device/d-sai.c
@@ -127,10 +127,10 @@ said_check_device(lws_sorted_usec_list_t *sul)
lws_tokenize_init(&ts, d->compatible,
LWS_TOKENIZE_F_COMMA_SEP_LIST |
LWS_TOKENIZE_F_MINUS_NONTERM);
- ts.len = (int)strlen(d->compatible);
+ ts.len = strlen(d->compatible);
do {
- ts.e = lws_tokenize(&ts);
+ ts.e = (int8_t)lws_tokenize(&ts);
switch (ts.e) {
case LWS_TOKZE_TOKEN:
if (!strncmp(ts.token, devtype, ts.token_len))
@@ -204,7 +204,7 @@ said_check_device(lws_sorted_usec_list_t *sul)
char *p1 = p;
p += lws_snprintf(p, sizeof(ename) -
- lws_ptr_diff(p, ename),
+ lws_ptr_diff_size_t(p, ename),
"SAI_DEVICE_TTY%d",
try);
setenv(p1, t->tty_path, 1);
@@ -228,7 +228,7 @@ said_check_device(lws_sorted_usec_list_t *sul)
n = lws_snprintf(log, sizeof(log),
"sai-device: acquired device '%s' (%s)\n",
d->name, d->type);
- saicom_lp_add(ssh[0], log, n);
+ saicom_lp_add(ssh[0], log, (unsigned int)n);
/*
* We'll check in the background if the child
* exited, in the meanwhile we can send any
@@ -281,7 +281,7 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
n = lws_snprintf(log, sizeof(log),
"sai-device: queueing for device compatible with '%s'\n",
devtype);
- saicom_lp_add(ssh[0], log, n);
+ saicom_lp_add(ssh[0], log, (unsigned int)n);
lws_sul_schedule(context, 0, &sul, said_check_device, 1);
break;
diff --git a/src/expect/e-sai.c b/src/expect/e-sai.c
index c90a796..ec73f24 100644
--- a/src/expect/e-sai.c
+++ b/src/expect/e-sai.c
@@ -97,7 +97,7 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
goto bail;
n = lws_snprintf(log, sizeof(log), "sai-expect: starting\n");
- saicom_lp_add(ssh[0], log, n);
+ saicom_lp_add(ssh[0], log, (unsigned int)n);
break;
}
diff --git a/src/expect/e-serial.c b/src/expect/e-serial.c
index 2de2443..338f5e1 100644
--- a/src/expect/e-serial.c
+++ b/src/expect/e-serial.c
@@ -83,8 +83,8 @@ sai_serial_try_open(struct lws_vhost *vh, const char *devpath, int _rate, int i)
return NULL;
}
- cfsetospeed(&tio, rate);
- cfsetispeed(&tio, rate);
+ cfsetospeed(&tio, (speed_t)rate);
+ cfsetispeed(&tio, (speed_t)rate);
tcsetattr(fd, TCSANOW, &tio);
tcflush(fd, TCIOFLUSH);
@@ -114,7 +114,7 @@ finished_cb(void *opaque)
static void
spill(struct pss *pss)
{
- saicom_lp_add(ssh[pss->i + 1], pss->collation, pss->pos);
+ saicom_lp_add(ssh[pss->i + 1], pss->collation, (unsigned int)pss->pos);
pss->pos = 0;
pss->earliest = 0;
lws_sul_cancel(&pss->sul);
@@ -165,7 +165,7 @@ callback_serial(struct lws *wsi, enum lws_callback_reasons reason,
* Let's collate them up to 128 bytes, with a 150ms limit to
* holding pieces
*/
- n = read((int)(intptr_t)lws_get_socket_fd(wsi), buf, sizeof(buf));
+ n = (int)read((int)(intptr_t)lws_get_socket_fd(wsi), buf, sizeof(buf));
if (n < 1) {
lwsl_debug("%s: read on stdwsi failed\n", __func__);
return -1;
@@ -175,7 +175,7 @@ callback_serial(struct lws *wsi, enum lws_callback_reasons reason,
break;
for (m = 0; m < n; m++) {
- pss->collation[pss->pos++] = buf[m];
+ pss->collation[pss->pos++] = (char)buf[m];
if (buf[m] == pass[pss->pass_match]) {
pss->pass_match++;
diff --git a/src/jig/j-conf.c b/src/jig/j-conf.c
index 095abae..86e0193 100644
--- a/src/jig/j-conf.c
+++ b/src/jig/j-conf.c
@@ -104,7 +104,7 @@ saij_config_global(const char *d)
lws_struct_json_init_parse(&ctx, NULL, &a);
do {
- n = read(fd, buf, sizeof(buf));
+ n = (int)read(fd, buf, sizeof(buf));
if (!n)
break;
@@ -118,7 +118,7 @@ saij_config_global(const char *d)
}
close(fd);
- n = ctx.line;
+ n = (int)ctx.line;
lejp_destruct(&ctx);
jig = a.dest;
@@ -152,7 +152,7 @@ saij_config_global(const char *d)
goto bail1;
}
jig->chip[g->chip_idx] =
- gpiod_chip_open_by_number(g->chip_idx);
+ gpiod_chip_open_by_number((unsigned int)g->chip_idx);
if (!jig->chip[g->chip_idx]) {
lwsl_err("%s: unable to open chip %d\n",
__func__, g->chip_idx);
@@ -161,7 +161,7 @@ saij_config_global(const char *d)
}
g->line = gpiod_chip_get_line(jig->chip[g->chip_idx],
- g->offset);
+ (unsigned int)g->offset);
if (!g->line) {
lwsl_err("%s: unable to get gpio line %d\n",
__func__, g->offset);
diff --git a/src/jig/j-server.c b/src/jig/j-server.c
index 4040288..a9c48fe 100644
--- a/src/jig/j-server.c
+++ b/src/jig/j-server.c
@@ -200,7 +200,7 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,
break;
fin:
- if (lws_add_http_common_headers(wsi, pss->ret, "text/html", 0,
+ if (lws_add_http_common_headers(wsi, (unsigned int)pss->ret, "text/html", 0,
&p, end))
return 1;
if (lws_finalize_write_http_header(wsi, start, &p, end))
diff --git a/src/server/s-comms.c b/src/server/s-comms.c
index fe88a57..80a45b4 100644
--- a/src/server/s-comms.c
+++ b/src/server/s-comms.c
@@ -240,17 +240,17 @@ sais_event_db_delete_database(struct vhd *vhd, const char *event_uuid)
lws_snprintf(filepath, sizeof(filepath), "%s-event-%s.sqlite3",
vhd->sqlite3_path_lhs, saf);
- r = unlink(filepath);
+ r = (char)!!unlink(filepath);
lws_snprintf(filepath, sizeof(filepath), "%s-event-%s.sqlite3-wal",
vhd->sqlite3_path_lhs, saf);
- r |= unlink(filepath);
+ r |= (char)!!unlink(filepath);
lws_snprintf(filepath, sizeof(filepath), "%s-event-%s.sqlite3-shm",
vhd->sqlite3_path_lhs, saf);
- return r | unlink(filepath);
+ return r | !!unlink(filepath);
}
@@ -336,7 +336,7 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
*end = &buf[sizeof(buf) - LWS_PRE - 1];
struct pss *pss = (struct pss *)user;
sai_http_murl_t mu = SHMUT_NONE;
- int n, resp;
+ int n;
(void)end;
(void)p;
@@ -408,7 +408,6 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
case LWS_CALLBACK_HTTP:
- resp = HTTP_STATUS_FORBIDDEN;
pss->vhd = vhd;
for (n = 0; n < (int)LWS_ARRAY_SIZE(well_known); n++)
@@ -437,15 +436,6 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
return 0;
}
- resp = HTTP_STATUS_OK;
-
- if (lws_add_http_header_status(wsi, resp, &p, end))
- goto bail;
- if (lws_add_http_header_content_length(wsi, 0, &p, end))
- goto bail;
- if (lws_finalize_write_http_header(wsi, start, &p, end))
- goto bail;
- goto try_to_reuse;
/*
* Notifcation POSTs
@@ -695,15 +685,6 @@ passthru:
}
return lws_callback_http_dummy(wsi, reason, user, in, len);
-
-bail:
- return 1;
-
-try_to_reuse:
- if (lws_http_transaction_completed(wsi))
- return -1;
-
- return 0;
}
const struct lws_protocols protocol_ws =
diff --git a/src/server/s-notification.c b/src/server/s-notification.c
index 315be97..d401758 100644
--- a/src/server/s-notification.c
+++ b/src/server/s-notification.c
@@ -169,7 +169,7 @@ sai_tuple_element_compare(const char *e1, const char *e2)
}
static int
-sai_tuple_compare(const char *req, int req_len, const char *plat)
+sai_tuple_compare(const char *req, size_t req_len, const char *plat)
{
const char *pos = req;
char e1[96];
@@ -330,7 +330,8 @@ sai_saifile_lejp_cb(struct lejp_ctx *ctx, char reason)
if (!strncmp(ts.token, "none",
ts.token_len)) {
- not = match = 0;
+ not = 0;
+ match = 0;
continue;
}
if (!strncmp(ts.token, "not",
@@ -446,7 +447,8 @@ sai_saifile_lejp_cb(struct lejp_ctx *ctx, char reason)
if (!strncmp(ts.token, "none",
ts.token_len)) {
- not = match = 0;
+ not = 0;
+ match = 0;
continue;
}
if (!strncmp(ts.token, "not",
@@ -535,7 +537,7 @@ sai_saifile_lejp_cb(struct lejp_ctx *ctx, char reason)
lws_struct_sq3_serialize(pdb,
lsm_schema_sq3_map_task,
- &owner, pss->sn.t.uid);
+ &owner, (uint32_t)pss->sn.t.uid);
}
} lws_end_foreach_dll(p);
@@ -748,7 +750,7 @@ sai_notification_lejp_cb(struct lejp_ctx *ctx, char reason)
break;
case LEJPN_SAIFILE_LEN:
- sn->saifile_in_len = atoi(ctx->buf);
+ sn->saifile_in_len = (unsigned int)atoi(ctx->buf);
/* only accept sane base64 size */
if (sn->saifile_in_len < 8 || sn->saifile_in_len > 65536) {
lwsl_err("%s: bad saifile_len %u\n", __func__,
@@ -832,7 +834,7 @@ sai_notification_file_upload_cb(void *data, const char *name,
case LWS_UFS_FINAL_CONTENT:
case LWS_UFS_CONTENT:
lwsl_notice("%s: LWS_UFS_[]CONTENT: %p %p, \n", __func__, pss, buf);
- if (len && lws_genhmac_update(&pss->hmac, buf, len))
+ if (len && lws_genhmac_update(&pss->hmac, buf, (unsigned int)len))
return -1;
printf("%.*s", (int)len, buf);
@@ -917,7 +919,7 @@ sai_notification_file_upload_cb(void *data, const char *name,
lejp_construct(&saictx, sai_saifile_lejp_cb, pss, saifile_paths,
LWS_ARRAY_SIZE(saifile_paths));
m = lejp_parse(&saictx, (uint8_t *)pss->sn.saifile,
- pss->sn.saifile_out_pos);
+ (int)pss->sn.saifile_out_pos);
sais_event_db_close(pss->vhd, (sqlite3 **)&pss->sn.e.pdb);
if (m < 0) {
lwsl_notice("%s: saifile JSON decode failed '%s' (%d)\n",
@@ -951,7 +953,7 @@ sai_notification_file_upload_cb(void *data, const char *name,
lejp_construct(&saictx, sai_saifile_lejp_cb, pss, saifile_paths,
LWS_ARRAY_SIZE(saifile_paths));
m = lejp_parse(&saictx, (uint8_t *)pss->sn.saifile,
- pss->sn.saifile_out_pos);
+ (int)pss->sn.saifile_out_pos);
free(pss->sn.saifile);
pss->sn.saifile = NULL;
if (m < 0) {
diff --git a/src/server/s-task.c b/src/server/s-task.c
index f36737f..f80d8da 100644
--- a/src/server/s-task.c
+++ b/src/server/s-task.c
@@ -34,7 +34,7 @@ sql3_get_integer_cb(void *user, int cols, char **values, char **name)
unsigned int *pui = (unsigned int *)user;
// lwsl_warn("%s: values[0] '%s'\n", __func__, values[0]);
- *pui = atoi(values[0]);
+ *pui = (unsigned int)atoi(values[0]);
return 0;
}
@@ -348,7 +348,7 @@ sais_task_cancel(struct vhd *vhd, const char *task_uuid)
return -1;
memset(can, 0, sizeof(*can));
- strncpy(can->task_uuid, task_uuid, sizeof(can->task_uuid));
+ lws_strncpy(can->task_uuid, task_uuid, sizeof(can->task_uuid));
lws_dll2_add_tail(&can->list, &pss->task_cancel_owner);
diff --git a/src/server/s-websrv.c b/src/server/s-websrv.c
index 1425648..72eff5a 100644
--- a/src/server/s-websrv.c
+++ b/src/server/s-websrv.c
@@ -149,8 +149,9 @@ sais_list_builders(struct vhd *vhd)
size_t w;
int n;
- p += lws_snprintf((char *)p, end - p, "{\"schema\":\"sai-builders\","
- "\"platforms\":[");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p),
+ "{\"schema\":\"sai-builders\","
+ "\"platforms\":[");
while (end - p > 512 && walk) {
@@ -167,7 +168,7 @@ sais_list_builders(struct vhd *vhd)
subsequent = 1;
n = lws_struct_json_serialize(js, (unsigned char *)p,
- lws_ptr_diff(end, p), &w);
+ lws_ptr_diff_size_t(end, p), &w);
p += w;
lws_struct_json_serialize_destroy(&js);
@@ -176,11 +177,11 @@ sais_list_builders(struct vhd *vhd)
walk = walk->next;
if (!walk) {
- p += lws_snprintf((char *)p, end - p, "]}");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}");
sais_websrv_broadcast(vhd->h_ss_websrv,
vhd->json_builders,
- lws_ptr_diff(p, vhd->json_builders));
+ lws_ptr_diff_size_t(p, vhd->json_builders));
return 0;
}
@@ -206,7 +207,7 @@ _sais_taskchange(struct lws_ss_handle *h, void *_arg)
"\"event_hash\":\"%s\", \"state\":%d}",
arg->uid, arg->state);
- if (lws_buflist_append_segment(&m->bltx, (uint8_t *)tc, n) >= 0)
+ if (lws_buflist_append_segment(&m->bltx, (uint8_t *)tc, (unsigned int)n) >= 0)
lws_ss_request_tx(h);
else
lwsl_warn("%s: buflist append failed\n", __func__);
@@ -232,7 +233,7 @@ _sais_eventchange(struct lws_ss_handle *h, void *_arg)
"\"event_hash\":\"%s\", \"state\":%d}",
arg->uid, arg->state);
- if (lws_buflist_append_segment(&m->bltx, (uint8_t *)tc, n) >= 0)
+ if (lws_buflist_append_segment(&m->bltx, (uint8_t *)tc, (unsigned int)n) >= 0)
lws_ss_request_tx(h);
else
lwsl_warn("%s: buflist append failed\n", __func__);
@@ -268,7 +269,7 @@ websrvss_ws_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
a.ac_block_size = 128;
lws_struct_json_init_parse(&m->ctx, NULL, &a);
- n = lejp_parse(&m->ctx, (uint8_t *)buf, len);
+ n = lejp_parse(&m->ctx, (uint8_t *)buf, (int)len);
if (n < 0 || !a.dest) {
lwsl_hexdump_notice(buf, len);
lwsl_notice("%s: notification JSON decode failed '%s'\n",
@@ -319,6 +320,7 @@ websrvss_ws_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
sqlite3_exec(pdb, "BEGIN TRANSACTION",
NULL, NULL, &err);
+ sqlite3_free(err);
/*
* Walk the results list resetting all the tasks
@@ -334,6 +336,7 @@ websrvss_ws_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
sqlite3_exec(pdb, "END TRANSACTION",
NULL, NULL, &err);
+ sqlite3_free(err);
}
sais_event_db_close(m->vhd, &pdb);
diff --git a/src/server/s-ws-builder.c b/src/server/s-ws-builder.c
index 768839d..b931311 100644
--- a/src/server/s-ws-builder.c
+++ b/src/server/s-ws-builder.c
@@ -129,7 +129,7 @@ sais_dump_logs_to_db(lws_sorted_usec_list_t *sul)
n = lws_snprintf(sw, sizeof(sw), "{\"schema\":\"sai-tasklogs\","
"\"event_hash\":\"%s\"}", lcpt->uuid);
- sais_websrv_broadcast(vhd->h_ss_websrv, sw, n);
+ sais_websrv_broadcast(vhd->h_ss_websrv, sw, (unsigned int)n);
/*
* Destroy the whole task-specific cache, it will regenerate
@@ -245,7 +245,7 @@ sais_ws_json_rx_builder(struct vhd *vhd, struct pss *pss, uint8_t *buf, size_t b
if (pss->bulk_binary_data) {
lwsl_info("%s: bulk %d\n", __func__, (int)bl);
- m = bl;
+ m = (int)bl;
goto handle;
}
@@ -270,7 +270,7 @@ sais_ws_json_rx_builder(struct vhd *vhd, struct pss *pss, uint8_t *buf, size_t b
} else
pss->frag = 0;
- m = lejp_parse(&pss->ctx, (uint8_t *)buf, bl);
+ m = lejp_parse(&pss->ctx, (uint8_t *)buf, (int)bl);
/*
* returns negative, or unused amount... for us, we either had a
@@ -566,7 +566,7 @@ bail:
if (lws_struct_sq3_serialize(pss->pdb_artifact,
lsm_schema_sq3_map_artifact,
- &o, ap->uid)) {
+ &o, (unsigned int)ap->uid)) {
lwsl_err("%s: failed artifact struct insert\n",
__func__);
@@ -614,7 +614,7 @@ bail:
*/
if (sqlite3_blob_open(pss->pdb_artifact, "main",
- "artifacts", "blob", rid, 1,
+ "artifacts", "blob", (sqlite3_int64)rid, 1,
&pss->blob_artifact) != SQLITE_OK) {
lwsl_err("%s: unable to open blob\n", __func__);
goto afail;
@@ -627,24 +627,24 @@ bail:
pss->bulk_binary_data = 1;
pss->artifact_length = ap->len;
} else {
- m = bl;
+ m = (int)bl;
lwsl_info("%s: BUILDER_ARTIFACT: blob bulk\n", __func__);
}
if (m) {
lwsl_info("%s: blob write +%d, ofs %llu / %llu, len %d (0x%02x)\n",
- __func__, (int)(bl - m),
+ __func__, (int)(bl - (unsigned int)m),
(unsigned long long)pss->artifact_offset,
(unsigned long long)pss->artifact_length, m, buf[0]);
if (sqlite3_blob_write(pss->blob_artifact,
- (uint8_t *)buf + (bl - m), (int)m,
- pss->artifact_offset)) {
+ (uint8_t *)buf + (bl - (unsigned int)m), (int)m,
+ (int)pss->artifact_offset)) {
lwsl_err("%s: writing blob failed\n", __func__);
goto afail;
}
lws_set_timeout(pss->wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5);
- pss->artifact_offset += (int)m;
+ pss->artifact_offset = pss->artifact_offset + (uint64_t)m;
} else
lwsl_info("%s: no m\n", __func__);
@@ -710,7 +710,7 @@ sais_ws_json_tx_builder(struct vhd *vhd, struct pss *pss, uint8_t *buf,
if (!js)
return 1;
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
lws_dll2_remove(&c->list);
@@ -743,7 +743,7 @@ sais_ws_json_tx_builder(struct vhd *vhd, struct pss *pss, uint8_t *buf,
if (!js)
return 1;
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
pss->one_event = NULL;
lwsac_free(&task->ac_task_container);
@@ -769,7 +769,7 @@ send_json:
// lwsl_hexdump_notice(start, p - start);
- if (lws_write(pss->wsi, start, p - start, flags) < 0)
+ if (lws_write(pss->wsi, start, lws_ptr_diff_size_t(p, start), flags) < 0)
return -1;
lws_callback_on_writable(pss->wsi);
diff --git a/src/web/w-artifact.c b/src/web/w-artifact.c
index 2b87270..553a2a9 100644
--- a/src/web/w-artifact.c
+++ b/src/web/w-artifact.c
@@ -127,7 +127,7 @@ saiw_get_blob(struct vhd *vhd, const char *url, sqlite3 **pdb,
* Get a read-only handle on the blob
*/
- if (sqlite3_blob_open(*pdb, "main", "artifacts", "blob", rid, 0, blob) != SQLITE_OK) {
+ if (sqlite3_blob_open(*pdb, "main", "artifacts", "blob", (sqlite3_int64)rid, 0, blob) != SQLITE_OK) {
lwsl_err("%s: unable to open blob, rid %d\n", __func__, (int)rid);
goto fail;
}
diff --git a/src/web/w-comms.c b/src/web/w-comms.c
index 21da346..4cb28e8 100644
--- a/src/web/w-comms.c
+++ b/src/web/w-comms.c
@@ -475,11 +475,11 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
}
n = open(cp, LWS_O_RDONLY);
- if (!n) {
+ if (n < 0) {
lwsl_err("%s: can't open auth JWK %s\n", __func__, cp);
return -1;
}
- r = read(n, buf, sizeof(buf));
+ r = (int)read(n, buf, sizeof(buf));
close(n);
if (r < 0) {
lwsl_err("%s: can't read auth JWK %s\n", __func__, cp);
@@ -487,7 +487,7 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
}
if (lws_jwk_import(&vhd->jwt_jwk_auth, NULL, NULL,
- (const char *)buf, r)) {
+ (const char *)buf, (unsigned int)r)) {
lwsl_notice("%s: Failed to parse JWK key\n", __func__);
return -1;
}
@@ -661,12 +661,12 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
return 0;
}
- resp = HTTP_STATUS_OK;
+// resp = HTTP_STATUS_OK;
- /* faillthru */
+// /* faillthru */
http_resp:
- if (lws_add_http_header_status(wsi, resp, &p, end))
+ if (lws_add_http_header_status(wsi, (unsigned int)resp, &p, end))
goto bail;
if (lws_add_http_header_content_length(wsi, 0, &p, end))
goto bail;
@@ -687,14 +687,14 @@ http_resp:
n = (int)(pss->artifact_length - pss->artifact_offset);
if (sqlite3_blob_read(pss->blob_artifact, start, n,
- pss->artifact_offset)) {
+ (int)pss->artifact_offset)) {
lwsl_err("%s: blob read failed\n", __func__);
return -1;
}
- pss->artifact_offset += n;
+ pss->artifact_offset = pss->artifact_offset + (unsigned int)n;
- if (lws_write(wsi, start, n,
+ if (lws_write(wsi, start, (unsigned int)n,
pss->artifact_offset != pss->artifact_length ?
LWS_WRITE_HTTP : LWS_WRITE_HTTP_FINAL) != n)
return -1;
@@ -868,7 +868,7 @@ back:
if (lws_add_http_header_by_token(wsi,
WSI_TOKEN_HTTP_LOCATION,
(unsigned char *)sr,
- strlen((const char *)sr),
+ (int)strlen((const char *)sr),
&p, end)) {
goto clean_spa;
}
diff --git a/src/web/w-websrv.c b/src/web/w-websrv.c
index ab7bf88..a7e849a 100644
--- a/src/web/w-websrv.c
+++ b/src/web/w-websrv.c
@@ -85,7 +85,7 @@ saiw_lp_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
lws_struct_json_init_parse(&m->ctx, NULL, &m->a);
}
- n = lejp_parse(&m->ctx, (uint8_t *)buf, len);
+ n = lejp_parse(&m->ctx, (uint8_t *)buf, (int)len);
if (n < LEJP_CONTINUE || (n >= 0 && !m->a.dest)) {
lwsac_free(&m->a.ac);
lwsl_hexdump_notice(buf, len);
diff --git a/src/web/w-ws-browser.c b/src/web/w-ws-browser.c
index 1ec58ba..c426346 100644
--- a/src/web/w-ws-browser.c
+++ b/src/web/w-ws-browser.c
@@ -299,7 +299,7 @@ saiw_pss_schedule_taskinfo(struct pss *pss, const char *task_uuid, int logsub)
m = lws_snprintf(qu, sizeof(qu), " and uuid='%s'", esc);
if (pss->specific_project[0]) {
lws_sql_purify(esc2, pss->specific_project, sizeof(esc2));
- m += lws_snprintf(qu + m, sizeof(qu) - m, " and repo_name='%s'", esc2);
+ m += lws_snprintf(qu + m, sizeof(qu) - (unsigned int)m, " and repo_name='%s'", esc2);
}
if (pss->specific_ref[0] && pss->specificity != SAIM_SPECIFIC_TASK) {
@@ -307,13 +307,13 @@ saiw_pss_schedule_taskinfo(struct pss *pss, const char *task_uuid, int logsub)
if (pss->specific_ref[0] == 'r') {
/* check event ref against, eg, ref/heads/xxx */
if (!strcmp(pss->specific_ref, "refs/heads/master"))
- m += lws_snprintf(qu + m, sizeof(qu) - m,
+ m += lws_snprintf(qu + m, sizeof(qu) - (unsigned int)m,
" and (ref='refs/heads/master' or ref='refs/heads/main')");
else
- m += lws_snprintf(qu + m, sizeof(qu) - m, " and ref='%s'", esc2);
+ m += lws_snprintf(qu + m, sizeof(qu) - (unsigned int)m, " and ref='%s'", esc2);
} else
/* check event hash against, eg, 12341234abcd... */
- m += lws_snprintf(qu + m, sizeof(qu) - m, " and hash='%s'", esc2);
+ m += lws_snprintf(qu + m, sizeof(qu) - (unsigned int)m, " and hash='%s'", esc2);
}
n = lws_struct_sq3_deserialize(pss->vhd->pdb, qu, NULL,
@@ -324,7 +324,7 @@ saiw_pss_schedule_taskinfo(struct pss *pss, const char *task_uuid, int logsub)
goto bail;
}
- sch->logsub = logsub;
+ sch->logsub = !!logsub;
sch->one_event = lws_container_of(o.head, sai_event_t, list);
saiw_alloc_sched(pss, WSS_PREPARE_BUILDER_SUMMARY);
@@ -404,7 +404,7 @@ saiw_ws_json_rx_browser(struct vhd *vhd, struct pss *pss, uint8_t *buf,
a.ac_block_size = 128;
lws_struct_json_init_parse(&pss->ctx, NULL, &a);
- m = lejp_parse(&pss->ctx, (uint8_t *)buf, bl);
+ m = lejp_parse(&pss->ctx, (uint8_t *)buf, (int)bl);
if (m < 0 || !a.dest) {
lwsl_hexdump_notice(buf, bl);
lwsl_notice("%s: browser->web JSON decode failed '%s'\n",
@@ -652,7 +652,7 @@ again:
}
pss->log_cache_index = 0;
- pss->log_cache_size = pss->logs_owner.count;
+ pss->log_cache_size = (int)pss->logs_owner.count;
}
if (pss->log_cache_index < pss->log_cache_size) {
@@ -675,7 +675,7 @@ again:
return 0;
}
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
if (n == LSJS_RESULT_ERROR) {
lwsl_notice("%s: json ser error\n", __func__);
@@ -710,6 +710,9 @@ again:
case WSS_PREPARE_OVERVIEW:
+ if (!sch) /* coverity */
+ goto no_sch;
+
filt[0] = '\0';
if (pss->specific_project[0]) {
lws_sql_purify(esc, pss->specific_project, sizeof(esc) - 1);
@@ -736,7 +739,7 @@ again:
lwsl_debug("%s: WSS_PREPARE_OVERVIEW: %d results %p\n",
__func__, sch->owner.count, sch->ac);
- p += lws_snprintf((char *)p, end - p,
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p),
"{\"schema\":\"sai.warmcat.com.overview\","
" \"alang\":\"%s\","
" \"authorized\": %d,"
@@ -771,6 +774,9 @@ again:
case WSS_SEND_OVERVIEW:
+ if (!sch) /* coverity */
+ goto no_sch;
+
if (sch->ovstate == SOS_TASKS)
goto enum_tasks;
@@ -813,9 +819,9 @@ again:
*p++ = ',';
sch->subsequent = 1;
- p += lws_snprintf((char *)p, end - p, "{\"e\":");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "{\"e\":");
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
switch (n) {
case LSJS_RESULT_ERROR:
@@ -829,7 +835,7 @@ again:
p += w;
sch->ovstate = SOS_TASKS;
sch->task_index = 0;
- p += lws_snprintf((char *)p, end - p, ", \"t\":[");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), ", \"t\":[");
goto enum_tasks;
}
}
@@ -848,6 +854,7 @@ enum_tasks:
*/
e = lws_container_of(sch->walk, sai_event_t, list);
+ lws_dll2_owner_clear(&task_owner);
do {
task_ac = NULL;
@@ -899,7 +906,7 @@ enum_tasks:
lsm_schema_json_map_task,
LWS_ARRAY_SIZE(lsm_schema_json_map_task), 0, t);
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
lwsac_free(&task_ac);
p += w;
@@ -913,7 +920,7 @@ enum_tasks:
/* none left to do, go back up a level */
- p += lws_snprintf((char *)p, end - p, "]}");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}");
sch->ovstate = SOS_EVENT;
if (pss->specificity)
@@ -928,13 +935,17 @@ enum_tasks:
break;
so_finish:
- p += lws_snprintf((char *)p, end - p, "]}");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}");
pss->send_state = WSS_IDLE;
endo = 1;
break;
case WSS_PREPARE_BUILDER_SUMMARY:
- p += lws_snprintf((char *)p, end - p,
+
+ if (!sch) /* coverity */
+ goto no_sch;
+
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p),
"{\"schema\":\"com.warmcat.sai.builders\","
" \"alang\":\"%s\","
" \"authorized\":%d,"
@@ -956,6 +967,10 @@ so_finish:
/* fallthru */
case WSS_SEND_BUILDER_SUMMARY:
+
+ if (!sch) /* coverity */
+ goto no_sch;
+
if (!sch->walk)
goto b_finish;
@@ -983,7 +998,7 @@ so_finish:
*p++ = ',';
sch->subsequent = 1;
- switch (lws_struct_json_serialize(js, p, end - p, &w)) {
+ switch (lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w)) {
case LSJS_RESULT_ERROR:
lws_struct_json_serialize_destroy(&js);
pss->send_state = WSS_IDLE;
@@ -1008,13 +1023,17 @@ so_finish:
}
break;
b_finish:
- p += lws_snprintf((char *)p, end - p, "]}");
+ p += lws_snprintf((char *)p, lws_ptr_diff_size_t(end, p), "]}");
lwsac_unreference(&vhd->builders);
endo = 1;
break;
case WSS_PREPARE_TASKINFO:
+
+ if (!sch) /* coverity */
+ goto no_sch;
+
/*
* We're sending a browser the specific task info that he
* asked for.
@@ -1027,7 +1046,7 @@ b_finish:
task_reply.event = sch->one_event;
task_reply.task = sch->one_task;
- task_reply.auth_secs = pss->authorized ? pss->expiry_unix_time - lws_now_secs() : 0;
+ task_reply.auth_secs = (int)(pss->authorized ? pss->expiry_unix_time - lws_now_secs() : 0);
task_reply.authorized = pss->authorized;
lws_strncpy(task_reply.auth_user, pss->auth_user,
sizeof(task_reply.auth_user));
@@ -1040,7 +1059,7 @@ b_finish:
return 1;
}
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
/*
@@ -1096,6 +1115,10 @@ b_finish:
break;
case WSS_SEND_ARTIFACT_INFO:
+
+ if (!sch) /* coverity */
+ goto no_sch;
+
if (sch->owner.head) {
sai_artifact_t *aft = (sai_artifact_t *)sch->owner.head;
@@ -1114,7 +1137,7 @@ b_finish:
return 1;
}
- n = lws_struct_json_serialize(js, p, end - p, &w);
+ n = lws_struct_json_serialize(js, p, lws_ptr_diff_size_t(end, p), &w);
lws_struct_json_serialize_destroy(&js);
if (n == LSJS_RESULT_ERROR) {
lwsl_notice("%s: taskinfo: ---------- error generating json\n", __func__);
@@ -1135,6 +1158,10 @@ b_finish:
}
send_it:
+
+ if (!sch) /* coverity */
+ goto no_sch;
+
flags = lws_write_ws_flags(LWS_WRITE_TEXT, first, endo || lg || !sch->walk);
if (lg || endo ||
@@ -1157,10 +1184,15 @@ send_it:
saiw_dealloc_sched(sch);
}
- if (lws_write(pss->wsi, start, p - start, flags) < 0)
+ if (lws_write(pss->wsi, start, lws_ptr_diff_size_t(p, start), flags) < 0)
return -1;
lws_callback_on_writable(pss->wsi);
return 0;
+
+no_sch:
+ pss->send_state = WSS_IDLE;
+
+ return 0;
}