diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/dlt_daemon_socket.c | 11 | ||||
-rw-r--r-- | src/offlinelogstorage/dlt_offline_logstorage_behavior.c | 47 | ||||
-rw-r--r-- | src/shared/dlt_offline_trace.c | 4 |
3 files changed, 28 insertions, 34 deletions
diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c index 65d9a5c..a2cf08a 100644 --- a/src/daemon/dlt_daemon_socket.c +++ b/src/daemon/dlt_daemon_socket.c @@ -193,15 +193,16 @@ int dlt_daemon_socket_sendreliable(int sock, void *data_buffer, int message_size int data_sent = 0; while (data_sent < message_size) { - ssize_t ret = send(sock, (char *)data_buffer + data_sent, message_size - data_sent, 0); + ssize_t ret = send(sock, + (uint8_t*)data_buffer + data_sent, + message_size - data_sent, + 0); if (ret < 0) { dlt_vlog(LOG_WARNING, - "dlt_daemon_socket_sendreliable: socket send failed [errno: %d]!\n", - errno); + "%s: socket send failed [errno: %d]!\n", __func__, errno); return DLT_DAEMON_ERROR_SEND_FAILED; - } - else { + } else { data_sent += ret; } } diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c index 3f7555e..d0ea325 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c @@ -515,17 +515,13 @@ DLT_STATIC int dlt_logstorage_find_dlt_header(void *ptr, unsigned int offset, unsigned int cnt) { - int index = 0; - char substring[] = { 'D', 'L', 'T', 0x01 }; + const char magic[] = { 'D', 'L', 'T', 0x01 }; + const char *cache = (char*)ptr + offset; - while (cnt > 0) { - if (*((char *)ptr + offset + index) == 'D') { - if (strncmp((char *)ptr + offset + index, substring, 4) == 0) - return index; - } - - cnt--; - index++; + unsigned int i; + for (i = 0; i < cnt; i++) { + if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) + return i; } return -1; @@ -545,18 +541,15 @@ DLT_STATIC int dlt_logstorage_find_last_dlt_header(void *ptr, unsigned int offset, unsigned int cnt) { - char substring[] = {'D', 'L', 'T', 0x01}; - while(cnt > 0) - { - if (*((char *)ptr + offset + cnt) == 'D') - { - if (strncmp((char *)ptr + offset + cnt, substring, 4) == 0) - { - return cnt; - } - } - cnt--; + const char magic[] = {'D', 'L', 'T', 0x01}; + const char *cache = (char*)ptr + offset; + + unsigned int i; + for (i = cnt; i > 0; i--) { + if ((cache[i] == 'D') && (strncmp(&cache[i], magic, 4) == 0)) + return i; } + return -1; } @@ -653,7 +646,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } } - ret = fwrite((char *)config->cache + start_offset + start_index, count, 1, + ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); @@ -691,7 +684,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } } - ret = fwrite((char *)config->cache + start_offset + start_index, count, 1, + ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); @@ -962,7 +955,7 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, DltLogStorageCacheFooter *footer = NULL; int msg_size; int remain_cache_size; - char *curr_write_addr = NULL; + uint8_t *curr_write_addr = NULL; int ret = 0; unsigned int cache_size; @@ -983,7 +976,7 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((char *)config->cache + cache_size); + footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); if (footer == NULL) { dlt_log(LOG_ERR, "Cannot retrieve cache footer. Address is NULL\n"); @@ -994,7 +987,7 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, if (msg_size <= remain_cache_size) /* add at current position */ { - curr_write_addr = (char *)config->cache + footer->offset; + curr_write_addr = (uint8_t*)config->cache + footer->offset; footer->offset += msg_size; if (footer->wrap_around_cnt < 1) { footer->end_sync_offset = footer->offset; @@ -1123,7 +1116,7 @@ int dlt_logstorage_sync_msg_cache(DltLogStorageFilterConfig *config, cache_size = config->file_size; } - footer = (DltLogStorageCacheFooter *)((char *)config->cache + cache_size); + footer = (DltLogStorageCacheFooter *)((uint8_t*)config->cache + cache_size); if (footer == NULL) { dlt_log(LOG_ERR, "Cannot retrieve cache information\n"); diff --git a/src/shared/dlt_offline_trace.c b/src/shared/dlt_offline_trace.c index 303d6b3..060b97f 100644 --- a/src/shared/dlt_offline_trace.c +++ b/src/shared/dlt_offline_trace.c @@ -195,7 +195,7 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace) DLT_OFFLINETRACE_FILENAME_TIMESTAMP_DELI, timestamp, DLT_OFFLINETRACE_FILENAME_EXT); - if ((ret < 0) || (ret >= (int)sizeof(trace->filename))) { + if ((ret < 0) || ((size_t)ret >= (int)sizeof(trace->filename))) { printf("dlt_offlinetrace filename cannot be concatenated\n"); return DLT_RETURN_ERROR; } @@ -203,7 +203,7 @@ DltReturnValue dlt_offline_trace_create_new_file(DltOfflineTrace *trace) ret = snprintf(file_path, sizeof(file_path), "%s/%s", trace->directory, trace->filename); - if ((ret < 0) || (ret >= (int)sizeof(file_path))) { + if ((ret < 0) || ((size_t)ret >= (int)sizeof(file_path))) { printf("dlt_offlinetrace file path cannot be concatenated\n"); return DLT_RETURN_ERROR; } |