From 56db6a8e4dbd0c4704b2e89715a4850ea2298a5d Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 10 Sep 2022 01:42:15 +0000 Subject: [PATCH] Fix exciting new gcc 11 compiler warnings. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3973 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/file.js.c | 16 ++++++++-------- src/socket.js.c | 36 ++++++++++-------------------------- src/ssb.js.c | 4 ++-- src/task.c | 9 ++------- 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/file.js.c b/src/file.js.c index 2f2d01e3..03ceeee8 100644 --- a/src/file.js.c +++ b/src/file.js.c @@ -84,7 +84,7 @@ static void _file_read_read_callback(uv_fs_t* req) } else { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(req->result))); } int result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); if (result < 0) @@ -108,7 +108,7 @@ static void _file_read_open_callback(uv_fs_t* req) int result = uv_fs_read(req->loop, req, fsreq->file, &buf, 1, 0, _file_read_read_callback); if (result < 0) { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(result))); result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); if (result < 0) { @@ -119,7 +119,7 @@ static void _file_read_open_callback(uv_fs_t* req) } else { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(req->result))); uv_fs_req_cleanup(req); tf_free(req); } @@ -144,7 +144,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar int result = uv_fs_open(tf_task_get_loop(task), &req->fs, file_name, UV_FS_O_RDONLY, 0, _file_read_open_callback); if (result < 0) { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(result))); uv_fs_req_cleanup(&req->fs); tf_free(req); } @@ -165,7 +165,7 @@ static void _file_write_write_callback(uv_fs_t* req) } else { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(req->result))); } int result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); if (result < 0) @@ -189,7 +189,7 @@ static void _file_write_open_callback(uv_fs_t* req) int result = uv_fs_write(req->loop, req, fsreq->file, &buf, 1, 0, _file_write_write_callback); if (result < 0) { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(result))); result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); if (result < 0) { @@ -200,7 +200,7 @@ static void _file_write_open_callback(uv_fs_t* req) } else { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(req->result))); uv_fs_req_cleanup(req); tf_free(req); } @@ -243,7 +243,7 @@ static JSValue _file_write_file(JSContext* context, JSValueConst this_val, int a int result = uv_fs_open(tf_task_get_loop(task), &req->fs, file_name, UV_FS_O_CREAT | UV_FS_O_WRONLY, 0644, _file_write_open_callback); if (result < 0) { - tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); + tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, "%s", uv_strerror(result))); } JS_FreeCString(context, file_name); return promise_value; diff --git a/src/socket.js.c b/src/socket.js.c index fdd383fe..b3f5b89e 100644 --- a/src/socket.js.c +++ b/src/socket.js.c @@ -430,9 +430,7 @@ JSValue _socket_bind(JSContext* context, JSValueConst this_val, int argc, JSValu int result = uv_getaddrinfo(tf_task_get_loop(socket->_task), &data->resolver, _socket_onResolvedForBind, node, port, &hints); if (result != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_getaddrinfo: %s", uv_strerror(result)); - tf_task_reject_promise(socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(socket->_task), error)); + tf_task_reject_promise(socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(socket->_task), "uv_getaddrinfo: %s", uv_strerror(result))); tf_free(data); } return promise; @@ -443,18 +441,14 @@ void _socket_onResolvedForBind(uv_getaddrinfo_t* resolver, int status, struct ad socket_resolve_data_t* data = (socket_resolve_data_t*)resolver->data; if (status != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_getaddrinfo: %s", uv_strerror(status)); - tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), error)); + tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_getaddrinfo: %s", uv_strerror(status))); } else { int bindResult = uv_tcp_bind(&data->socket->_socket, result->ai_addr, 0); if (bindResult != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_tcp_bind: %s", uv_strerror(bindResult)); - tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), error)); + tf_task_reject_promise(data->socket->_task, data->promise, JS_ThrowInternalError(tf_task_get_context(data->socket->_task), "uv_tcp_bind: %s", uv_strerror(bindResult))); } else { @@ -561,9 +555,7 @@ JSValue _socket_listen(JSContext* context, JSValueConst this_val, int argc, JSVa int result = uv_listen((uv_stream_t*)&socket->_socket, backlog, _socket_onNewConnection); if (result != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_listen: %s", uv_strerror(result)); - return JS_ThrowInternalError(context, error); + return JS_ThrowInternalError(context, "uv_listen: %s", uv_strerror(result)); } return JS_NewInt32(context, result); } @@ -609,9 +601,7 @@ JSValue _socket_accept(JSContext* context, JSValueConst this_val, int argc, JSVa } else { - char error[256]; - snprintf(error, sizeof(error), "uv_accept: %s", uv_strerror(status)); - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, error)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, "uv_accept: %s", uv_strerror(status))); } JS_FreeValue(context, client->_object); return result; @@ -706,9 +696,7 @@ JSValue _socket_read(JSContext* context, JSValueConst this_val, int argc, JSValu int result = uv_read_start((uv_stream_t*)&socket->_socket, _socket_allocateBuffer, _socket_onRead); if (result != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_read_start: %s", uv_strerror(result)); - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, error)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, "uv_read_start: %s", uv_strerror(result))); } else { @@ -768,7 +756,7 @@ void _socket_onRead(uv_stream_t* stream, ssize_t readSize, const uv_buf_t* buffe char buffer[8192]; if (tf_tls_session_get_error(socket->_tls, buffer, sizeof(buffer))) { - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, buffer)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, "%s", buffer)); } else { @@ -935,7 +923,7 @@ JSValue _socket_write(JSContext* context, JSValueConst this_val, int argc, JSVal char buffer[8192]; if (result <= 0 && tf_tls_session_get_error(socket->_tls, buffer, sizeof(buffer))) { - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, buffer)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, "%s", buffer)); } else if (result < length) { @@ -954,9 +942,7 @@ JSValue _socket_write(JSContext* context, JSValueConst this_val, int argc, JSVal if (result != 0) { - char error[256]; - snprintf(error, sizeof(error), "uv_write: %s", uv_strerror(result)); - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, error)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(context, "uv_write: %s", uv_strerror(result))); } } } @@ -979,9 +965,7 @@ void _socket_onWrite(uv_write_t* request, int status) } else { - char error[256]; - snprintf(error, sizeof(error), "uv_write: %s", uv_strerror(status)); - tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(tf_task_get_context(socket->_task), error)); + tf_task_reject_promise(socket->_task, promise, JS_ThrowInternalError(tf_task_get_context(socket->_task), "uv_write: %s", uv_strerror(status))); } } tf_free(request); diff --git a/src/ssb.js.c b/src/ssb.js.c index 25d5c7b9..4905ded4 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -682,8 +682,8 @@ void tf_ssb_run_file(JSContext* context, const char* file_name) long file_size = ftell(file); fseek(file, 0, SEEK_SET); source = tf_malloc(file_size + 1); - fread(source, 1, file_size, file); - source[file_size] = '\0'; + int bytes_read = fread(source, 1, file_size, file); + source[bytes_read] = '\0'; fclose(file); JSValue result = JS_Eval(context, source, file_size, file_name, 0); diff --git a/src/task.c b/src/task.c index 7752c85a..5952784e 100644 --- a/src/task.c +++ b/src/task.c @@ -294,8 +294,8 @@ static const char* _task_loadFile(const char* fileName) long fileSize = ftell(file); fseek(file, 0, SEEK_SET); result = tf_malloc(fileSize + 1); - fread(result, 1, fileSize, file); - result[fileSize] = '\0'; + int bytes_read = fread(result, 1, fileSize, file); + result[bytes_read] = '\0'; fclose(file); } return result; @@ -703,11 +703,6 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int JS_SetPropertyStr(context, result, "tls_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_tls_malloc_size() / total_memory)); JS_SetPropertyStr(context, result, "tf_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_tf_malloc_size() / total_memory)); -#if !defined(_WIN32) - struct mallinfo mi = mallinfo(); - JS_SetPropertyStr(context, result, "arena_percent", JS_NewFloat64(context, 100.0f * mi.arena / total_memory)); -#endif - JS_SetPropertyStr(context, result, "socket_count", JS_NewInt32(context, tf_socket_get_count())); JS_SetPropertyStr(context, result, "socket_open_count", JS_NewInt32(context, tf_socket_get_open_count()));