summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadek Kaczorowski <kaczor72@gmail.com>2021-10-05 04:04:24 +0200
committerGitHub <noreply@github.com>2021-10-05 11:04:24 +0900
commitcc4d1e04fe4a8b57b137c347ad9fd66166b6250a (patch)
tree2d5cb2e61c3c736e38a16ef70545b69fcc249cf7
parent3b339d73aec2a23d45f35b84f2097d63b868dd96 (diff)
downloadDLT-daemon-cc4d1e04fe4a8b57b137c347ad9fd66166b6250a.tar.gz
fix malformed printf format strings (#295)
Co-authored-by: Saya Sugiura <39760799+ssugiura@users.noreply.github.com>
-rw-r--r--include/dlt/dlt_common.h68
-rw-r--r--src/console/dlt-sortbytimestamp.c1
-rw-r--r--src/console/logstorage/dlt-logstorage-ctrl.c6
-rw-r--r--src/daemon/dlt-daemon.c62
-rw-r--r--src/daemon/dlt_daemon_client.c4
-rw-r--r--src/daemon/dlt_daemon_connection.c2
-rw-r--r--src/daemon/dlt_daemon_event_handler.c10
-rw-r--r--src/lib/dlt_user.c18
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c8
-rw-r--r--src/shared/dlt_common.c78
10 files changed, 123 insertions, 134 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index 9704ac9..f89cb1b 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -242,13 +242,9 @@ enum {
# define __func__ __FUNCTION__
# endif
-# define PRINT_FUNCTION_VERBOSE(_verbose) \
- { \
- if (_verbose) \
- { \
- dlt_vlog(LOG_INFO, "%s()\n", __func__); \
- } \
- }
+# define PRINT_FUNCTION_VERBOSE(_verbose) \
+ if (_verbose) \
+ dlt_vlog(LOG_INFO, "%s()\n", __func__)
# ifndef NULL
# define NULL (char *)0
@@ -299,44 +295,44 @@ enum {
# define DLT_FILTER_MAX 30 /**< Maximum number of filters */
# define DLT_MSG_READ_VALUE(dst, src, length, type) \
- { \
+ do { \
if ((length < 0) || ((length) < ((int32_t)sizeof(type)))) \
{ length = -1; } \
else \
{ dst = *((type *)src); src += sizeof(type); length -= sizeof(type); } \
- }
+ } while(0)
# define DLT_MSG_READ_ID(dst, src, length) \
- { \
+ do { \
if ((length < 0) || ((length) < DLT_ID_SIZE)) \
{ length = -1; } \
else \
{ memcpy(dst, src, DLT_ID_SIZE); src += DLT_ID_SIZE; length -= DLT_ID_SIZE; } \
- }
-
-#define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \
-{ \
- if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) \
- { \
- maxlength = -1; \
- } \
- else \
- { \
- memcpy(dst, src, length); \
- dlt_clean_string(dst, length); \
- dst[length] = 0; \
- src += length; \
- maxlength -= length; \
- } \
-}
+ } while(0)
+
+# define DLT_MSG_READ_STRING(dst, src, maxlength, dstlength, length) \
+ do { \
+ if ((maxlength < 0) || (length <= 0) || (dstlength < length) || (maxlength < length)) \
+ { \
+ maxlength = -1; \
+ } \
+ else \
+ { \
+ memcpy(dst, src, length); \
+ dlt_clean_string(dst, length); \
+ dst[length] = 0; \
+ src += length; \
+ maxlength -= length; \
+ } \
+ } while(0)
# define DLT_MSG_READ_NULL(src, maxlength, length) \
- { \
+ do { \
if (((maxlength) < 0) || ((length) < 0) || ((maxlength) < (length))) \
{ length = -1; } \
else \
{ src += length; maxlength -= length; } \
- }
+ } while(0)
# define DLT_HEADER_SHOW_NONE 0x0000
# define DLT_HEADER_SHOW_TIME 0x0001
@@ -756,8 +752,8 @@ typedef struct sDltFile
int32_t counter; /**< number of messages in DLT file with filter */
int32_t counter_total; /**< number of messages in DLT file without filter */
int32_t position; /**< current index to message parsed in DLT file starting at 0 */
- long file_length; /**< length of the file */
- long file_position; /**< current position in the file */
+ uint64_t file_length; /**< length of the file */
+ uint64_t file_position; /**< current position in the file */
/* error counters */
int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
@@ -878,7 +874,7 @@ DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr,
* This function returns zero if @a str is a null pointer,
* and it returns @a maxsize if the null character was not found in the first @a maxsize bytes of @a str.
* This is a re-implementation of C11's strnlen_s, which we cannot yet assume to be available.
- * @param text pointer to string whose length is to be determined
+ * @param str pointer to string whose length is to be determined
* @param maxsize maximal considered length of @a str
* @return the bounded length of the string
*/
@@ -1205,7 +1201,7 @@ void dlt_log_init(int mode);
* @param format format string for message
* @return negative value if there was an error or the total number of characters written is returned on success
*/
-int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1,2);
+int dlt_user_printf(const char *format, ...) PRINTF_FORMAT(1, 2);
/**
* Log ASCII string with null-termination to (external) logging facility
* @param prio priority (see syslog() call)
@@ -1219,7 +1215,7 @@ DltReturnValue dlt_log(int prio, char *s);
* @param format format string for log message
* @return negative value if there was an error
*/
-DltReturnValue dlt_vlog(int prio, const char *format, ...);
+DltReturnValue dlt_vlog(int prio, const char *format, ...) PRINTF_FORMAT(2, 3);
/**
* Log size bytes with variable arguments to (external) logging facility (similar to snprintf)
* @param prio priority (see syslog() call)
@@ -1227,7 +1223,7 @@ DltReturnValue dlt_vlog(int prio, const char *format, ...);
* @param format format string for log message
* @return negative value if there was an error
*/
-DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...);
+DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...) PRINTF_FORMAT(3, 4);
/**
* De-Initialize (external) logging facility
*/
@@ -1595,7 +1591,7 @@ DltReturnValue dlt_message_argument_print(DltMessage *msg,
/**
* Check environment variables.
*/
-void dlt_check_envvar();
+void dlt_check_envvar(void);
/**
* Parse the response text and identifying service id and its options.
diff --git a/src/console/dlt-sortbytimestamp.c b/src/console/dlt-sortbytimestamp.c
index 5b99318..3e418e1 100644
--- a/src/console/dlt-sortbytimestamp.c
+++ b/src/console/dlt-sortbytimestamp.c
@@ -88,6 +88,7 @@ int verbosity = 0;
/**
* Print information, conditional upon requested verbosity level
*/
+void verbose(int level, char *msg, ...) PRINTF_FORMAT(2, 3);
void verbose(int level, char *msg, ...) {
if (level <= verbosity) {
if (verbosity > 1) { /* timestamp */
diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c
index 858331b..cd0e040 100644
--- a/src/console/logstorage/dlt-logstorage-ctrl.c
+++ b/src/console/logstorage/dlt-logstorage-ctrl.c
@@ -166,17 +166,17 @@ static int analyze_response(char *data, void *payload, int len)
snprintf(resp_ok,
MAX_RESPONSE_LENGTH,
- "service(%u), ok",
+ "service(%d), ok",
DLT_SERVICE_ID_OFFLINE_LOGSTORAGE);
snprintf(resp_warning,
MAX_RESPONSE_LENGTH,
- "service(%u), warning",
+ "service(%d), warning",
DLT_SERVICE_ID_OFFLINE_LOGSTORAGE);
snprintf(resp_perm_denied,
MAX_RESPONSE_LENGTH,
- "service(%u), perm_denied",
+ "service(%d), perm_denied",
DLT_SERVICE_ID_OFFLINE_LOGSTORAGE);
if (strncmp(data, resp_ok, strlen(resp_ok)) == 0)
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 350e594..c09a809 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -289,7 +289,7 @@ int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
- fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
+ fprintf (stderr, "Unknown option character `\\x%x'.\n", (uint32_t)optopt);
/* unknown or wrong option used, show usage information and terminate */
usage();
@@ -376,7 +376,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineLogstorageCacheSize);
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
- sizeof(daemon_local->flags.ctrlSockPath) - 1);
+ sizeof(daemon_local->flags.ctrlSockPath));
#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
snprintf(daemon_local->flags.appSockPath, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH);
@@ -390,7 +390,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.gatewayMode = 0;
strncpy(daemon_local->flags.gatewayConfigFile,
DLT_GATEWAY_CONFIG_PATH,
- DLT_DAEMON_FLAG_MAX - 1);
+ DLT_DAEMON_FLAG_MAX);
daemon_local->flags.autoResponseGetLogInfoOption = 7;
daemon_local->flags.contextLogLevel = DLT_LOG_INFO;
daemon_local->flags.contextTraceStatus = DLT_TRACE_STATUS_OFF;
@@ -2270,7 +2270,7 @@ int dlt_daemon_process_app_connect(
}
/* check if file file descriptor was already used, and make it invalid if it
- * is reused. This prevents sending messages to wrong file descriptor */
+ * is reused. This prevents sending messages to wrong file descriptor */
dlt_daemon_applications_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
dlt_daemon_contexts_invalidate_fd(daemon, daemon->ecuid, in_sock, verbose);
@@ -2370,7 +2370,7 @@ static int dlt_daemon_process_user_message_not_sup(DltDaemon *daemon,
PRINT_FUNCTION_VERBOSE(verbose);
- dlt_vlog(LOG_ERR, "Invalid user message type received: %d!\n",
+ dlt_vlog(LOG_ERR, "Invalid user message type received: %u!\n",
userheader->message);
/* remove user header */
@@ -2701,7 +2701,7 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
len = userctxt.description_length;
if (len > DLT_DAEMON_DESCSIZE) {
- dlt_vlog(LOG_WARNING, "Context description exceeds limit: %d\n", len);
+ dlt_vlog(LOG_WARNING, "Context description exceeds limit: %u\n", len);
len = DLT_DAEMON_DESCSIZE;
}
@@ -2746,22 +2746,26 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
}
/* Set log level */
- if (userctxt.log_level == DLT_USER_LOG_LEVEL_NOT_SET)
+ if (userctxt.log_level == DLT_USER_LOG_LEVEL_NOT_SET) {
userctxt.log_level = DLT_LOG_DEFAULT;
- else
- /* Plausibility check */
- if ((userctxt.log_level < DLT_LOG_DEFAULT) ||
- (userctxt.log_level > DLT_LOG_VERBOSE))
- return -1;
+ } else {
+ /* Plausibility check */
+ if ((userctxt.log_level < DLT_LOG_DEFAULT) ||
+ (userctxt.log_level > DLT_LOG_VERBOSE)) {
+ return -1;
+ }
+ }
/* Set trace status */
- if (userctxt.trace_status == DLT_USER_TRACE_STATUS_NOT_SET)
+ if (userctxt.trace_status == DLT_USER_TRACE_STATUS_NOT_SET) {
userctxt.trace_status = DLT_TRACE_STATUS_DEFAULT;
- else
- /* Plausibility check */
- if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) ||
- (userctxt.trace_status > DLT_TRACE_STATUS_ON))
- return -1;
+ } else {
+ /* Plausibility check */
+ if ((userctxt.trace_status < DLT_TRACE_STATUS_DEFAULT) ||
+ (userctxt.trace_status > DLT_TRACE_STATUS_ON)) {
+ return -1;
+ }
+ }
context = dlt_daemon_context_add(daemon,
userctxt.apid,
@@ -3331,37 +3335,37 @@ static void *timer_thread(void *data)
int pexit = 0;
unsigned int sleep_ret = 0;
- DltDaemonPeriodicData* timer_data = (DltDaemonPeriodicData*) data;
+ DltDaemonPeriodicData* timer_thread_data = (DltDaemonPeriodicData*) data;
/* Timer will start in starts_in sec*/
- if ((sleep_ret = sleep(timer_data->starts_in))) {
+ if ((sleep_ret = sleep(timer_thread_data->starts_in))) {
dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for starting!"
"Stop thread of timer [%d]\n",
- sleep_ret, timer_data->timer_id);
- close_pipes(dlt_timer_pipes[timer_data->timer_id]);
+ sleep_ret, timer_thread_data->timer_id);
+ close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]);
return NULL;
}
while (1) {
- if (0 > write(dlt_timer_pipes[timer_data->timer_id][1], "1", 1)) {
+ if (0 > write(dlt_timer_pipes[timer_thread_data->timer_id][1], "1", 1)) {
dlt_vlog(LOG_ERR, "Failed to send notification for timer [%s]!\n",
- dlt_timer_names[timer_data->timer_id]);
+ dlt_timer_names[timer_thread_data->timer_id]);
pexit = 1;
}
if (pexit || g_exit) {
dlt_vlog(LOG_NOTICE, "Received signal!"
"Stop thread of timer [%d]\n",
- timer_data->timer_id);
- close_pipes(dlt_timer_pipes[timer_data->timer_id]);
+ timer_thread_data->timer_id);
+ close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]);
return NULL;
}
- if ((sleep_ret = sleep(timer_data->period_sec))) {
+ if ((sleep_ret = sleep(timer_thread_data->period_sec))) {
dlt_vlog(LOG_NOTICE, "Sleep remains [%u] for interval!"
"Stop thread of timer [%d]\n",
- sleep_ret, timer_data->timer_id);
- close_pipes(dlt_timer_pipes[timer_data->timer_id]);
+ sleep_ret, timer_thread_data->timer_id);
+ close_pipes(dlt_timer_pipes[timer_thread_data->timer_id]);
return NULL;
}
}
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index 2724973..becd061 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -1028,7 +1028,7 @@ void dlt_daemon_control_get_log_info(int sock,
if (verbose)
dlt_vlog(LOG_DEBUG,
- "Allocate %d bytes for response msg databuffer\n",
+ "Allocate %u bytes for response msg databuffer\n",
resp.datasize);
/* Allocate buffer for response message */
@@ -2587,7 +2587,7 @@ void dlt_daemon_control_service_logstorage(int sock,
/* Check for cache synchronization request from log storage ctrl app */
else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES)
{
- int ret = 0;
+ ret = 0;
if (device_index == -1) { /* sync all Logstorage devices */
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index a438c03..805afed 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -396,7 +396,7 @@ int dlt_connection_create(DltDaemonLocal *daemon_local,
temp->receiver = dlt_connection_get_receiver(daemon_local, type, fd);
if (!temp->receiver) {
- dlt_vlog(LOG_CRIT, "Unable to get receiver from %d connection.\n",
+ dlt_vlog(LOG_CRIT, "Unable to get receiver from %u connection.\n",
type);
free(temp);
return -1;
diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c
index 0d463da..db5767a 100644
--- a/src/daemon/dlt_daemon_event_handler.c
+++ b/src/daemon/dlt_daemon_event_handler.c
@@ -246,7 +246,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
callback = dlt_connection_get_callback(con);
if (!callback) {
- dlt_vlog(LOG_CRIT, "Unable to find function for %d handle type.\n",
+ dlt_vlog(LOG_CRIT, "Unable to find function for %u handle type.\n",
type);
return -1;
}
@@ -256,7 +256,7 @@ int dlt_daemon_handle_event(DltEventHandler *pEvent,
daemon_local,
con->receiver,
daemon_local->flags.vflag) == -1) {
- dlt_vlog(LOG_CRIT, "Processing from %d handle type failed!\n",
+ dlt_vlog(LOG_CRIT, "Processing from %u handle type failed!\n",
type);
return -1;
}
@@ -402,7 +402,7 @@ int dlt_connection_check_activate(DltEventHandler *evhdl,
case ACTIVE:
if (activation_type == DEACTIVATE) {
- dlt_vlog(LOG_INFO, "Deactivate connection type: %d\n", con->type);
+ dlt_vlog(LOG_INFO, "Deactivate connection type: %u\n", con->type);
dlt_event_handler_disable_fd(evhdl, con->receiver->fd);
@@ -416,7 +416,7 @@ int dlt_connection_check_activate(DltEventHandler *evhdl,
case INACTIVE:
if (activation_type == ACTIVATE) {
- dlt_vlog(LOG_INFO, "Activate connection type: %d\n", con->type);
+ dlt_vlog(LOG_INFO, "Activate connection type: %u\n", con->type);
dlt_event_handler_enable_fd(evhdl,
con->receiver->fd,
@@ -427,7 +427,7 @@ int dlt_connection_check_activate(DltEventHandler *evhdl,
break;
default:
- dlt_vlog(LOG_ERR, "Unknown connection status: %d\n", con->status);
+ dlt_vlog(LOG_ERR, "Unknown connection status: %u\n", con->status);
return -1;
}
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 3525ce9..778ea8f 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -783,7 +783,7 @@ DltReturnValue dlt_init_common(void)
else {
dlt_user.log_buf_len = (uint16_t) buffer_max_configured;
dlt_vlog(LOG_INFO,
- "Configured buffer size to [%d bytes]\n",
+ "Configured buffer size to [%u bytes]\n",
buffer_max_configured);
}
}
@@ -1001,7 +1001,7 @@ DltReturnValue dlt_free(void)
* If read fails, time to close the socket then.
*/
dlt_vlog(LOG_DEBUG, "[%s] polling returns [%d] with revent [0x%x]."
- "There are something to read\n", __func__, ret, nfd[0].revents);
+ "There are something to read\n", __func__, ret, (unsigned int)nfd[0].revents);
bytes_read = read(dlt_user.dlt_log_handle, dlt_user.resend_buffer, dlt_user.log_buf_len);
prev_errno = errno;
@@ -1010,7 +1010,7 @@ DltReturnValue dlt_free(void)
dlt_vlog(LOG_WARNING, "[%s] Failed to read with error [%s]\n",
__func__, strerror(prev_errno));
- if ((prev_errno == EAGAIN) || (prev_errno == EWOULDBLOCK))
+ if ((prev_errno == EAGAIN) || (EWOULDBLOCK != EAGAIN && prev_errno == EWOULDBLOCK))
continue;
else
break;
@@ -1018,7 +1018,7 @@ DltReturnValue dlt_free(void)
if (bytes_read >= 0) {
if (!bytes_read)
break;
- dlt_vlog(LOG_NOTICE, "[%s] data is still readable... [%d] bytes read\n",
+ dlt_vlog(LOG_NOTICE, "[%s] data is still readable... [%ld] bytes read\n",
__func__, bytes_read);
}
}
@@ -1794,7 +1794,7 @@ static DltReturnValue dlt_user_log_write_raw_internal(DltContextData *log, const
/* Have to cast type to signed type because some compilers assume that DltFormatType is unsigned and issue a warning */
if (((int16_t)type < DLT_FORMAT_DEFAULT) || (type >= DLT_FORMAT_MAX)) {
- dlt_vlog(LOG_ERR, "Format type %d is outside valid range", type);
+ dlt_vlog(LOG_ERR, "Format type %u is outside valid range", type);
return DLT_RETURN_WRONG_PARAMETER;
}
@@ -2725,7 +2725,7 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id,
return DLT_RETURN_WRONG_PARAMETER;
if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) {
- dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type);
+ dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type);
return DLT_RETURN_WRONG_PARAMETER;
}
@@ -2817,7 +2817,7 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id,
struct timespec ts;
if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) {
- dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type);
+ dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type);
return DLT_RETURN_WRONG_PARAMETER;
}
@@ -2895,7 +2895,7 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han
int ret = DLT_RETURN_ERROR;
if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) {
- dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type);
+ dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type);
return DLT_RETURN_WRONG_PARAMETER;
}
@@ -3162,7 +3162,7 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle,
return DLT_RETURN_WRONG_PARAMETER;
if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) {
- dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type);
+ dlt_vlog(LOG_ERR, "Network trace type %u is outside valid range", nw_trace_type);
return DLT_RETURN_WRONG_PARAMETER;
}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index 9c121e0..35d8306 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -491,7 +491,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
strcat(absolute_file_path, config->working_file_name);
dlt_vlog(LOG_DEBUG,
- "%s: Number of log files-newest file-wrap_id [%d]-[%s]-[%d]\n",
+ "%s: Number of log files-newest file-wrap_id [%u]-[%s]-[%u]\n",
__func__, num_log_files, config->working_file_name,
config->wrap_id);
@@ -542,14 +542,14 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
remove(absolute_file_path);
num_log_files -= 1;
dlt_vlog(LOG_DEBUG,
- "%s: Remove '%s' (num_log_files: %d, config->num_files:%d)\n",
+ "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n",
__func__, absolute_file_path, num_log_files, config->num_files);
}
config->log = fopen(absolute_file_path, "a+");
dlt_vlog(LOG_DEBUG,
- "%s: Filename and Index after updating [%s]-[%d]\n",
+ "%s: Filename and Index after updating [%s]-[%u]\n",
__func__, file_name, idx);
/* Add file to file list */
@@ -577,7 +577,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config,
strcat(absolute_file_path, storage_path);
strcat(absolute_file_path, (*head)->name);
dlt_vlog(LOG_DEBUG,
- "%s: Remove '%s' (num_log_files: %d, config->num_files:%d)\n",
+ "%s: Remove '%s' (num_log_files: %u, config->num_files:%u)\n",
__func__, absolute_file_path, num_log_files,
config->num_files);
remove(absolute_file_path);
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index c597468..4d7ad25 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -192,7 +192,7 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr,
for (lines = 0; lines < (size / DLT_COMMON_HEX_CHARS); lines++) {
int ret = 0;
/* Line number */
- ret = snprintf(text, DLT_COMMON_HEX_LINELEN + 1, "%.6x: ", lines * DLT_COMMON_HEX_CHARS);
+ ret = snprintf(text, DLT_COMMON_HEX_LINELEN + 1, "%.6x: ", (uint32_t)lines * DLT_COMMON_HEX_CHARS);
if ((ret < 0) || (ret >= (DLT_COMMON_HEX_LINELEN + 1)))
dlt_log(LOG_WARNING, "line was truncated\n");
@@ -230,7 +230,7 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr,
if (rest > 0) {
/* Line number */
int ret = 0;
- ret = snprintf(text, 9, "%.6x: ", (size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS);
+ ret = snprintf(text, 9, "%.6x: ", (uint32_t)(size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS);
if ((ret < 0) || (ret >= 9))
dlt_log(LOG_WARNING, "line number was truncated");
@@ -396,9 +396,8 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb
return DLT_RETURN_WRONG_PARAMETER;
FILE *handle;
- char str1[DLT_COMMON_BUFFER_LENGTH];
+ char str1[DLT_COMMON_BUFFER_LENGTH + 1];
char apid[DLT_ID_SIZE], ctid[DLT_ID_SIZE];
- char format[10];
PRINT_FUNCTION_VERBOSE(verbose);
@@ -409,7 +408,8 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb
return DLT_RETURN_ERROR;
}
- sprintf(format, "%c%ds", '%', DLT_COMMON_BUFFER_LENGTH-1);
+ #define FORMAT_STRING_(x) "%" #x "s"
+ #define FORMAT_STRING(x) FORMAT_STRING_(x)
/* Reset filters */
filter->counter = 0;
@@ -417,7 +417,7 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb
while (!feof(handle)) {
str1[0] = 0;
- if (fscanf(handle, format, str1) != 1)
+ if (fscanf(handle, FORMAT_STRING(DLT_COMMON_BUFFER_LENGTH), str1) != 1)
break;
if (str1[0] == 0)
@@ -432,7 +432,7 @@ DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verb
str1[0] = 0;
- if (fscanf(handle, format, str1) != 1)
+ if (fscanf(handle, FORMAT_STRING(DLT_COMMON_BUFFER_LENGTH), str1) != 1)
break;
if (str1[0] == 0)
@@ -1046,7 +1046,7 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int
/* check if verbose mode is on*/
if (verbose) {
- dlt_vlog(LOG_DEBUG, "BufferLength=%d, HeaderSize=%d, DataSize=%d\n",
+ dlt_vlog(LOG_DEBUG, "BufferLength=%u, HeaderSize=%u, DataSize=%u\n",
length, msg->headersize, msg->datasize);
}
@@ -1090,7 +1090,7 @@ int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int
if (msg->databuffer == NULL) {
dlt_vlog(LOG_WARNING,
- "Cannot allocate memory for payload buffer of size %d!\n",
+ "Cannot allocate memory for payload buffer of size %u!\n",
msg->datasize);
return DLT_MESSAGE_ERROR_UNKNOWN;
}
@@ -1261,7 +1261,7 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose)
/* check if verbose mode is on */
if (verbose) {
- dlt_vlog(LOG_DEBUG, "HeaderSize=%d, DataSize=%d\n",
+ dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n",
file->msg.headersize, file->msg.datasize);
}
@@ -1360,7 +1360,7 @@ DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose)
/* check if verbose mode is on */
if (verbose) {
- dlt_vlog(LOG_DEBUG, "HeaderSize=%d, DataSize=%d\n",
+ dlt_vlog(LOG_DEBUG, "HeaderSize=%u, DataSize=%u\n",
file->msg.headersize, file->msg.datasize);
}
@@ -1431,7 +1431,7 @@ DltReturnValue dlt_file_read_data(DltFile *file, int verbose)
if (file->msg.databuffer == NULL) {
dlt_vlog(LOG_WARNING,
- "Cannot allocate memory for payload buffer of size %d!\n",
+ "Cannot allocate memory for payload buffer of size %u!\n",
file->msg.datasize);
return DLT_RETURN_ERROR;
}
@@ -1440,7 +1440,7 @@ DltReturnValue dlt_file_read_data(DltFile *file, int verbose)
if (fread(file->msg.databuffer, file->msg.datasize, 1, file->handle) != 1) {
if (file->msg.datasize != 0) {
dlt_vlog(LOG_WARNING,
- "Cannot read payload data from file of size %d!\n",
+ "Cannot read payload data from file of size %u!\n",
file->msg.datasize);
return DLT_RETURN_ERROR;
}
@@ -1522,14 +1522,14 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose)
/* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
if (0 != fseek(file->handle, file->file_position, SEEK_SET)) {
- dlt_vlog(LOG_WARNING, "Seek failed to file_position %ld \n",
+ dlt_vlog(LOG_WARNING, "Seek failed to file_position %lu\n",
file->file_position);
return DLT_RETURN_ERROR;
}
/* get file position at start of DLT message */
if (verbose)
- dlt_vlog(LOG_INFO, "Position in file: %ld\n", file->file_position);
+ dlt_vlog(LOG_INFO, "Position in file: %lu\n", file->file_position);
/* read header */
if (dlt_file_read_header(file, verbose) < DLT_RETURN_OK) {
@@ -1563,7 +1563,7 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose)
if (fseek(file->handle, file->msg.datasize, SEEK_CUR) != 0) {
/* go back to last position in file */
dlt_vlog(LOG_WARNING,
- "Seek failed to skip payload data of size %d!\n",
+ "Seek failed to skip payload data of size %u!\n",
file->msg.datasize);
if (0 != fseek(file->handle, file->file_position, SEEK_SET))
@@ -1580,7 +1580,7 @@ DltReturnValue dlt_file_read(DltFile *file, int verbose)
SEEK_CUR)) {
dlt_vlog(LOG_WARNING,
- "Seek failed to skip extra header and payload data from file of size %d!\n",
+ "Seek failed to skip extra header and payload data from file of size %u!\n",
file->msg.headersize - (int32_t)sizeof(DltStorageHeader) -
(int32_t)sizeof(DltStandardHeader) + file->msg.datasize);
@@ -1640,7 +1640,7 @@ DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose)
/* get file position at start of DLT message */
if (verbose)
- dlt_vlog(LOG_DEBUG, "Position in file: %ld\n", file->file_position);
+ dlt_vlog(LOG_DEBUG, "Position in file: %lu\n", file->file_position);
/* read header */
if (dlt_file_read_header_raw(file, resync, verbose) < DLT_RETURN_OK) {
@@ -1860,7 +1860,7 @@ DltReturnValue dlt_log(int prio, char *s)
2][11] =
{ "EMERGENCY", "ALERT ", "CRITICAL ", "ERROR ", "WARNING ", "NOTICE ", "INFO ", "DEBUG ",
" " };
- static const char sFormatString[] = "[%5d.%06d]~DLT~%5d~%s~%s";
+ static const char sFormatString[] = "[%5u.%06u]~DLT~%5d~%s~%s";
struct timespec sTimeSpec;
if (s == NULL)
@@ -2262,17 +2262,6 @@ DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader)
? DLT_RETURN_TRUE : DLT_RETURN_OK;
}
-
-
-
-
-
-
-
-
-
-
-
DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
{
if ((buf == NULL) || (ptr == NULL))
@@ -2298,7 +2287,7 @@ DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char
memset(buf->mem, 0, buf->size);
dlt_vlog(LOG_DEBUG,
- "%s: Buffer: Size %d, Start address %lX\n",
+ "%s: Buffer: Size %u, Start address %lX\n",
__func__, buf->size, (unsigned long)buf->mem);
return DLT_RETURN_OK; /* OK */
@@ -2320,7 +2309,7 @@ DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char
buf->size = (uint32_t)(buf->min_size - sizeof(DltBufferHead));
dlt_vlog(LOG_DEBUG,
- "%s: Buffer: Size %d, Start address %lX\n",
+ "%s: Buffer: Size %u, Start address %lX\n",
__func__, buf->size, (unsigned long)buf->mem);
return DLT_RETURN_OK; /* OK */
@@ -2355,7 +2344,7 @@ DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32
if (buf->shm == NULL) {
dlt_vlog(LOG_EMERG,
- "%s: Buffer: Cannot allocate %d bytes\n",
+ "%s: Buffer: Cannot allocate %u bytes\n",
__func__, buf->min_size);
return DLT_RETURN_ERROR;
}
@@ -2377,7 +2366,7 @@ DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32
buf->size = (uint32_t) (buf->min_size - sizeof(DltBufferHead));
dlt_vlog(LOG_DEBUG,
- "%s: Buffer: Size %d, Start address %lX\n",
+ "%s: Buffer: Size %u, Start address %lX\n",
__func__, buf->size, (unsigned long)buf->mem);
/* clear memory */
@@ -2514,7 +2503,7 @@ int dlt_buffer_increase_size(DltBuffer *buf)
if (new_ptr == NULL) {
dlt_vlog(LOG_WARNING,
- "%s: Buffer: Cannot increase size because allocate %d bytes failed\n",
+ "%s: Buffer: Cannot increase size because allocate %u bytes failed\n",
__func__, buf->min_size);
return DLT_RETURN_ERROR;
}
@@ -2546,7 +2535,7 @@ int dlt_buffer_increase_size(DltBuffer *buf)
buf->size += buf->step_size;
dlt_vlog(LOG_DEBUG,
- "%s: Buffer: Size increased to %d bytes with start address %lX\n",
+ "%s: Buffer: Size increased to %u bytes with start address %lX\n",
__func__,
buf->size + (int32_t)sizeof(DltBufferHead),
(unsigned long)buf->mem);
@@ -2573,7 +2562,7 @@ int dlt_buffer_minimize_size(DltBuffer *buf)
if (new_ptr == NULL) {
dlt_vlog(LOG_WARNING,
- "%s: Buffer: Cannot set to min size of %d bytes\n",
+ "%s: Buffer: Cannot set to min size of %u bytes\n",
__func__, buf->min_size);
return DLT_RETURN_ERROR;
}
@@ -2592,7 +2581,7 @@ int dlt_buffer_minimize_size(DltBuffer *buf)
((int *)(buf->shm))[2] = 0; /* number of packets */
dlt_vlog(LOG_DEBUG,
- "%s: Buffer: Buffer minimized to Size %d bytes with start address %lX\n",
+ "%s: Buffer: Buffer minimized to Size %u bytes with start address %lX\n",
__func__, buf->size, (unsigned long)buf->mem);
/* clear memory */
@@ -2610,7 +2599,7 @@ int dlt_buffer_reset(DltBuffer *buf)
}
dlt_vlog(LOG_WARNING,
- "%s: Buffer: Buffer reset triggered. Size: %d, Start address: %lX\n",
+ "%s: Buffer: Buffer reset triggered. Size: %u, Start address: %lX\n",
__func__, buf->size, (unsigned long)buf->mem);
/* reset pointers and counters */
@@ -2659,7 +2648,7 @@ int dlt_buffer_push3(DltBuffer *buf,
/* check pointers */
if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size)) {
dlt_vlog(LOG_ERR,
- "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %d\n",
+ "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Size: %u\n",
__func__, read, write, buf->size);
dlt_buffer_reset(buf);
return DLT_RETURN_ERROR; /* ERROR */
@@ -2684,7 +2673,7 @@ int dlt_buffer_push3(DltBuffer *buf,
/* update pointers */
write = ((int *)(buf->shm))[0];
read = ((int *)(buf->shm))[1];
-
+
/* update free size */
if (read > write)
free_size = read - write;
@@ -2692,7 +2681,6 @@ int dlt_buffer_push3(DltBuffer *buf,
free_size = 0;
else
free_size = buf->size - write + read;
-
}
/* set header */
@@ -2746,7 +2734,7 @@ int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete
/* check pointers */
if (((unsigned int)read > buf->size) || ((unsigned int)write > buf->size) || (count < 0)) {
dlt_vlog(LOG_ERR,
- "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %d\n",
+ "%s: Buffer: Pointer out of range. Read: %d, Write: %d, Count: %d, Size: %u\n",
__func__, read, write, count, buf->size);
dlt_buffer_reset(buf);
return DLT_RETURN_ERROR; /* ERROR */
@@ -2865,7 +2853,7 @@ void dlt_buffer_info(DltBuffer *buf)
}
dlt_vlog(LOG_DEBUG,
- "Buffer: Available size: %d, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n",
+ "Buffer: Available size: %u, Buffer: Buffer full start address: %lX, Buffer: Buffer start address: %lX\n",
buf->size, (unsigned long)buf->shm, (unsigned long)buf->mem);
}
@@ -4161,7 +4149,7 @@ DltReturnValue dlt_file_quick_parsing(DltFile *file, const char *filename,
while (ret >= DLT_RETURN_OK && file->file_position < file->file_length) {
/* get file position at start of DLT message */
if (verbose)
- dlt_vlog(LOG_DEBUG, "Position in file: %ld\n", file->file_position);
+ dlt_vlog(LOG_DEBUG, "Position in file: %lu\n", file->file_position);
/* read all header and payload */
ret = dlt_file_read_header(file, verbose);