summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhong Tran <tranmanphong@gmail.com>2018-03-29 13:51:29 +0700
committerManikandanChockalingam <manikandan.chockalingam@in.bosch.com>2018-03-29 12:21:29 +0530
commit90c8b5b2890a227088b5a67a21bdc24028b156d5 (patch)
treeeb8fea77da9090e94ada870fa8519ce479e18e58 /src
parentb3b7f98bff66d8235474f68004f7b767835b8e3e (diff)
downloadDLT-daemon-90c8b5b2890a227088b5a67a21bdc24028b156d5.tar.gz
minor compiler warning gcc 7.x (#30)
* Fix -Wpointer-compare of compare with null char Signed-off-by: Phong Tran <tranmanphong@gmail.com> * dlt_common: fix -Wformat-truncation of snprintf Avoid snprintf output truncation by handling return value Signed-off-by: Phong Tran <tranmanphong@gmail.com> * dlt_offline_trace: Fix Wformat-truncation of snprintf Compile with Gcc 7.x has the warning of snprintf buffer length size. Check return value of snprintf() for avoiding the warning. Signed-off-by: Phong Tran <tranmanphong@gmail.com> * dlt_common_test: Fix memleak t_dlt_message_read some resources were not free after using. Detected by running valgrind --leak-check=full ./gtest_dlt_common Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/dlt_daemon_common.c2
-rw-r--r--src/lib/dlt_user.c4
-rw-r--r--src/shared/dlt_common.c12
-rw-r--r--src/shared/dlt_offline_trace.c16
4 files changed, 27 insertions, 7 deletions
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 096708c..11be6e6 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -596,7 +596,7 @@ int dlt_daemon_applications_save(DltDaemon *daemon, const char *filename, int ve
dlt_set_id(apid,daemon->applications[i].apid);
if ((daemon->applications[i].application_description) &&
- (daemon->applications[i].application_description!='\0'))
+ (daemon->applications[i].application_description[0] != '\0'))
{
fprintf(fd,"%s:%s:\n",apid, daemon->applications[i].application_description);
}
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index eba6189..8d1aec1 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -3817,7 +3817,7 @@ DltReturnValue dlt_user_log_send_register_context(DltContextData *log)
return DLT_RETURN_ERROR;
}
- if (log->handle->contextID=='\0')
+ if (log->handle->contextID[0] == '\0')
{
return DLT_RETURN_ERROR;
}
@@ -3900,7 +3900,7 @@ DltReturnValue dlt_user_log_send_unregister_context(DltContextData *log)
return DLT_RETURN_WRONG_PARAMETER;
}
- if (log->handle->contextID=='\0')
+ if (log->handle->contextID[0] == '\0')
{
return DLT_RETURN_ERROR;
}
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index b98c7fa..818f3ef 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -186,8 +186,11 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength ,uint8_t *ptr,
/* print full lines */
for (lines=0; lines< (size / DLT_COMMON_HEX_CHARS); lines++)
{
+ int ret = 0;
/* Line number */
- snprintf(text,DLT_COMMON_HEX_LINELEN+1,"%.6x: ",lines * DLT_COMMON_HEX_CHARS);
+ ret = snprintf(text,DLT_COMMON_HEX_LINELEN+1,"%.6x: ",lines * DLT_COMMON_HEX_CHARS);
+ if ((ret < 0 ) || (ret >= (DLT_COMMON_HEX_LINELEN + 1)))
+ dlt_log(LOG_WARNING, "line was truncated\n");
text+=DLT_COMMON_HEX_LINELEN; /* 'XXXXXX: ' */
/* Hex-Output */
@@ -222,7 +225,12 @@ DltReturnValue dlt_print_mixed_string(char *text, int textlength ,uint8_t *ptr,
if (rest>0)
{
/* Line number */
- snprintf(text,9,"%.6x: ", (size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS);
+ int ret = 0;
+ ret = snprintf(text,9,"%.6x: ", (size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS);
+ if ((ret < 0) || (ret >= 9))
+ {
+ dlt_log(LOG_WARNING, "line number was truncated");
+ }
text+=DLT_COMMON_HEX_LINELEN; /* 'XXXXXX: ' */
/* Hex-Output */
diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c
index 32b5253..6b7a10a 100644
--- a/src/shared/dlt_offline_trace.c
+++ b/src/shared/dlt_offline_trace.c
@@ -216,6 +216,7 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace) {
/* set filename */
if(trace->filenameTimestampBased)
{
+ int ret = 0;
t = time(NULL);
tmp = localtime(&t);
if (NULL == tmp) {
@@ -224,16 +225,27 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace) {
}
if (strftime(outstr, sizeof(outstr),"%Y%m%d_%H%M%S", tmp) == 0) {
}
- snprintf(trace->filename, NAME_MAX + 1, "%s/dlt_offlinetrace_%s.dlt", trace->directory, outstr);
+ ret = snprintf(trace->filename, NAME_MAX , "%s/dlt_offlinetrace_%s.dlt", trace->directory, outstr);
+ if ((ret < 0) || (ret >= NAME_MAX))
+ {
+ printf("dlt_offlinetrace filename cannot be concatenated\n");
+ return DLT_RETURN_ERROR;
+ }
}
else
{
+ int ret = 0;
/* targeting newest file, ignoring number of files in dir returned */
dlt_offline_trace_storage_dir_info(trace->directory, DLT_OFFLINETRACE_FILENAME_BASE, newest, oldest);
idx = dlt_offline_trace_get_idx_of_log_file(newest) + 1;
dlt_offline_trace_file_name(outstr, DLT_OFFLINETRACE_FILENAME_BASE, idx);
- snprintf(trace->filename, NAME_MAX + 1, "%s/%s", trace->directory, outstr);
+ ret = snprintf(trace->filename, NAME_MAX, "%s/%s", trace->directory, outstr);
+ if ((ret < 0) || (ret >= NAME_MAX))
+ {
+ printf("filename cannot be concatenated\n");
+ return DLT_RETURN_ERROR;
+ }
}