From 72c2ea521e1002996f423b56293adf21f6f00ea6 Mon Sep 17 00:00:00 2001 From: "Dinh Cong Toan(RBVH/ECM12)" Date: Thu, 15 Oct 2020 17:09:55 +0700 Subject: logstorage: fix conversion warnings - Some functions like 'strncmp()', 'strncat()', 'strcpy()' and 'memcpy()' take an argument in type 'size_t', so explicit data type to 'size_t' in this case is needed to avoid conversion warnings. - Function 'strlen' return data type 'size_t', which still need to cast data type Signed-off-by: Dinh Cong Toan(RBVH/ECM12) --- src/offlinelogstorage/dlt_offline_logstorage.c | 62 ++++++++++---------- .../dlt_offline_logstorage_behavior.c | 68 +++++++++++----------- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c index 07d09a5..85b215b 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage.c +++ b/src/offlinelogstorage/dlt_offline_logstorage.c @@ -193,7 +193,7 @@ DLT_STATIC int dlt_logstorage_list_add(char *keys, return -1; tmp->key_list = (char *)calloc( - (num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), sizeof(char)); + (size_t) (num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), sizeof(char)); if (tmp->key_list == NULL) { free(tmp); @@ -201,7 +201,7 @@ DLT_STATIC int dlt_logstorage_list_add(char *keys, return -1; } - memcpy(tmp->key_list, keys, num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + memcpy(tmp->key_list, keys, (size_t) (num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)); tmp->num_keys = num_keys; tmp->next = NULL; tmp->data = calloc(1, sizeof(DltLogStorageFilterConfig)); @@ -327,7 +327,7 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, char *value) { int i = 0; int y = 0; - int len = 0; + size_t len = 0; char *tok; int num = 1; @@ -349,7 +349,7 @@ DLT_STATIC int dlt_logstorage_read_list_of_names(char **names, char *value) num = dlt_logstorage_count_ids(value); /* need to alloc space for 5 chars, 4 for the name and "," and "\0" */ - *names = (char *)calloc(num * 5, sizeof(char)); + *names = (char *)calloc((size_t) (num * 5), sizeof(char)); if (*names == NULL) return -1; @@ -399,7 +399,7 @@ DLT_STATIC int dlt_logstorage_read_number(unsigned int *number, char *value) return -1; *number = 0; - len = strlen(value); + len = (int) strlen(value); /* check if string consists of digits only */ for (i = 0; i < len; i++) @@ -495,7 +495,7 @@ DLT_STATIC void dlt_logstorage_create_keys_only_ctid(char *ecuid, char *ctid, char *key) { char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - int curr_len = 0; + size_t curr_len = 0; if (ecuid != NULL) { strncpy(curr_str, ecuid, strlen(ecuid)); @@ -527,7 +527,7 @@ DLT_STATIC void dlt_logstorage_create_keys_only_apid(char *ecuid, char *apid, char *key) { char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - int curr_len = 0; + size_t curr_len = 0; if (ecuid != NULL) { strncpy(curr_str, ecuid, strlen(ecuid)); @@ -561,7 +561,7 @@ DLT_STATIC void dlt_logstorage_create_keys_multi(char *ecuid, char *apid, char *ctid, char *key) { char curr_str[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { 0 }; - int curr_len = 0; + size_t curr_len = 0; if (ecuid != NULL) { strncpy(curr_str, ecuid, strlen(ecuid)); @@ -651,7 +651,7 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids, (ctids != NULL) && (strncmp(ctids, ".*", 2) == 0) && (ecuid != NULL)) ) { dlt_logstorage_create_keys_only_ecu(ecuid, curr_key); *(num_keys) = 1; - *(keys) = (char *)calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, + *(keys) = (char *)calloc((size_t) (*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), sizeof(char)); if (*(keys) == NULL) @@ -682,7 +682,7 @@ DLT_STATIC int dlt_logstorage_create_keys(char *apids, *(num_keys) = num_apids * num_ctids; /* allocate memory for needed number of keys */ - *(keys) = (char *)calloc(*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, + *(keys) = (char *)calloc((size_t) (*num_keys * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), sizeof(char)); if (*(keys) == NULL) { @@ -822,20 +822,20 @@ DLT_STATIC int dlt_logstorage_validate_filter_name(char *name) { int len = 0; int idx = 0; - int config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION); - int storage_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION); - int control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION); + size_t config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION); + size_t storage_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION); + size_t control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION); if (name == NULL) return -1; - len = strlen(name); + len = (int) strlen(name); /* Check if section header is of format "FILTER" followed by a number */ if (strncmp(name, DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION, config_sec_len) == 0) { - for (idx = config_sec_len; idx < len - 1; idx++) + for (idx = (int) config_sec_len; idx < len - 1; idx++) if (!isdigit(name[idx])) return -1; @@ -846,7 +846,7 @@ DLT_STATIC int dlt_logstorage_validate_filter_name(char *name) DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION, storage_sec_len) == 0) { - for (idx = storage_sec_len; idx < len - 1; idx++) + for (idx = (int) storage_sec_len; idx < len - 1; idx++) if (!isdigit(name[idx])) return -1; @@ -857,7 +857,7 @@ DLT_STATIC int dlt_logstorage_validate_filter_name(char *name) DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION, control_sec_len) == 0) { - for (idx = control_sec_len; idx < len - 1; idx++) + for (idx = (int) control_sec_len; idx < len - 1; idx++) if (!isdigit(name[idx])) return -1; @@ -1001,7 +1001,7 @@ DLT_STATIC int dlt_logstorage_check_reset_loglevel(DltLogStorageFilterConfig *co DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, char *value) { - int len; + size_t len; if ((value == NULL) || (strcmp(value, "") == 0)) return -1; @@ -1015,7 +1015,7 @@ DLT_STATIC int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, /* do not allow the user to change directory by adding a relative path */ if (strstr(value, "..") == NULL) { - config->file_name = calloc((len + 1), sizeof(char)); + config->file_name = calloc(len + 1, sizeof(char)); if (config->file_name == NULL) { dlt_log(LOG_ERR, @@ -1123,7 +1123,7 @@ DLT_STATIC int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *con DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, char *value) { - int len; + size_t len; if ((config == NULL) || (value == NULL) || (value[0] == '\0')) return -1; @@ -1134,7 +1134,7 @@ DLT_STATIC int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, } len = strlen(value); - config->ecuid = calloc((len + 1), sizeof(char)); + config->ecuid = calloc(len + 1, sizeof(char)); if (config->ecuid == NULL) return -1; @@ -1368,9 +1368,9 @@ DLT_STATIC int dlt_logstorage_get_filter_value(DltConfigFile *config_file, char *value) { int ret = 0; - int config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION); - int storage_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION); - int control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION); + size_t config_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_CONFIG_SECTION); + size_t storage_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_STORAGE_SECTION); + size_t control_sec_len = strlen(DLT_OFFLINE_LOGSTORAGE_NONVERBOSE_CONTROL_SECTION); if ((config_file == NULL) || (sec_name == NULL)) return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR; @@ -1931,9 +1931,9 @@ int dlt_logstorage_get_config(DltLogStorage *handle, char key[DLT_CONFIG_FILE_SECTIONS_MAX][DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = { { '\0' }, { '\0' }, { '\0' } }; int i = 0; - int apid_len = 0; - int ctid_len = 0; - int ecuid_len = 0; + size_t apid_len = 0; + size_t ctid_len = 0; + size_t ecuid_len = 0; int num_configs = 0; int num = 0; @@ -2161,10 +2161,10 @@ int dlt_logstorage_write(DltLogStorage *handle, + sizeof(DltStandardHeader)); if (DLT_IS_HTYP_UEH(standardHeader->htyp)) { - header_len = sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + standardHeaderExtraLen; + header_len = (unsigned int) (sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + standardHeaderExtraLen); /* check if size2 is big enough to contain expected DLT message header */ - if ((unsigned int)size2 < header_len) { + if ((unsigned int) size2 < header_len) { dlt_log(LOG_ERR, "DLT message header is too small\n"); return 0; } @@ -2185,10 +2185,10 @@ int dlt_logstorage_write(DltLogStorage *handle, } } else { - header_len = sizeof(DltStandardHeader) + standardHeaderExtraLen; + header_len = (unsigned int) (sizeof(DltStandardHeader) + standardHeaderExtraLen); /* check if size2 is big enough to contain expected DLT message header */ - if ((unsigned int)size2 < header_len) { + if ((unsigned int) size2 < header_len) { dlt_log(LOG_ERR, "DLT message header is too small (without extended header)\n"); return 0; } diff --git a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c index 9c121e0..b7b7955 100644 --- a/src/offlinelogstorage/dlt_offline_logstorage_behavior.c +++ b/src/offlinelogstorage/dlt_offline_logstorage_behavior.c @@ -73,7 +73,7 @@ void dlt_logstorage_log_file_name(char *log_file_name, unsigned int digit_idx = 0; unsigned int i = 0; snprintf(file_index, 10, "%d", idx); - digit_idx = strlen(file_index); + digit_idx = (unsigned int) strlen(file_index); if (file_config->logfile_counteridxlen > digit_idx) { @@ -233,16 +233,16 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co return -1; } - filename_len = strlen(file) - strlen(filename); + filename_len = (unsigned int) (strlen(file) - strlen(filename)); /* index is retrived from file name */ if (file_config->logfile_timestamp) { - fileindex_len = strlen(file) - + fileindex_len = (unsigned int) strlen(file) - (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN + filename_len + 1); - idx = (int)strtol(&file[strlen(file) - + idx = (unsigned int) strtol(&file[strlen(file) - (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + fileindex_len + DLT_OFFLINE_LOGSTORAGE_TIMESTAMP_LEN)], @@ -250,11 +250,11 @@ unsigned int dlt_logstorage_get_idx_of_log_file(DltLogStorageUserConfig *file_co 10); } else { - fileindex_len = strlen(file) - + fileindex_len = (unsigned int) strlen(file) - (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + filename_len + 1); - idx = (int)strtol(&file[strlen(file) - + idx = (unsigned int) strtol(&file[strlen(file) - (DLT_OFFLINE_LOGSTORAGE_FILE_EXTENSION_LEN + fileindex_len)], &endptr, 10); } @@ -323,7 +323,7 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, } for (i = 0; i < cnt; i++) { - int len = 0; + size_t len = 0; len = strlen(config->file_name); if ((strncmp(files[i]->d_name, config->file_name, len) == 0) && @@ -500,7 +500,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, /* if size is enough, open it */ if ((ret == 0) && (s.st_size + msg_size <= (int) config->file_size)) { config->log = fopen(absolute_file_path, "a+"); - config->current_write_file_offset = s.st_size; + config->current_write_file_offset = (unsigned int) s.st_size; } else { /* no space in file or file stats cannot be read */ @@ -521,7 +521,7 @@ int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, dlt_logstorage_log_file_name(file_name, file_config, config->file_name, - idx); + (int) idx); /* concatenate path and file and open absolute path */ memset(absolute_file_path, @@ -719,8 +719,8 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, int ret = 0; int start_index = 0; int end_index = 0; - int count = 0; - int remain_file_size = 0; + unsigned int count = 0; + unsigned int remain_file_size = 0; if ((config == NULL) || (file_config == NULL) || (dev_path == NULL) || (footer == NULL)) @@ -741,7 +741,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } if (dlt_logstorage_open_log_file(config, file_config, - dev_path, count, true) != 0) { + dev_path, (int) count, true) != 0) { dlt_vlog(LOG_ERR, "%s: failed to open log file\n", __func__); return -1; } @@ -754,14 +754,14 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, remain_file_size); end_index = dlt_logstorage_find_last_dlt_header(config->cache, - start_offset + start_index, - remain_file_size - start_index); - count = end_index - start_index; + start_offset + (unsigned int) start_index, + remain_file_size - (unsigned int) start_index); + count = (unsigned int) (end_index - start_index); if ((start_index >= 0) && (end_index > start_index) && (count > 0) && (count <= remain_file_size)) { - ret = fwrite((uint8_t*)config->cache + start_offset + start_index, + ret = (int) fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); @@ -783,7 +783,7 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, } start_index = dlt_logstorage_find_dlt_header(config->cache, start_offset, count); - count = end_offset - start_offset - start_index; + count = end_offset - start_offset - (unsigned int) start_index; if ((start_index >= 0) && (count > 0)) { @@ -791,14 +791,14 @@ DLT_STATIC int dlt_logstorage_sync_to_file(DltLogStorageFilterConfig *config, if (config->log == NULL) { if (dlt_logstorage_prepare_on_msg(config, file_config, dev_path, - count, NULL) != 0) + (int) count, NULL) != 0) { dlt_vlog(LOG_ERR, "%s: failed to prepare log file\n", __func__); return -1; } } - ret = fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, + ret = (int) fwrite((uint8_t*)config->cache + start_offset + start_index, count, 1, config->log); dlt_logstorage_check_write_ret(config, ret); @@ -935,17 +935,17 @@ int dlt_logstorage_write_on_msg(DltLogStorageFilterConfig *config, return -1; } - ret = fwrite(data1, 1, size1, config->log); + ret = (int) fwrite(data1, 1, (size_t) size1, config->log); if (ret != size1) dlt_log(LOG_WARNING, "Wrote less data than specified\n"); - ret = fwrite(data2, 1, size2, config->log); + ret = (int) fwrite(data2, 1, (size_t) size2, config->log); if (ret != size2) dlt_log(LOG_WARNING, "Wrote less data than specified\n"); - ret = fwrite(data3, 1, size3, config->log); + ret = (int) fwrite(data3, 1, (size_t) size3, config->log); if (ret != size3) dlt_log(LOG_WARNING, "Wrote less data than specified\n"); @@ -1089,7 +1089,7 @@ int dlt_logstorage_prepare_msg_cache(DltLogStorageFilterConfig *config, else { /* update current used cache size */ - g_logstorage_cache_size = cache_size + sizeof(DltLogStorageCacheFooter); + g_logstorage_cache_size = (unsigned int) (cache_size + sizeof(DltLogStorageCacheFooter)); } } @@ -1123,8 +1123,8 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, int size3) { DltLogStorageCacheFooter *footer = NULL; - int msg_size; - int remain_cache_size; + unsigned int msg_size; + unsigned int remain_cache_size; uint8_t *curr_write_addr = NULL; int ret = 0; unsigned int cache_size; @@ -1152,23 +1152,23 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, dlt_log(LOG_ERR, "Cannot retrieve cache footer. Address is NULL\n"); return -1; } - msg_size = size1 + size2 + size3; + msg_size = (unsigned int) (size1 + size2 + size3); remain_cache_size = cache_size - footer->offset; if (msg_size <= remain_cache_size) /* add at current position */ { curr_write_addr = (uint8_t*)config->cache + footer->offset; - footer->offset += msg_size; + footer->offset += (unsigned int) msg_size; if (footer->wrap_around_cnt < 1) { footer->end_sync_offset = footer->offset; } /* write data to cache */ - memcpy(curr_write_addr, data1, size1); + memcpy(curr_write_addr, data1, (size_t) size1); curr_write_addr += size1; - memcpy(curr_write_addr, data2, size2); + memcpy(curr_write_addr, data2, (size_t) size2); curr_write_addr += size2; - memcpy(curr_write_addr, data3, size3); + memcpy(curr_write_addr, data3, (size_t) size3); } /* @@ -1226,14 +1226,14 @@ int dlt_logstorage_write_msg_cache(DltLogStorageFilterConfig *config, /* start writing from beginning */ footer->end_sync_offset = footer->offset; curr_write_addr = config->cache; - footer->offset = msg_size; + footer->offset = (unsigned int) msg_size; /* write data to cache */ - memcpy(curr_write_addr, data1, size1); + memcpy(curr_write_addr, data1, (size_t) size1); curr_write_addr += size1; - memcpy(curr_write_addr, data2, size2); + memcpy(curr_write_addr, data2, (size_t) size2); curr_write_addr += size2; - memcpy(curr_write_addr, data3, size3); + memcpy(curr_write_addr, data3, (size_t) size3); } } -- cgit v1.2.1