summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Herrmann <fherrmann@de.adit-jv.com>2020-01-13 10:40:25 +0100
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commit676e8fc1ba927dc84df82b508d796e31d9fd120c (patch)
tree141271d339f1ba68d0b29fd124e8eaa5d3d99fd4 /src
parentec391decd94ac9f6c6133c24a41c8afb2c01623f (diff)
downloadDLT-daemon-676e8fc1ba927dc84df82b508d796e31d9fd120c.tar.gz
fix some gcc9 compiler warnings
Many stringop-truncation and stringop-overflow warnings are still there (so many). https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
Diffstat (limited to 'src')
-rw-r--r--src/console/dlt-sortbytimestamp.c4
-rw-r--r--src/daemon/dlt-daemon.c22
-rw-r--r--src/daemon/dlt_daemon_common.c11
-rw-r--r--src/daemon/dlt_daemon_offline_logstorage.c14
-rw-r--r--src/lib/dlt_user.c61
-rw-r--r--src/offlinelogstorage/dlt_offline_logstorage_behavior.c22
-rw-r--r--src/shared/dlt_common.c7
-rw-r--r--src/shared/dlt_config_file_parser.c16
-rw-r--r--src/shared/dlt_offline_trace.c14
9 files changed, 92 insertions, 79 deletions
diff --git a/src/console/dlt-sortbytimestamp.c b/src/console/dlt-sortbytimestamp.c
index 71ad2a4..f840ef1 100644
--- a/src/console/dlt-sortbytimestamp.c
+++ b/src/console/dlt-sortbytimestamp.c
@@ -422,8 +422,8 @@ int main(int argc, char *argv[]) {
qsort((void *) timestamp_index, message_count, sizeof(TimestampIndex), compare_index_systime);
for (num = begin; num <= end; num++) {
- delta_tmsp = abs(timestamp_index[num + 1].tmsp - timestamp_index[num].tmsp);
- delta_systime = abs(timestamp_index[num + 1].systmsp - timestamp_index[num].systmsp);
+ delta_tmsp = (uint32_t)llabs((int64_t)timestamp_index[num + 1].tmsp - timestamp_index[num].tmsp);
+ delta_systime = (uint32_t)llabs((int64_t)timestamp_index[num + 1].systmsp - timestamp_index[num].systmsp);
/*
* Here is a try to detect a new cycle of boot in system.
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index ee8b929..fd46795 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -253,10 +253,14 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.offlineTraceFilenameTimestampBased = 1;
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
- snprintf(daemon_local->flags.loggingFilename,
- sizeof(daemon_local->flags.loggingFilename),
- "%s/dlt.log",
- dltFifoBaseDir);
+
+ if (snprintf(daemon_local->flags.loggingFilename,
+ sizeof(daemon_local->flags.loggingFilename),
+ "%s/dlt.log", dltFifoBaseDir) != 0) {
+ dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error %s\n", __func__,
+ daemon_local->flags.loggingFilename);
+ }
+
daemon_local->timeoutOnSend = 4;
daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE;
daemon_local->RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE;
@@ -1496,7 +1500,9 @@ void dlt_daemon_exit_trigger()
{
char tmp[DLT_PATH_MAX] = { 0 };
- snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
+ if (snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir) != 0) {
+ dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error %s\n", __func__, tmp);
+ }
(void)unlink(tmp);
/* stop event loop */
@@ -2346,7 +2352,8 @@ int dlt_daemon_process_user_message_register_application(DltDaemon *daemon,
if (dlt_receiver_check_and_get(rec, description, len, DLT_RCV_NONE) < 0) {
dlt_log(LOG_ERR, "Unable to get application description\n");
/* in case description was not readable, set dummy description */
- strncpy(description, "Unknown", sizeof("Unknown"));
+ memcpy(description, "Unknown", sizeof("Unknown"));
+
/* unknown len of original description, set to 0 to not remove in next
* step. Because message buffer is re-adjusted the corrupted description
* is ignored. */
@@ -2454,7 +2461,8 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon,
if (dlt_receiver_check_and_get(rec, description, len, DLT_RCV_NONE) < 0) {
dlt_log(LOG_ERR, "Unable to get context description\n");
/* in case description was not readable, set dummy description */
- strncpy(description, "Unknown", sizeof("Unknown"));
+ memcpy(description, "Unknown", sizeof("Unknown"));
+
/* unknown len of original description, set to 0 to not remove in next
* step. Because message buffer is re-adjusted the corrupted description
* is ignored. */
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 195c55f..d96d8f2 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -481,12 +481,8 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
application->application_description = malloc(strlen(description) + 1);
if (application->application_description) {
- strncpy(application->application_description,
- description,
- strlen(description));
- application->application_description[strlen(description)] = '\0';
- }
- else {
+ memcpy(application->application_description, description, strlen(description) + 1);
+ } else {
dlt_log(LOG_ERR, "Cannot allocate memory to store application description\n");
free(application);
return (DltDaemonApplication *)NULL;
@@ -874,8 +870,7 @@ DltDaemonContext *dlt_daemon_context_add(DltDaemon *daemon,
context->context_description = malloc(strlen(description) + 1);
if (context->context_description) {
- strncpy(context->context_description, description, strlen(description));
- context->context_description[strlen(description)] = '\0';
+ memcpy(context->context_description, description, strlen(description) + 1);
}
}
diff --git a/src/daemon/dlt_daemon_offline_logstorage.c b/src/daemon/dlt_daemon_offline_logstorage.c
index 4e9c6c6..0b3c14f 100644
--- a/src/daemon/dlt_daemon_offline_logstorage.c
+++ b/src/daemon/dlt_daemon_offline_logstorage.c
@@ -49,9 +49,9 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid(char *key,
if ((len > (DLT_ID_SIZE + 2)) || (len < 2))
return DLT_RETURN_ERROR;
- strncpy(ecuid, key, (len - 2));
- strncpy(apid, ".*", 2);
- strncpy(ctid, ".*", 2);
+ memcpy(ecuid, key, (len - 2));
+ memcpy(apid, ".*", 2);
+ memcpy(ctid, ".*", 2);
return DLT_RETURN_OK;
}
@@ -76,7 +76,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_ctid(char *key,
return DLT_RETURN_ERROR;
strncpy(ctid, (key + 2), (len - 1));
- strncpy(apid, ".*", 2);
+ memcpy(apid, ".*", 2);
return DLT_RETURN_OK;
}
@@ -101,7 +101,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_apid(char *key,
return DLT_RETURN_ERROR;
strncpy(apid, key + 1, (len - 2));
- strncpy(ctid, ".*", 2);
+ memcpy(ctid, ".*", 2);
return DLT_RETURN_OK;
}
@@ -183,7 +183,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char *key,
else
return DLT_RETURN_ERROR;
- strncpy(ctid, ".*", 2);
+ memcpy(ctid, ".*", 2);
return DLT_RETURN_OK;
}
@@ -227,7 +227,7 @@ DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char *key,
if (tok != NULL)
strncpy(ctid, tok, DLT_ID_SIZE);
- strncpy(apid, ".*", 2);
+ memcpy(apid, ".*", 2);
}
else {
strncpy(ecuid, tok, DLT_ID_SIZE);
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index be00a76..a879f95 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -1038,10 +1038,8 @@ DltReturnValue dlt_register_app(const char *apid, const char *description)
dlt_user.application_description = malloc(desc_len + 1);
if (dlt_user.application_description) {
- strncpy(dlt_user.application_description, description, desc_len);
- dlt_user.application_description[desc_len] = '\0';
- }
- else {
+ strncpy(dlt_user.application_description, description, desc_len + 1);
+ } else {
DLT_SEM_FREE();
return DLT_RETURN_ERROR;
}
@@ -1204,40 +1202,43 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle,
}
}
+ /* New context entry to be initialized */
+ dlt_ll_ts_type *ctx_entry;
+ ctx_entry = &dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries];
+
/* Store locally context id and context description */
- dlt_set_id(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].contextID, contextid);
+ dlt_set_id(ctx_entry->contextID, contextid);
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description != 0)
- free(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description);
+ if (ctx_entry->context_description != 0)
+ free(ctx_entry->context_description);
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = 0;
+ ctx_entry->context_description = 0;
if (description != 0) {
size_t desc_len = strlen(description);
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(desc_len + 1);
+ ctx_entry->context_description = malloc(desc_len + 1);
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description == 0) {
+ if (ctx_entry->context_description == 0) {
DLT_SEM_FREE();
return DLT_RETURN_ERROR;
}
- strncpy(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description, description, desc_len);
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len] = '\0';
+ strncpy(ctx_entry->context_description, description, desc_len + 1);
}
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) {
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t));
+ if (ctx_entry->log_level_ptr == 0) {
+ ctx_entry->log_level_ptr = malloc(sizeof(int8_t));
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0) {
+ if (ctx_entry->log_level_ptr == 0) {
DLT_SEM_FREE();
return DLT_RETURN_ERROR;
}
}
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) {
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t));
+ if (ctx_entry->trace_status_ptr == 0) {
+ ctx_entry->trace_status_ptr = malloc(sizeof(int8_t));
- if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0) {
+ if (ctx_entry->trace_status_ptr == 0) {
DLT_SEM_FREE();
return DLT_RETURN_ERROR;
}
@@ -1250,31 +1251,29 @@ DltReturnValue dlt_register_context_ll_ts_llccb(DltContext *handle,
DLT_USER_LOG_LEVEL_NOT_SET);
if (envLogLevel != DLT_USER_LOG_LEVEL_NOT_SET) {
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = envLogLevel;
+ ctx_entry->log_level = envLogLevel;
loglevel = envLogLevel;
}
else if (loglevel != DLT_USER_LOG_LEVEL_NOT_SET)
{
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel;
+ ctx_entry->log_level = loglevel;
}
if (tracestatus != DLT_USER_TRACE_STATUS_NOT_SET)
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
+ ctx_entry->trace_status = tracestatus;
/* Prepare transfer struct */
dlt_set_id(handle->contextID, contextid);
handle->log_level_pos = dlt_user.dlt_ll_ts_num_entries;
- handle->log_level_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr;
- handle->trace_status_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr;
+ handle->log_level_ptr = ctx_entry->log_level_ptr;
+ handle->trace_status_ptr = ctx_entry->trace_status_ptr;
- log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description;
+ log.context_description = ctx_entry->context_description;
- *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) =
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level;
- *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) =
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
- dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_changed_callback = dlt_log_level_changed_callback;
+ *(ctx_entry->log_level_ptr) = ctx_entry->log_level;
+ *(ctx_entry->trace_status_ptr) = ctx_entry->trace_status = tracestatus;
+ ctx_entry->log_level_changed_callback = dlt_log_level_changed_callback;
log.log_level = loglevel;
log.trace_status = tracestatus;
@@ -2588,7 +2587,7 @@ DltReturnValue dlt_register_injection_callback_with_id(DltContext *handle, uint3
dlt_user.dlt_ll_ts[i].injection_table[j].service_id = service_id;
if (priv == NULL) {
- dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = (dlt_injection_callback)dlt_injection_cbk;
+ dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = (dlt_injection_callback)(void*)dlt_injection_cbk;
dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback_with_id = NULL;
dlt_user.dlt_ll_ts[i].injection_table[j].data = NULL;
}
@@ -2610,7 +2609,7 @@ DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t serv
{
return dlt_register_injection_callback_with_id(handle,
service_id,
- (dlt_injection_callback_id)dlt_injection_callback,
+ (dlt_injection_callback_id)(void*)dlt_injection_callback,
NULL);
}
diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
index d0ea325..7c55a1a 100644
--- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
+++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c
@@ -90,15 +90,19 @@ void dlt_logstorage_log_file_name(char *log_file_name,
struct tm tm_info;
tzset();
localtime_r(&t, &tm_info);
- sprintf(stamp,
- "%c%04d%02d%02d-%02d%02d%02d",
- file_config->logfile_delimiter,
- 1900 + tm_info.tm_year,
- 1 + tm_info.tm_mon,
- tm_info.tm_mday,
- tm_info.tm_hour,
- tm_info.tm_min,
- tm_info.tm_sec);
+ if (snprintf(stamp,
+ DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + 1,
+ "%c%04d%02d%02d-%02d%02d%02d",
+ file_config->logfile_delimiter,
+ 1900 + tm_info.tm_year,
+ 1 + tm_info.tm_mon,
+ tm_info.tm_mday,
+ tm_info.tm_hour,
+ tm_info.tm_min,
+ tm_info.tm_sec) != 0) {
+ dlt_vlog(LOG_WARNING, "%s: snprintf truncation %s\n", __func__,
+ stamp);
+ }
strcat(log_file_name, stamp);
}
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 642d43d..670b01b 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -3042,21 +3042,22 @@ void dlt_get_version(char *buf, size_t size)
return;
}
+/* Clang does not like these macros, because they are not reproducable */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdate-time"
snprintf(buf,
size,
"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n",
_DLT_PACKAGE_VERSION,
_DLT_PACKAGE_VERSION_STATE,
_DLT_PACKAGE_REVISION,
-/* Clang does not like these macros, because they are not reproducable */
-#pragma clang diagnostic ignored "-Wdate-time"
__DATE__,
__TIME__,
-#pragma clang diagnostic error "-Wdate-time"
_DLT_SYSTEMD_ENABLE,
_DLT_SYSTEMD_WATCHDOG_ENABLE,
_DLT_TEST_ENABLE,
_DLT_SHM_ENABLE);
+#pragma GCC diagnostic pop
}
void dlt_get_major_version(char *buf, size_t size)
diff --git a/src/shared/dlt_config_file_parser.c b/src/shared/dlt_config_file_parser.c
index e701341..7392836 100644
--- a/src/shared/dlt_config_file_parser.c
+++ b/src/shared/dlt_config_file_parser.c
@@ -288,17 +288,21 @@ static int dlt_config_file_get_key_value(char *line, char *str1, char *str2)
ptr = strtok_r(line, delimiter, &save_ptr);
- if (ptr != NULL) /* get key */
- strncpy(str1, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN);
- else
+ if (ptr != NULL) { /* get key */
+ strncpy(str1, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1);
+ str1[DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1] = '\0';
+ } else {
return -1;
+ }
ptr = strtok_r(NULL, delimiter, &save_ptr);
- if (ptr != NULL)
- strncpy(str2, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN);
- else
+ if (ptr != NULL) {
+ strncpy(str2, ptr, DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1);
+ str2[DLT_CONFIG_FILE_ENTRY_MAX_LEN - 1] = '\0';
+ } else {
return -1;
+ }
return 0;
}
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 060b97f..1f6a5d5 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -116,13 +116,15 @@ unsigned int dlt_offline_trace_storage_dir_info(char *path, char *file_name, cha
}
if (num > 0) {
- if (tmp_old != NULL)
- if (strlen(tmp_old) < NAME_MAX)
- strncpy(oldest, tmp_old, NAME_MAX);
+ if ((tmp_old != NULL) && (strlen(tmp_old) < NAME_MAX)) {
+ strncpy(oldest, tmp_old, NAME_MAX);
+ oldest[NAME_MAX] = '\0';
+ }
- if (tmp_new != NULL)
- if (strlen(tmp_old) < NAME_MAX)
- strncpy(newest, tmp_new, NAME_MAX);
+ if ((tmp_new != NULL) && (strlen(tmp_old) < NAME_MAX)) {
+ strncpy(newest, tmp_new, NAME_MAX);
+ oldest[NAME_MAX] = '\0';
+ }
}
/* free scandir result */