From 92f4639528518f80c87adb2ffaaafdc35765ecbd Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Wed, 29 Apr 2026 11:32:18 +0200 Subject: [PATCH] Fix FTBFS with gcc-16 and unused variables https://bugs.debian.org/1133458 (Closes: #1133458) Signed-off-by: Gianfranco Costamagna Signed-off-by: Gianfranco Costamagna --- doc/dlt_filetransfer.md | 2 +- include/dlt/dlt_common.h | 2 +- include/dlt/dlt_filetransfer.h | 6 +-- src/console/dlt-control-common.c | 2 +- src/console/dlt-control-v2.c | 6 +-- src/console/dlt-control.c | 4 +- src/console/logstorage/dlt-logstorage-ctrl.c | 2 +- src/console/logstorage/dlt-logstorage-udev.c | 2 +- src/daemon/dlt-daemon.c | 20 ++++---- src/daemon/dlt-daemon.h | 8 +-- src/daemon/dlt_daemon_client.c | 4 +- src/dbus/dlt-dbus-options.c | 4 +- src/dbus/dlt-dbus.c | 4 +- src/dbus/dlt-dbus.h | 2 +- src/examples/dlt-example-filetransfer.c | 4 +- src/gateway/dlt_gateway.c | 18 +++---- src/gateway/dlt_gateway_types.h | 8 +-- src/kpi/dlt-kpi-common.c | 16 +++--- src/kpi/dlt-kpi-common.h | 2 +- src/kpi/dlt-kpi-interrupt.c | 8 +-- src/kpi/dlt-kpi-options.c | 12 ++--- src/kpi/dlt-kpi-process.c | 18 +++---- src/kpi/dlt-kpi-process.h | 11 +++-- src/kpi/dlt-kpi.c | 52 +++++++++----------- src/kpi/dlt-kpi.h | 2 +- src/lib/dlt_filetransfer.c | 12 ++--- src/lib/dlt_user.c | 2 +- src/shared/dlt_common.c | 4 +- src/system/dlt-system-filetransfer.c | 38 +++++++------- src/system/dlt-system-journal.c | 2 +- src/system/dlt-system-logfile.c | 8 +-- src/system/dlt-system-options.c | 6 +-- src/system/dlt-system-process-handling.c | 4 +- src/system/dlt-system-processes.c | 2 +- src/system/dlt-system-syslog.c | 6 +-- src/system/dlt-system-watchdog.c | 16 +++--- src/system/dlt-system.h | 4 +- systemd/3rdparty/sd-daemon.c | 4 +- systemd/3rdparty/sd-daemon.h | 2 +- tests/gtest_dlt_common.cpp | 3 -- tests/gtest_dlt_daemon_gateway.cpp | 2 +- tests/gtest_dlt_daemon_offline_log.cpp | 2 +- 42 files changed, 163 insertions(+), 173 deletions(-) diff --git a/doc/dlt_filetransfer.md b/doc/dlt_filetransfer.md index 52593b418..20533103a 100644 --- a/doc/dlt_filetransfer.md +++ b/doc/dlt_filetransfer.md @@ -54,7 +54,7 @@ FLST | Package flag After the header package was sent, at least one or more data packages can be sent using: -` int dlt_user_log_file_data(DltContext *fileContext,const char *filename,int packageToTransfer, int timeout) ` +` int dlt_user_log_file_data(DltContext *fileContext,const char *filename,int packageToTransfer, unsigned int timeout) ` Data Data Package Protocol: diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 85cf5b74f..30d3ca706 100644 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -2308,7 +2308,7 @@ int dlt_execute_command(char *filename, char *command, ...); * @param filename Only file names without prepended path allowed. * @return pointer to extension */ -char *get_filename_ext(const char *filename); +const char *get_filename_ext(const char *filename); /** * Extract the base name of given file name (without the extension). diff --git a/include/dlt/dlt_filetransfer.h b/include/dlt/dlt_filetransfer.h index 577c71684..f5ee5eff2 100644 --- a/include/dlt/dlt_filetransfer.h +++ b/include/dlt/dlt_filetransfer.h @@ -70,7 +70,7 @@ * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, int timeout); +extern int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, unsigned int timeout); /* !This method gives information about the number of packages the file have */ @@ -126,7 +126,7 @@ extern int dlt_user_log_file_header(DltContext *fileContext, const char *filenam * @param fileCancelTransferFlag is a bool pointer to cancel the filetransfer on demand. For example in case of application shutdown event outstanding file transfer should abort and return * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_data_cancelable(DltContext *fileContext, const char *filename, int packageToTransfer, int timeout, bool *const fileCancelTransferFlag); +extern int dlt_user_log_file_data_cancelable(DltContext *fileContext, const char *filename, int packageToTransfer, unsigned int timeout, bool *const fileCancelTransferFlag); /* !Transfer the content data of a file. */ @@ -137,7 +137,7 @@ extern int dlt_user_log_file_data_cancelable(DltContext *fileContext, const char * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure value < 0 will be returned. */ -extern int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, int timeout); +extern int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, unsigned int timeout); diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 3e10e771a..5acb363c3 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -349,7 +349,7 @@ static int prepare_headers(DltMessage *msg, uint8_t *header) return -1; } - msg->standardheader->len = DLT_HTOBE_16(len); + msg->standardheader->len = DLT_HTOBE_16((uint16_t)len); return 0; } diff --git a/src/console/dlt-control-v2.c b/src/console/dlt-control-v2.c index e2fea73a6..ab1cd87e3 100644 --- a/src/console/dlt-control-v2.c +++ b/src/console/dlt-control-v2.c @@ -787,8 +787,8 @@ int main(int argc, char *argv[]) /*dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); */ /* Wait timeout */ - ts.tv_sec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(dltdata.tvalue * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(dltdata.tvalue * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); } else { ret = -1; @@ -934,4 +934,4 @@ int dlt_receive_message_callback_v2(DltMessageV2 *message, void *data) } return ret; -} \ No newline at end of file +} diff --git a/src/console/dlt-control.c b/src/console/dlt-control.c index 797c0aab2..658c78d44 100644 --- a/src/console/dlt-control.c +++ b/src/console/dlt-control.c @@ -754,8 +754,8 @@ int main(int argc, char *argv[]) /*dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag); */ /* Wait timeout */ - ts.tv_sec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (dltdata.tvalue * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(dltdata.tvalue * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(dltdata.tvalue * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); } else { ret = -1; diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c index 2b1b3afc6..def7a9898 100644 --- a/src/console/logstorage/dlt-logstorage-ctrl.c +++ b/src/console/logstorage/dlt-logstorage-ctrl.c @@ -545,7 +545,7 @@ static int parse_args(int argc, char *argv[]) } #if !defined(DLT_SYSTEMD_ENABLE) -int sd_notify(int unset_environment, const char *state) +int sd_notify(int unset_environment, char *state) { /* Satisfy Compiler for warnings */ (void)unset_environment; diff --git a/src/console/logstorage/dlt-logstorage-udev.c b/src/console/logstorage/dlt-logstorage-udev.c index e35474e19..35d5836d6 100644 --- a/src/console/logstorage/dlt-logstorage-udev.c +++ b/src/console/logstorage/dlt-logstorage-udev.c @@ -247,7 +247,7 @@ static int logstorage_udev_udevd_callback(void) * and/or for hot unplug (without unmount). */ ts.tv_sec = 0; - ts.tv_nsec = 500 * NANOSEC_PER_MILLISEC; + ts.tv_nsec = (long int) 500 * NANOSEC_PER_MILLISEC; nanosleep(&ts, NULL); ret = check_mountpoint_from_partition(EVENT_MOUNTED, partition); } diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index b3da31dd0..3956419f5 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1604,7 +1604,7 @@ int main(int argc, char *argv[]) { char *watchdogUSec = getenv("WATCHDOG_USEC"); // set a sensible default, in case the environment variable is not set - int watchdogTimeoutSeconds = 30; + unsigned int watchdogTimeoutSeconds = 30; dlt_log(LOG_DEBUG, "Systemd watchdog initialization\n"); @@ -1612,7 +1612,7 @@ int main(int argc, char *argv[]) // WATCHDOG_USEC is the timeout in micrsoseconds // divide this by 2*10^6 to get the interval in seconds // 2 * because we notify systemd after half the timeout - watchdogTimeoutSeconds = atoi(watchdogUSec) / 2000000; + watchdogTimeoutSeconds = (unsigned int)atoi(watchdogUSec) / 2000000; } if (watchdogTimeoutSeconds == 0) { @@ -2874,7 +2874,7 @@ int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, msg.datasize += (int32_t)uiSize; /* Calc length */ - msg.standardheader->len = DLT_HTOBE_16((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize); + msg.standardheader->len = DLT_HTOBE_16((uint16_t)((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize)); dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon,daemon_local, msg.headerbuffer, sizeof(DltStorageHeader), @@ -5660,8 +5660,8 @@ static void *timer_thread(void *data) #endif int create_timer_fd(DltDaemonLocal *daemon_local, - int period_sec, - int starts_in, + unsigned int period_sec, + unsigned int starts_in, DltTimers timer_id) { int local_fd = DLT_FD_INIT; @@ -5679,7 +5679,7 @@ int create_timer_fd(DltDaemonLocal *daemon_local, return -1; } - if ((period_sec <= 0) || (starts_in <= 0)) { + if ((period_sec == 0) || (starts_in == 0)) { /* timer not activated via the service file */ dlt_vlog(LOG_INFO, "<%s> not set: period=0\n", timer_name); local_fd = DLT_FD_INIT; @@ -5693,10 +5693,10 @@ int create_timer_fd(DltDaemonLocal *daemon_local, dlt_vlog(LOG_WARNING, "<%s> timerfd_create failed: %s\n", timer_name, strerror(errno)); - l_timer_spec.it_interval.tv_sec = period_sec; - l_timer_spec.it_interval.tv_nsec = 0; - l_timer_spec.it_value.tv_sec = starts_in; - l_timer_spec.it_value.tv_nsec = 0; + l_timer_spec.it_interval.tv_sec = (long int) period_sec; + l_timer_spec.it_interval.tv_nsec = (long int) 0; + l_timer_spec.it_value.tv_sec = (long int) starts_in; + l_timer_spec.it_value.tv_nsec = (long int) 0; if (timerfd_settime(local_fd, 0, &l_timer_spec, NULL) < 0) { dlt_vlog(LOG_WARNING, "<%s> timerfd_settime failed: %s\n", diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index ef4444555..c1e62fbfb 100644 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -190,8 +190,8 @@ typedef struct typedef struct { unsigned long long wakeups_missed; - int period_sec; - int starts_in; + unsigned int period_sec; + unsigned int starts_in; int timer_id; } DltDaemonPeriodicData; @@ -232,7 +232,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); int dlt_daemon_process_one_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); -int dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); +ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *recv, int verbose); #if defined DLT_DAEMON_USE_UNIX_SOCKET_IPC || defined DLT_DAEMON_VSOCK_IPC_ENABLE @@ -300,7 +300,7 @@ void dlt_daemon_ecu_version_thread(void *ptr); void dlt_daemon_systemd_watchdog_thread(void *ptr); #endif -int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, DltTimers timer); +int create_timer_fd(DltDaemonLocal *daemon_local, unsigned int period_sec, unsigned int starts_in, DltTimers timer); int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index 4d576f583..fe9e4bc8b 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -4678,7 +4678,7 @@ int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon, } #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE -int dlt_daemon_process_systemd_timer(DltDaemon *daemon, +ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose) @@ -4716,7 +4716,7 @@ int dlt_daemon_process_systemd_timer(DltDaemon *daemon, return 0; } #else -int dlt_daemon_process_systemd_timer(DltDaemon *daemon, +ssize_t dlt_daemon_process_systemd_timer(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose) diff --git a/src/dbus/dlt-dbus-options.c b/src/dbus/dlt-dbus-options.c index b2d8a7e23..419b9d8a0 100644 --- a/src/dbus/dlt-dbus-options.c +++ b/src/dbus/dlt-dbus-options.c @@ -167,8 +167,8 @@ int read_configuration_file(DltDBusConfiguration *config, char *file_name) filterEnd = strpbrk (line, "\r\n"); if (filterBegin) { - if (filterEnd && (filterEnd > filterBegin)) { - strncpy(filter, filterBegin + 1, filterEnd - filterBegin - 1); + if (filterEnd && (filterEnd - filterBegin - 1 >= 0)) { + strncpy(filter, filterBegin + 1, (long unsigned int) (filterEnd - filterBegin - 1)); filter[filterEnd - filterBegin - 1] = 0; } else { diff --git a/src/dbus/dlt-dbus.c b/src/dbus/dlt-dbus.c index b7cb8cade..d3e0d3d4f 100644 --- a/src/dbus/dlt-dbus.c +++ b/src/dbus/dlt-dbus.c @@ -57,7 +57,7 @@ filter_func (DBusConnection *con, return DBUS_HANDLER_RESULT_HANDLED; } - DLT_TRACE_NETWORK_SEGMENTED(dbusContext, DLT_NW_TRACE_IPC, 0, 0, len_p, (void *)*buf); + DLT_TRACE_NETWORK_SEGMENTED(dbusContext, DLT_NW_TRACE_IPC, 0, 0, (uint16_t)len_p, (void *)*buf); free(*buf); *buf = NULL; @@ -86,7 +86,7 @@ int main (int argc, char *argv[]) DBusError error; DBusBusType type; - int num; + unsigned int num; if (read_command_line(&options, argc, argv) < 0) { fprintf(stderr, "Failed to read command line!\n"); diff --git a/src/dbus/dlt-dbus.h b/src/dbus/dlt-dbus.h index 13b25e2f2..8c28b252c 100644 --- a/src/dbus/dlt-dbus.h +++ b/src/dbus/dlt-dbus.h @@ -53,7 +53,7 @@ typedef struct { typedef struct { char *ContextId; char *BusType; - int FilterCount; + unsigned int FilterCount; char *FilterMatch[DLT_DBUS_FILTER_MAX]; } DBusOptions; diff --git a/src/examples/dlt-example-filetransfer.c b/src/examples/dlt-example-filetransfer.c index 0290f9c03..c4af083fb 100644 --- a/src/examples/dlt-example-filetransfer.c +++ b/src/examples/dlt-example-filetransfer.c @@ -76,7 +76,7 @@ DLT_DECLARE_CONTEXT(fileContext) char *file = 0; -int timeout; +unsigned int timeout; int dflag = 0; bool shutdownStatus = false; @@ -229,7 +229,7 @@ int main(int argc, char *argv[]) } if (tvalue) - timeout = atoi(tvalue); + timeout = (unsigned int)atoi(tvalue); else timeout = TIMEOUT; diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c index d3aba52bb..219f360c9 100644 --- a/src/gateway/dlt_gateway.c +++ b/src/gateway/dlt_gateway.c @@ -220,7 +220,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_interval(DltGateway *gateway, return DLT_RETURN_WRONG_PARAMETER; } - gateway->interval = (int)strtol(value, NULL, 10); + gateway->interval = (unsigned int)strtol(value, NULL, 10); if (gateway->interval > 0) return DLT_RETURN_OK; @@ -322,7 +322,7 @@ DLT_STATIC DltReturnValue dlt_gateway_check_control_messages(DltGatewayConnectio con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT; con->p_control_msgs->type = CONTROL_MESSAGE_ON_STARTUP; con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED; - con->p_control_msgs->interval = -1; + con->p_control_msgs->interval = 0; if (head == NULL) head = con->p_control_msgs; @@ -398,9 +398,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( while (con->p_control_msgs != NULL) { if (con->p_control_msgs->id == id) { con->p_control_msgs->type = CONTROL_MESSAGE_BOTH; - con->p_control_msgs->interval = (int)strtol(p_rest, NULL, 10); + con->p_control_msgs->interval = (unsigned int)strtol(p_rest, NULL, 10); - if (con->p_control_msgs->interval <= 0) + if (con->p_control_msgs->interval == 0) dlt_vlog(LOG_WARNING, "%s interval is %d. It won't be send periodically.\n", dlt_get_service_name(con->p_control_msgs->id), @@ -435,9 +435,9 @@ DLT_STATIC DltReturnValue dlt_gateway_check_periodic_control_messages( con->p_control_msgs->user_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT; con->p_control_msgs->type = CONTROL_MESSAGE_PERIODIC; con->p_control_msgs->req = CONTROL_MESSAGE_NOT_REQUESTED; - con->p_control_msgs->interval = (int)strtol(p_rest, NULL, 10); + con->p_control_msgs->interval = (unsigned int)strtol(p_rest, NULL, 10); - if (con->p_control_msgs->interval <= 0) + if (con->p_control_msgs->interval == 0) dlt_vlog(LOG_WARNING, "%s interval is %d. It won't be send periodically.\n", dlt_get_service_name(con->p_control_msgs->id), @@ -907,7 +907,7 @@ DLT_STATIC int dlt_gateway_add_to_event_loop(DltDaemonLocal *daemon_local, int verbose) { DltPassiveControlMessage *control_msg = NULL; - int sendtime = 1; + unsigned int sendtime = 1; if ((daemon_local == NULL) || (con == NULL)) { dlt_vlog(LOG_ERR, "%s: wrong parameter\n", __func__); @@ -1782,7 +1782,7 @@ int dlt_gateway_send_control_message(DltGatewayConnection *con, /* check sendtime counter and message interval */ /* sendtime counter is 0 on startup, otherwise positive value */ if ((control_msg->type != CONTROL_MESSAGE_ON_DEMAND) && (con->sendtime_cnt > 0)) { - if (control_msg->interval <= 0) + if ((control_msg->interval) == 0) return DLT_RETURN_ERROR; if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || @@ -1861,7 +1861,7 @@ int dlt_gateway_send_control_message_v2(DltGatewayConnection *con, /* check sendtime counter and message interval */ /* sendtime counter is 0 on startup, otherwise positive value */ if ((control_msg->type != CONTROL_MESSAGE_ON_DEMAND) && (con->sendtime_cnt > 0)) { - if (control_msg->interval <= 0) + if (control_msg->interval == 0) return DLT_RETURN_ERROR; if ((control_msg->type == CONTROL_MESSAGE_PERIODIC) || diff --git a/src/gateway/dlt_gateway_types.h b/src/gateway/dlt_gateway_types.h index d468ffce9..addf0084c 100644 --- a/src/gateway/dlt_gateway_types.h +++ b/src/gateway/dlt_gateway_types.h @@ -107,7 +107,7 @@ typedef struct DltPassiveControlMessage { uint32_t user_id; control_msg_trigger type; /* on startup or periodic or both */ control_msg_request req; /* whether it is requested from gateway or not */ - int interval; /* interval for periodic sending. if on startup, -1 */ + unsigned int interval; /* interval for periodic sending. if on startup, -1 */ struct DltPassiveControlMessage *next; /* for multiple passive control message */ } DltPassiveControlMessage; @@ -127,8 +127,8 @@ typedef struct { int timeout; /* connection timeout */ int timeout_cnt; /* connection timeout counter */ int reconnect_cnt; /* reconnection counter */ - int sendtime; /* periodic sending max time */ - int sendtime_cnt; /* periodic sending counter */ + unsigned int sendtime; /* periodic sending max time */ + unsigned int sendtime_cnt; /* periodic sending counter */ DltPassiveControlMessage *p_control_msgs; /* passive control msgs */ DltPassiveControlMessage *head; /* to go back to the head pointer of p_control_msgs */ int send_serial; /* Send serial header with control messages */ @@ -142,7 +142,7 @@ typedef struct int send_serial; /* Default: Send serial header with control messages */ DltGatewayConnection *connections; /* pointer to connections */ int num_connections; /* number of connections */ - int interval; /* interval of retry connection */ + unsigned int interval; /* interval of retry connection */ } DltGateway; typedef struct { diff --git a/src/kpi/dlt-kpi-common.c b/src/kpi/dlt-kpi-common.c index d905c1079..e42557d7e 100644 --- a/src/kpi/dlt-kpi-common.c +++ b/src/kpi/dlt-kpi-common.c @@ -24,7 +24,7 @@ #include "dlt-kpi-common.h" -static int dlt_kpi_cpu_count = -1; +static long unsigned int dlt_kpi_cpu_count = 0; DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target) { @@ -62,7 +62,7 @@ DltReturnValue dlt_kpi_read_file(char *filename, char *buffer, uint maxLength) /* fprintf(stderr, "Could not read file %s\n", filename); */ return DLT_RETURN_ERROR; - int buflen = fread(buffer, 1, maxLength - 1, file); + size_t buflen = fread(buffer, 1, maxLength - 1, file); buffer[buflen] = '\0'; fclose(file); @@ -70,14 +70,14 @@ DltReturnValue dlt_kpi_read_file(char *filename, char *buffer, uint maxLength) return DLT_RETURN_OK; } -int dlt_kpi_read_cpu_count() +unsigned long int dlt_kpi_read_cpu_count() { char buffer[BUFFER_SIZE]; int ret = dlt_kpi_read_file("/proc/cpuinfo", buffer, sizeof(buffer)); if (ret != 0) { fprintf(stderr, "dlt_kpi_get_cpu_count(): Could not read /proc/cpuinfo\n"); - return -1; + return 0; } char *delim = "[] \t\n"; @@ -85,10 +85,10 @@ int dlt_kpi_read_cpu_count() if (tok == NULL) { fprintf(stderr, "dlt_kpi_get_cpu_count(): Could not extract token\n"); - return -1; + return 0; } - int num = 0; + unsigned long int num = 0; do { if (strcmp(tok, "processor") == 0) @@ -100,14 +100,14 @@ int dlt_kpi_read_cpu_count() return num; } -int dlt_kpi_get_cpu_count() +unsigned long int dlt_kpi_get_cpu_count() { if (dlt_kpi_cpu_count <= 0) { dlt_kpi_cpu_count = dlt_kpi_read_cpu_count(); if (dlt_kpi_cpu_count <= 0) { fprintf(stderr, "Could not get CPU count\n"); - dlt_kpi_cpu_count = -1; + dlt_kpi_cpu_count = 0; } } diff --git a/src/kpi/dlt-kpi-common.h b/src/kpi/dlt-kpi-common.h index 41bfa085a..79108b1ac 100644 --- a/src/kpi/dlt-kpi-common.h +++ b/src/kpi/dlt-kpi-common.h @@ -34,6 +34,6 @@ DltReturnValue dlt_kpi_read_file(char *filename, char *buffer, uint maxLength); DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target); -int dlt_kpi_get_cpu_count(); +unsigned long int dlt_kpi_get_cpu_count(); #endif /* SRC_KPI_DLT_KPI_COMMON_H_ */ diff --git a/src/kpi/dlt-kpi-interrupt.c b/src/kpi/dlt-kpi-interrupt.c index 19c9e37c5..0d699d515 100644 --- a/src/kpi/dlt-kpi-interrupt.c +++ b/src/kpi/dlt-kpi-interrupt.c @@ -61,7 +61,7 @@ DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level token = strtok(NULL, delim); } else { - int tokenlen = strlen(token); + int tokenlen = (int)strlen(token); if (token[tokenlen - 1] == ':') { column = 0; @@ -69,12 +69,12 @@ DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level if (first_row) first_row = 0; else - buffer_offset += snprintf(buffer + buffer_offset, BUFFER_SIZE - buffer_offset, "\n"); + buffer_offset += snprintf(buffer + buffer_offset, (long unsigned int)(BUFFER_SIZE - buffer_offset), "\n"); } if (column == 0) { /* IRQ number */ buffer_offset += snprintf(buffer + buffer_offset, - BUFFER_SIZE - buffer_offset, + (long unsigned int)(BUFFER_SIZE - buffer_offset), "%.*s;", tokenlen - 1, token); @@ -89,7 +89,7 @@ DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level } buffer_offset += snprintf(buffer + buffer_offset, - BUFFER_SIZE - buffer_offset, + (long unsigned int)(BUFFER_SIZE - buffer_offset), "cpu%d:%ld;", column - 1, interrupt_count); diff --git a/src/kpi/dlt-kpi-options.c b/src/kpi/dlt-kpi-options.c index 551097c1f..e3513a0e9 100644 --- a/src/kpi/dlt-kpi-options.c +++ b/src/kpi/dlt-kpi-options.c @@ -117,7 +117,7 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ char *token = NULL; char *value = NULL; char *pch, *strchk; - int tmp; + unsigned long int tmp; if ((config == NULL) || (file_name == NULL)) { fprintf(stderr, "%s: Nullpointer parameter!\n", __func__); @@ -170,7 +170,7 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ if ((token[0] != '\0') && (value[0] != '\0')) { if (strcmp(token, "process_interval") == '\0') { - tmp = strtol(value, &strchk, 10); + tmp = strtoul(value, &strchk, 10); if ((strchk[0] == '\0') && (tmp > 0)) config->process_log_interval = tmp; @@ -179,7 +179,7 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ } else if (strcmp(token, "irq_interval") == '\0') { - tmp = strtol(value, &strchk, 10); + tmp = strtoul(value, &strchk, 10); if ((strchk[0] == '\0') && (tmp > 0)) config->irq_log_interval = tmp; @@ -188,7 +188,7 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ } else if (strcmp(token, "check_interval") == '\0') { - tmp = strtol(value, &strchk, 10); + tmp = strtoul(value, &strchk, 10); if ((strchk[0] == '\0') && (tmp > 0)) config->check_log_interval = tmp; @@ -197,9 +197,9 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ } else if (strcmp(token, "log_level") == '\0') { - tmp = strtol(value, &strchk, 10); + tmp = strtoul(value, &strchk, 10); - if ((strchk[0] == '\0') && (tmp >= -1) && (tmp <= 6)) + if ((strchk[0] == '\0') && (tmp <= 6)) config->log_level = tmp; else fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token); diff --git a/src/kpi/dlt-kpi-process.c b/src/kpi/dlt-kpi-process.c index 751562f60..71bcd5d73 100644 --- a/src/kpi/dlt-kpi-process.c +++ b/src/kpi/dlt-kpi-process.c @@ -40,9 +40,9 @@ DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned l unsigned long int total_io_wait = dlt_kpi_read_process_stat_to_ulong(process->pid, 42); - int cpu_count = dlt_kpi_get_cpu_count(); + unsigned long int cpu_count = dlt_kpi_get_cpu_count(); - process->io_wait = (total_io_wait - process->last_io_wait) * 1000 / sysconf(_SC_CLK_TCK); /* busy milliseconds since last update */ + process->io_wait = (total_io_wait - process->last_io_wait) * 1000 / (long unsigned int)sysconf(_SC_CLK_TCK); /* busy milliseconds since last update */ if ((time_dif_ms > 0) && (cpu_count > 0)) process->io_wait = process->io_wait * 1000 / time_dif_ms / cpu_count; /* busy milliseconds per second per CPU */ @@ -62,12 +62,12 @@ DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned unsigned long int utime = dlt_kpi_read_process_stat_to_ulong(process->pid, 14); unsigned long int stime = dlt_kpi_read_process_stat_to_ulong(process->pid, 15); - unsigned long total_cpu_time = utime + stime; + unsigned long int total_cpu_time = utime + stime; if ((process->last_cpu_time > 0) && (process->last_cpu_time <= total_cpu_time)) { - int cpu_count = dlt_kpi_get_cpu_count(); + unsigned long int cpu_count = dlt_kpi_get_cpu_count(); - process->cpu_time = (total_cpu_time - process->last_cpu_time) * 1000 / sysconf(_SC_CLK_TCK); /* busy milliseconds since last update */ + process->cpu_time = (total_cpu_time - process->last_cpu_time) * 1000 / (long unsigned int)sysconf(_SC_CLK_TCK); /* busy milliseconds since last update */ if ((time_dif_ms > 0) && (cpu_count > 0)) process->cpu_time = process->cpu_time * 1000 / time_dif_ms / cpu_count; /* busy milliseconds per second per CPU */ @@ -418,7 +418,7 @@ DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer) return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen) +DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, size_t maxlen) { if ((process == NULL) || (buffer == NULL)) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); @@ -438,7 +438,7 @@ DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buff return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, int maxlen) +DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, size_t maxlen) { if ((process == NULL) || (buffer == NULL)) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); @@ -450,7 +450,7 @@ DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen) +DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, size_t maxlen) { if ((process == NULL) || (buffer == NULL)) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); @@ -462,7 +462,7 @@ DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen) +DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, size_t maxlen) { if ((process == NULL) || (buffer == NULL)) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); diff --git a/src/kpi/dlt-kpi-process.h b/src/kpi/dlt-kpi-process.h index bdc08fbfa..65b2813b5 100644 --- a/src/kpi/dlt-kpi-process.h +++ b/src/kpi/dlt-kpi-process.h @@ -36,7 +36,8 @@ typedef struct DltKpiProcess pid_t pid, ppid; char *command_line; unsigned long int cpu_time, last_cpu_time, io_wait, last_io_wait, io_bytes; - long int rss, ctx_switches; + unsigned long int rss; + long int ctx_switches; struct DltKpiProcess *next, *prev; } DltKpiProcess; @@ -46,9 +47,9 @@ DltKpiProcess *dlt_kpi_clone_process(DltKpiProcess *original); DltReturnValue dlt_kpi_free_process(DltKpiProcess *process); DltReturnValue dlt_kpi_print_process(DltKpiProcess *process); DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms); -DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, int maxlen); -DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen); -DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen); -DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen); +DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, size_t maxlen); +DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, size_t maxlen); +DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, size_t maxlen); +DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, size_t maxlen); #endif /* SRC_KPI_DLT_KPI_PROCESS_H_ */ diff --git a/src/kpi/dlt-kpi.c b/src/kpi/dlt-kpi.c index 84dfee28e..8d98e252c 100644 --- a/src/kpi/dlt-kpi.c +++ b/src/kpi/dlt-kpi.c @@ -54,7 +54,7 @@ DltReturnValue dlt_kpi_log_check_commandlines(); unsigned long int timespec_to_millis(struct timespec *time) { - return (time->tv_sec) * 1000 + (time->tv_nsec / 1000000); + return (long unsigned int)((time->tv_sec) * 1000 + (time->tv_nsec / 1000000)); } unsigned long int get_millis() @@ -195,13 +195,13 @@ DltReturnValue dlt_kpi_process_loop() dif_millis = get_millis() - old_millis; - if (dif_millis >= (unsigned long)(config.process_log_interval)) + if (dif_millis >= config.process_log_interval) sleep_millis = 0; else sleep_millis = config.process_log_interval - dif_millis; - ts.tv_sec = (sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); old_millis = get_millis(); @@ -210,20 +210,20 @@ DltReturnValue dlt_kpi_process_loop() return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, - DltReturnValue (*process_callback)(DltKpiProcess *, char *, int), +DltReturnValue dlt_kpi_log_list(DltKpiProcessList *p_list, + DltReturnValue (*process_callback)(DltKpiProcess *, char *, size_t), char *title, int delete_elements) { - if ((list == NULL) || (process_callback == NULL) || (title == NULL)) { + if ((p_list == NULL) || (process_callback == NULL) || (title == NULL)) { fprintf(stderr, "%s: Invalid Parameter (NULL)\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } - dlt_kpi_reset_cursor(list); + dlt_kpi_reset_cursor(p_list); - if (list->cursor == NULL) - return DLT_RETURN_OK; /* list empty; nothing to do */ + if (p_list->cursor == NULL) + return DLT_RETURN_OK; /* p_list empty; nothing to do */ /* Synchronization message */ DLT_LOG(kpi_ctx, config.log_level, DLT_STRING(title), DLT_STRING("BEG")); @@ -245,7 +245,7 @@ DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, } do { - if ((ret = (*process_callback)(list->cursor, buffer, sizeof(buffer) - 1)) < DLT_RETURN_OK) + if ((ret = (*process_callback)(p_list->cursor, buffer, sizeof(buffer) - 1)) < DLT_RETURN_OK) return ret; if ((ret = dlt_user_log_write_string(&data, buffer)) < DLT_RETURN_OK) { @@ -267,13 +267,13 @@ DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, } else if (delete_elements) { - if ((ret = dlt_kpi_remove_process_at_cursor(list)) < DLT_RETURN_OK) + if ((ret = dlt_kpi_remove_process_at_cursor(p_list)) < DLT_RETURN_OK) return ret; } else { - list->cursor = list->cursor->next; + p_list->cursor = p_list->cursor->next; } - } while (list->cursor != NULL); + } while (p_list->cursor != NULL); if ((ret = dlt_user_log_write_finish(&data)) < DLT_RETURN_OK) { fprintf(stderr, "%s: dlt_user_log_write_finish() returned error.\n", __func__); @@ -286,14 +286,14 @@ DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, return DLT_RETURN_OK; } -DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned long int time_dif_ms) +DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *p_list, unsigned long int time_dif_ms) { static char *strchk; static DltReturnValue tmp_ret; static struct dirent *current_dir; static pid_t current_dir_pid; - if (list == NULL) { + if (p_list == NULL) { fprintf(stderr, "dlt_kpi_update_process_list(): Nullpointer parameter"); return DLT_RETURN_WRONG_PARAMETER; } @@ -306,9 +306,7 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon } current_dir = readdir(proc_dir); - dlt_kpi_reset_cursor(list); - - int debug_process_count = 0; + dlt_kpi_reset_cursor(p_list); if (pthread_mutex_lock(&process_list_mutex) < 0) { fprintf(stderr, "Can't lock mutex\n"); @@ -331,7 +329,7 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon break; } - current_dir_pid = strtol(current_dir->d_name, &strchk, 10); + current_dir_pid = (pid_t)strtol(current_dir->d_name, &strchk, 10); if ((*strchk != '\0') || (current_dir_pid <= 0)) { /* no valid PID */ @@ -357,7 +355,6 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon return tmp_ret; current_dir = readdir(proc_dir); /* next process in proc-fs */ - debug_process_count++; } else if (current_dir_pid > list->cursor->pid) /* Process ended */ { @@ -387,7 +384,6 @@ DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned lon return tmp_ret; current_dir = readdir(proc_dir); /* next process in proc-fs */ - debug_process_count++; } } @@ -436,13 +432,13 @@ DltReturnValue dlt_kpi_irq_loop() dif_millis = get_millis() - old_millis; - if (dif_millis >= (unsigned long)(config.irq_log_interval)) + if (dif_millis >= config.irq_log_interval) sleep_millis = 0; else sleep_millis = config.irq_log_interval - dif_millis; - ts.tv_sec = (sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); old_millis = get_millis(); @@ -473,13 +469,13 @@ DltReturnValue dlt_kpi_check_loop() dif_millis = get_millis() - old_millis; - if (dif_millis >= (unsigned long)(config.check_log_interval)) + if (dif_millis >= config.check_log_interval) sleep_millis = 0; else sleep_millis = config.check_log_interval - dif_millis; - ts.tv_sec = (sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(sleep_millis * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); old_millis = get_millis(); diff --git a/src/kpi/dlt-kpi.h b/src/kpi/dlt-kpi.h index 2c802bd68..3c5622f33 100644 --- a/src/kpi/dlt-kpi.h +++ b/src/kpi/dlt-kpi.h @@ -50,7 +50,7 @@ typedef struct typedef struct { - int process_log_interval, irq_log_interval, check_log_interval; + unsigned long int process_log_interval, irq_log_interval, check_log_interval; DltLogLevelType log_level; } DltKpiConfig; diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 1bfa0e6e1..5b6d88884 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -203,11 +203,11 @@ int isFile (const char *file) /**Waits a period of time. The minimal time to wait is MIN_TIMEOUT. This makes sure that the FIFO of dlt is not flooded. * @param timeout Timeout to in ms but can not be smaller as MIN_TIMEOUT */ -void doTimeout(int timeout) +void doTimeout(unsigned int timeout) { struct timespec ts; - ts.tv_sec = (timeout * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; - ts.tv_nsec = (timeout * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + ts.tv_sec = (long int)(timeout * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (long int)(timeout * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; nanosleep(&ts, NULL); } @@ -369,7 +369,7 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, - int timeout) + unsigned int timeout) { if (!isFile(filename)) { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); @@ -576,7 +576,7 @@ int dlt_user_log_file_header(DltContext *fileContext, const char *filename) int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, - int timeout) + unsigned int timeout) { bool fileCancelTransferFlag = false; return dlt_user_log_file_data_cancelable(fileContext, filename, packageToTransfer, timeout, &fileCancelTransferFlag); @@ -594,7 +594,7 @@ int dlt_user_log_file_data(DltContext *fileContext, int dlt_user_log_file_data_cancelable(DltContext *fileContext, const char *filename, int packageToTransfer, - int timeout, + unsigned int timeout, bool *const fileCancelTransferFlag) { FILE *file; diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 31e9d3d51..477168220 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -5079,7 +5079,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int * return DLT_RETURN_ERROR; } len = (uint32_t)tmplen; - msg.standardheader->len = DLT_HTOBE_16(len); + msg.standardheader->len = DLT_HTOBE_16((uint16_t)len); /* print to std out, if enabled */ if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) && diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index f63d66df0..1b8472d52 100644 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -6483,14 +6483,14 @@ int dlt_execute_command(char *filename, char *command, ...) return ret; } -char *get_filename_ext(const char *filename) +const char *get_filename_ext(const char *filename) { if (filename == NULL) { fprintf(stderr, "ERROR: %s: invalid arguments\n", __func__); return ""; } - char *dot = strrchr(filename, '.'); + const char *dot = strrchr(filename, '.'); return (!dot || dot == filename) ? NULL : dot; } diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c index c082f226a..e7d1beb0d 100644 --- a/src/system/dlt-system-filetransfer.c +++ b/src/system/dlt-system-filetransfer.c @@ -105,14 +105,14 @@ char *unique_name(char *src) DLT_STRING("dlt-system-filetransfer, creating unique temporary file name.")); time_t t = time(NULL); int ok; - uint32_t l = getFileSerialNumber(src, &ok) ^ t; + uint32_t l = getFileSerialNumber(src, &ok) ^ (uint32_t)t; if (!ok) return (char *)NULL; char *basename_f = basename(src); /* Length of ULONG_MAX + 1 */ - int len = 11 + strlen(basename_f); + size_t len = 11 + strlen(basename_f); if (len > NAME_MAX) { DLT_LOG(dltsystem, DLT_LOG_WARN, @@ -155,7 +155,7 @@ void send_dumped_file(FiletransferOptions const *opts, char *dst_tosend) while ((total - used) < (total / 2)) { struct timespec t; t.tv_sec = 0; - t.tv_nsec = 1000000ul * opts->TimeoutBetweenLogs; + t.tv_nsec = (long int)(1000000ul * opts->TimeoutBetweenLogs); nanosleep(&t, NULL); dlt_user_log_resend_buffer(); dlt_user_check_buffer(&total, &used); @@ -220,7 +220,7 @@ int compress_file_to(char *src, char *dst, int level) MALLOC_ASSERT(buf); while (!feof(src_file)) { - int read = fread(buf, 1, Z_CHUNK_SZ, src_file); + size_t read = fread(buf, 1, Z_CHUNK_SZ, src_file); if (ferror(src_file)) { free(buf); @@ -230,7 +230,7 @@ int compress_file_to(char *src, char *dst, int level) return -1; } - gzwrite(dst_file, buf, read); + gzwrite(dst_file, buf, (unsigned int)read); } if (remove(src) < 0) @@ -290,7 +290,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which) char *dst_tocompress;/*file which is going to be compressed, the compressed one is named dst_tosend */ - int len = strlen(fdir) + strlen(SUBDIR_COMPRESS) + strlen(rn) + 3;/*the filename in .tocompress +2 for 2*"/", +1 for \0 */ + size_t len = strlen(fdir) + strlen(SUBDIR_COMPRESS) + strlen(rn) + 3;/*the filename in .tocompress +2 for 2*"/", +1 for \0 */ dst_tocompress = malloc(len); MALLOC_ASSERT(dst_tocompress); @@ -328,7 +328,7 @@ int send_one(char *src, FiletransferOptions const *opts, int which) /*move it directly into "tosend" */ DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, Moving file to tmp directory.")); - int len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + 3; + size_t len = strlen(fdir) + strlen(SUBDIR_TOSEND) + strlen(rn) + 3; dst_tosend = malloc(len);/*the resulting filename in .tosend +2 for 2*"/", +1 for \0 */ snprintf(dst_tosend, len, "%s/%s/%s", fdir, SUBDIR_TOSEND, rn); @@ -379,7 +379,7 @@ int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, co DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old compressed file found in send directory:"), DLT_STRING(dp->d_name)); - int len = strlen(send_dir) + strlen(dp->d_name) + 2; + size_t len = strlen(send_dir) + strlen(dp->d_name) + 2; fn = malloc(len); MALLOC_ASSERT(fn); snprintf(fn, len, "%s/%s", send_dir, dp->d_name); @@ -394,7 +394,7 @@ int flush_dir_send(FiletransferOptions const *opts, const char *compress_dir, co strncpy(tmp, dp->d_name, strlen(dp->d_name) - strlen(COMPRESS_EXTENSION)); tmp[strlen(dp->d_name) - strlen(COMPRESS_EXTENSION)] = '\0'; - int len = strlen(tmp) + strlen(compress_dir) + 1 + 1;/*2 sizes + 1*"/" + \0 */ + len = strlen(tmp) + strlen(compress_dir) + 1 + 1;/*2 sizes + 1*"/" + \0 */ char *path_uncompressed = malloc(len); MALLOC_ASSERT(path_uncompressed); snprintf(path_uncompressed, len, "%s/%s", compress_dir, tmp); @@ -475,7 +475,7 @@ int flush_dir_compress(FiletransferOptions const *opts, int which, const char *c /*compress file into to_send dir */ - int len = strlen(compress_dir) + strlen(dp->d_name) + 2; + size_t len = strlen(compress_dir) + strlen(dp->d_name) + 2; char *cd_filename = malloc(len); MALLOC_ASSERT(cd_filename); snprintf(cd_filename, len, "%s/%s", compress_dir, dp->d_name); @@ -526,7 +526,7 @@ int flush_dir_original(FiletransferOptions const *opts, int which) DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, old file found in directory.")); - int len = strlen(sdir) + strlen(dp->d_name) + 2; + size_t len = strlen(sdir) + strlen(dp->d_name) + 2; char *fn = malloc(len); MALLOC_ASSERT(fn); snprintf(fn, len, "%s/%s", sdir, dp->d_name); @@ -564,7 +564,7 @@ int flush_dir(FiletransferOptions const *opts, int which) char *compress_dir; char *send_dir; - int len = strlen(opts->Directory[which]) + strlen(SUBDIR_COMPRESS) + 2; + size_t len = strlen(opts->Directory[which]) + strlen(SUBDIR_COMPRESS) + 2; compress_dir = malloc (len); MALLOC_ASSERT(compress_dir); snprintf(compress_dir, len, "%s/%s", opts->Directory[which], SUBDIR_COMPRESS); @@ -625,7 +625,7 @@ int init_filetransfer_dirs(DltSystemConfiguration *config) /*create subdirectories for processing the files */ char *subdirpath; - int len = strlen(opts->Directory[i]) + strlen(SUBDIR_COMPRESS) + 2; + size_t len = strlen(opts->Directory[i]) + strlen(SUBDIR_COMPRESS) + 2; subdirpath = malloc (len); MALLOC_ASSERT(subdirpath); snprintf(subdirpath, len, "%s/%s", opts->Directory[i], SUBDIR_COMPRESS); @@ -697,9 +697,9 @@ int process_files(FiletransferOptions const *opts) return -1; } - unsigned int i = 0; + ssize_t i = 0; - while (i < (len - INOTIFY_SZ)) { + while (i < (len - (ssize_t)INOTIFY_SZ)) { struct inotify_event *ie = (struct inotify_event *)&buf[i]; if (ie->len > 0) { @@ -712,14 +712,14 @@ int process_files(FiletransferOptions const *opts) DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, found new file."), DLT_STRING(ie->name)); - int length = strlen(opts->Directory[j]) + ie->len + 1; + size_t length = strlen(opts->Directory[j]) + ie->len + 1 + 1; if (length > PATH_MAX) { DLT_LOG(filetransferContext, DLT_LOG_ERROR, DLT_STRING( "dlt-system-filetransfer: Very long path for file transfer. Cancelling transfer! Length is: "), - DLT_INT(length)); + DLT_INT((int)length)); return -1; } @@ -731,7 +731,7 @@ int process_files(FiletransferOptions const *opts) } } - i += INOTIFY_SZ + ie->len; + i += (ssize_t)(INOTIFY_SZ + ie->len); } #endif @@ -741,4 +741,4 @@ int process_files(FiletransferOptions const *opts) void filetransfer_fd_handler(DltSystemConfiguration *config) { process_files(&(config->Filetransfer)); -} \ No newline at end of file +} diff --git a/src/system/dlt-system-journal.c b/src/system/dlt-system-journal.c index 366555b61..d9dfbc4ba 100644 --- a/src/system/dlt-system-journal.c +++ b/src/system/dlt-system-journal.c @@ -393,7 +393,7 @@ void register_journal_fd(sd_journal **j, struct pollfd *pollfd, int i, DltSyste DLT_STRING(strerror(pollfd[i].fd))); j_tmp = NULL; } - pollfd[i].events = sd_journal_get_events(j_tmp); + pollfd[i].events = (short int)sd_journal_get_events(j_tmp); if(pollfd[i].events < 0) { DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while getting journal events: "), DLT_STRING(strerror(pollfd[i].events))); diff --git a/src/system/dlt-system-logfile.c b/src/system/dlt-system-logfile.c index 941a3be1e..6a488e41c 100644 --- a/src/system/dlt-system-logfile.c +++ b/src/system/dlt-system-logfile.c @@ -64,7 +64,7 @@ void send_file(LogFileOptions const *fileopt, int n) FILE *pFile; DltContext context = logfileContext[n]; char buffer[1024]; - int bytes; + size_t bytes; int seq = 1; pFile = fopen((*fileopt).Filename[n], "r"); @@ -72,11 +72,7 @@ void send_file(LogFileOptions const *fileopt, int n) if (pFile != NULL) { while (!feof(pFile)) { bytes = fread(buffer, 1, sizeof(buffer) - 1, pFile); - - if (bytes >= 0) - buffer[bytes] = 0; - else - buffer[0] = 0; + buffer[bytes] = 0; if (feof(pFile)) { DLT_LOG(context, DLT_LOG_INFO, DLT_INT(seq * -1), DLT_STRING(buffer)); diff --git a/src/system/dlt-system-options.c b/src/system/dlt-system-options.c index 406f4cd4e..c02b3d341 100644 --- a/src/system/dlt-system-options.c +++ b/src/system/dlt-system-options.c @@ -247,7 +247,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) /* Shell */ else if (strcmp(token, "ShellEnable") == 0) { - config->Shell.Enable = atoi(value); + config->Shell.Enable = (uint16_t)atoi(value); } /* Syslog */ @@ -261,7 +261,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) } else if (strcmp(token, "SyslogPort") == 0) { - config->Syslog.Port = atoi(value); + config->Syslog.Port = (uint16_t)atoi(value); } /* Journal */ @@ -309,7 +309,7 @@ int read_configuration_file(DltSystemConfiguration *config, char *file_name) } else if (strcmp(token, "FiletransferTimeoutBetweenLogs") == 0) { - config->Filetransfer.TimeoutBetweenLogs = atoi(value); + config->Filetransfer.TimeoutBetweenLogs = (unsigned int)atoi(value); } else if (strcmp(token, "FiletransferDirectory") == 0) { diff --git a/src/system/dlt-system-process-handling.c b/src/system/dlt-system-process-handling.c index 3e092d4e5..2122433e7 100644 --- a/src/system/dlt-system-process-handling.c +++ b/src/system/dlt-system-process-handling.c @@ -201,10 +201,10 @@ int register_timer_fd(struct pollfd *pollfd, int fdcnt) void timer_fd_handler(int fd, DltSystemConfiguration *config) { uint64_t timersElapsed = 0ULL; - int r = read(fd, &timersElapsed, 8U); // only needed to reset fd event + ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event if (r < 0) DLT_LOG(dltsystem, DLT_LOG_ERROR, DLT_STRING("Error while reading timer fd: "), - DLT_STRING(strerror(r))); + DLT_STRING(strerror((int)r))); if(config->LogProcesses.Enable) logprocess_fd_handler(config); diff --git a/src/system/dlt-system-processes.c b/src/system/dlt-system-processes.c index c35596c94..b17b8ee46 100644 --- a/src/system/dlt-system-processes.c +++ b/src/system/dlt-system-processes.c @@ -72,7 +72,7 @@ void send_process(LogProcessOptions const *popts, int n) struct dirent *dp; char filename[PATH_MAX]; char buffer[1024]; - int bytes; + size_t bytes; int found = 0; /* go through all process files in directory */ diff --git a/src/system/dlt-system-syslog.c b/src/system/dlt-system-syslog.c index 59e9d3ffd..37ab696cd 100644 --- a/src/system/dlt-system-syslog.c +++ b/src/system/dlt-system-syslog.c @@ -109,7 +109,7 @@ int init_socket(SyslogOptions opts) return sock; } -int read_socket(int sock) +ssize_t read_socket(int sock) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-syslog, read socket")); @@ -117,7 +117,7 @@ int read_socket(int sock) struct sockaddr_in client_addr; socklen_t addr_len = sizeof(struct sockaddr_in); - int bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0, + ssize_t bytes_read = recvfrom(sock, recv_data, RECV_BUF_SZ, 0, (struct sockaddr *)&client_addr, &addr_len); if (bytes_read == -1) { @@ -157,4 +157,4 @@ int register_syslog_fd(struct pollfd *pollfd, int i, DltSystemConfiguration *con void syslog_fd_handler(int syslogSock) { read_socket(syslogSock); -} \ No newline at end of file +} diff --git a/src/system/dlt-system-watchdog.c b/src/system/dlt-system-watchdog.c index 7ed160406..2761baba8 100644 --- a/src/system/dlt-system-watchdog.c +++ b/src/system/dlt-system-watchdog.c @@ -56,9 +56,9 @@ int calculate_period(struct itimerspec *itval) } DLT_LOG(watchdogContext, DLT_LOG_DEBUG, DLT_STRING("watchdogusec: "), DLT_STRING(watchdogUSec)); - watchdogTimeoutSeconds = atoi(watchdogUSec); + watchdogTimeoutSeconds = (unsigned int)atoi(watchdogUSec); - if (watchdogTimeoutSeconds <= 0) { + if (watchdogTimeoutSeconds == 0) { snprintf(str, 512, "systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds); DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING(str)); return -1; @@ -77,10 +77,10 @@ int calculate_period(struct itimerspec *itval) /* Make the timer periodic */ sec = notifiyPeriodNSec / 1000000; ns = (notifiyPeriodNSec - (sec * 1000000)) * 1000; - itval->it_interval.tv_sec = sec; - itval->it_interval.tv_nsec = ns; - itval->it_value.tv_sec = sec; - itval->it_value.tv_nsec = ns; + itval->it_interval.tv_sec = (long int)sec; + itval->it_interval.tv_nsec = (long int)ns; + itval->it_value.tv_sec = (long int)sec; + itval->it_value.tv_nsec = (long int)ns; return 0; } @@ -114,10 +114,10 @@ void watchdog_fd_handler(int fd) #endif { uint64_t timersElapsed = 0ULL; - int r = read(fd, &timersElapsed, 8U); // only needed to reset fd event + ssize_t r = read(fd, &timersElapsed, 8U); // only needed to reset fd event if(r < 0) DLT_LOG(watchdogContext, DLT_LOG_ERROR, DLT_STRING("Could not reset systemd watchdog. Exit with: "), - DLT_STRING(strerror(r))); + DLT_STRING(strerror((int)r))); #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE_DLT_SYSTEM if (!*received_message_since_last_watchdog_interval) { diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h index a94b950ca..c1d45e52d 100644 --- a/src/system/dlt-system.h +++ b/src/system/dlt-system.h @@ -115,7 +115,7 @@ typedef struct { typedef struct { int Enable; char ContextId[DLT_ID_SIZE]; - int Port; + uint16_t Port; } SyslogOptions; /* Configuration journal options */ @@ -136,7 +136,7 @@ typedef struct { int Enable; char ContextId[DLT_ID_SIZE]; int TimeStartup; - int TimeoutBetweenLogs; + unsigned int TimeoutBetweenLogs; /* Variable number of file transfer dirs */ int Count; diff --git a/systemd/3rdparty/sd-daemon.c b/systemd/3rdparty/sd-daemon.c index de3f98570..c0a7b31f3 100644 --- a/systemd/3rdparty/sd-daemon.c +++ b/systemd/3rdparty/sd-daemon.c @@ -419,7 +419,7 @@ _sd_export_ int sd_is_mq(int fd, const char *path) { #endif } -_sd_export_ int sd_notify(int unset_environment, const char *state) { +_sd_export_ int sd_notify(int unset_environment, char *state) { #if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC) return 0; #else @@ -461,7 +461,7 @@ _sd_export_ int sd_notify(int unset_environment, const char *state) { memset(&msghdr, 0, sizeof(msghdr)); msghdr.msg_name = &sockaddr; - msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e); + msghdr.msg_namelen = (socklen_t)(offsetof(struct sockaddr_un, sun_path) + strlen(e)); if (msghdr.msg_namelen > sizeof(struct sockaddr_un)) msghdr.msg_namelen = sizeof(struct sockaddr_un); diff --git a/systemd/3rdparty/sd-daemon.h b/systemd/3rdparty/sd-daemon.h index fe51159ee..a0870ad7b 100644 --- a/systemd/3rdparty/sd-daemon.h +++ b/systemd/3rdparty/sd-daemon.h @@ -238,7 +238,7 @@ int sd_is_mq(int fd, const char *path); See sd_notify(3) for more information. */ -int sd_notify(int unset_environment, const char *state); +int sd_notify(int unset_environment, char *state); /* Similar to sd_notify() but takes a format string. diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index b2135808f..3d9c6744b 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -1026,10 +1026,7 @@ TEST(t_dlt_buffer_write_block, normal) EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - int tmp = 0; - for (int i = 0; i <= 10000; i += 10) { - tmp += i; EXPECT_NO_THROW(dlt_buffer_write_block(&buf, &write, data, i)); } diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp index b4c24515a..a07723e22 100644 --- a/tests/gtest_dlt_daemon_gateway.cpp +++ b/tests/gtest_dlt_daemon_gateway.cpp @@ -553,7 +553,7 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp)); len = static_cast(msg.headersize - sizeof(DltStorageHeader) + msg.datasize); - msg.standardheader->len = DLT_HTOBE_16(len); + msg.standardheader->len = DLT_HTOBE_16((uint16_t)len); EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_parse_get_log_info(&daemon, ecuid, &msg, CONTROL_MESSAGE_NOT_REQUESTED, 0)); } diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index e95b311bc..9bbe01f62 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -1480,7 +1480,7 @@ TEST(t_dlt_logstorage_write_on_msg, gzip) DltNewestFileName newest_file_name; newest_file_name.file_name = const_cast("Test"); - newest_file_name.newest_file = (char *)"Test_003_20200728_191132.dlt.gz"; + newest_file_name.newest_file = const_cast("Test_003_20200728_191132.dlt.gz"); newest_file_name.wrap_id = 0; newest_file_name.next = NULL;