summaryrefslogtreecommitdiff
path: root/src/daemon
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/daemon
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/daemon')
-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
3 files changed, 25 insertions, 22 deletions
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);