Merge pull request #11173 from michalpasztamobica/coverity_fixes

Coverity and compilation warnings fixes
pull/11179/head
Seppo Takalo 2019-08-07 14:06:04 +03:00 committed by GitHub
commit 6781c793b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 52 additions and 49 deletions

View File

@ -107,7 +107,8 @@ static unsigned int local_math_power(int base, int exp);
//***********************
SPIFBlockDevice::SPIFBlockDevice(
PinName mosi, PinName miso, PinName sclk, PinName csel, int freq)
: _spi(mosi, miso, sclk), _cs(csel), _device_size_bytes(0), _is_initialized(false), _init_ref_count(0)
: _spi(mosi, miso, sclk), _cs(csel), _read_instruction(0), _prog_instruction(0), _erase_instruction(0),
_erase4k_inst(0), _page_size_bytes(0), _device_size_bytes(0), _init_ref_count(0), _is_initialized(false)
{
_address_size = SPIF_ADDR_SIZE_3_BYTES;
// Initial SFDP read tables are read with 8 dummy cycles
@ -205,7 +206,7 @@ int SPIFBlockDevice::init()
_region_high_boundary[0] = _device_size_bytes - 1;
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", sector_map_table_addr,
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - Parsing Sector Map Table - addr: 0x%" PRIx32 "h, Size: %d", sector_map_table_addr,
sector_map_table_size);
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
tr_error("init - Parse Sector Map Table Failed");
@ -296,7 +297,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
uint32_t offset = 0;
uint32_t chunk = 0;
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: program - Buff: 0x%lxh, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: program - Buff: 0x%" PRIx32 "h, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
while (size > 0) {
@ -352,6 +353,10 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
int status = SPIF_BD_ERROR_OK;
// Find region of erased address
int region = _utils_find_addr_region(addr);
if (region < 0) {
tr_error("no region found for address %llu", addr);
return SPIF_BD_ERROR_INVALID_ERASE_PARAMS;
}
// Erase Types of selected region
uint8_t bitfield = _region_erase_types_bitfield[region];
@ -377,7 +382,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
offset = addr % _erase_type_size_arr[type];
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu , ",
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , ",
addr, size, cur_erase_inst, chunk);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - Region: %d, Type:%d",
region, type);
@ -439,7 +444,7 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
}
// Find minimal erase size supported by the region to which the address belongs to
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr) const
{
// Find region of current address
int region = _utils_find_addr_region(addr);
@ -693,7 +698,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
(param_table[5] << 8) |
param_table[4]);
_device_size_bytes = (density_bits + 1) / 8;
tr_debug("Density bits: %ld , device size: %llu bytes", density_bits, _device_size_bytes);
tr_debug("Density bits: %" PRIu32 " , device size: %llu bytes", density_bits, _device_size_bytes);
// Set Default read/program/erase Instructions
_read_instruction = SPIF_READ;
@ -998,7 +1003,7 @@ int SPIFBlockDevice::_set_write_enable()
/*********************************************/
/************* Utility Functions *************/
/*********************************************/
int SPIFBlockDevice::_utils_find_addr_region(bd_size_t offset)
int SPIFBlockDevice::_utils_find_addr_region(bd_size_t offset) const
{
//Find the region to which the given offset belong to
if ((offset > _device_size_bytes) || (_regions_count == 0)) {

View File

@ -170,7 +170,7 @@ public:
* @return Size of minimal erase sector size, in given address region, in bytes
* @note Must be a multiple of the program size
*/
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr);
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const;
/** Get the value of storage byte after it was erased
*
@ -227,7 +227,7 @@ private:
/* Utilities Functions */
/***********************/
// Find the region to which the given offset belongs to
int _utils_find_addr_region(bd_size_t offset);
int _utils_find_addr_region(bd_size_t offset) const;
// Iterate on all supported Erase Types of the Region to which the offset belongs to.
// Iterates from highest type to lowest

View File

@ -717,7 +717,7 @@ nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const
if (!dns_timer_running) {
if (nsapi_dns_call_in(query->call_in_cb, DNS_TIMER_TIMEOUT, mbed::callback(nsapi_dns_query_async_timeout)) != NSAPI_ERROR_OK) {
delete query->host;
delete[] query->host;
delete query;
dns_mutex->unlock();
return NSAPI_ERROR_NO_MEMORY;

View File

@ -28,7 +28,7 @@ static inline uint32_t align_down(bd_size_t val, bd_size_t size)
}
BufferedBlockDevice::BufferedBlockDevice(BlockDevice *bd)
: _bd(bd), _bd_program_size(0), _bd_read_size(0), _write_cache_addr(0), _write_cache_valid(false),
: _bd(bd), _bd_program_size(0), _bd_read_size(0), _bd_size(0), _write_cache_addr(0), _write_cache_valid(false),
_write_cache(0), _read_buf(0), _init_ref_count(0), _is_initialized(false)
{
}

View File

@ -2719,7 +2719,7 @@ void get_fileinfo (
if (wc == 0) { di = 0; break; } /* Buffer overflow? */
di += wc;
#else /* ANSI/OEM output */
fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
if (di <= FF_SFN_BUF) fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
#endif
}
fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */
@ -4938,7 +4938,7 @@ FRESULT f_mkdir (
res = sync_fs(fs);
}
} else {
remove_chain(&dj.obj, dcl, 0); /* Could not register, remove cluster chain */
res = remove_chain(&dj.obj, dcl, 0); /* Could not register, remove cluster chain */
}
}
FREE_NAMBUF();
@ -4967,7 +4967,8 @@ FRESULT f_rename (
DEF_NAMBUF
get_ldnumber(&path_new); /* Snip the drive number of new name off */
int vol = get_ldnumber(&path_new); /* Snip the drive number of new name off */
if (vol < 0) return FR_INVALID_DRIVE;
res = find_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
if (res == FR_OK) {
djo.obj.fs = fs;

View File

@ -282,6 +282,7 @@ extern "C" DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
: FileSystem(name), _id(-1)
{
_fs = { 0 };
if (bd) {
mount(bd);
}

View File

@ -149,6 +149,9 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
, _prog_size(prog_size)
, _block_size(block_size)
, _lookahead(lookahead)
, _lfs()
, _config()
, _bd(NULL)
{
if (bd) {
mount(bd);

View File

@ -924,7 +924,7 @@ int lfs_mkdir(lfs_t *lfs, const char *path) {
// build up new directory
lfs_alloc_ack(lfs);
lfs_dir_t dir;
lfs_dir_t dir = { 0 };
err = lfs_dir_alloc(lfs, &dir);
if (err) {
return err;
@ -2106,7 +2106,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
lfs_alloc_ack(lfs);
// create superblock dir
lfs_dir_t superdir;
lfs_dir_t superdir = { 0 };
err = lfs_dir_alloc(lfs, &superdir);
if (err) {
goto cleanup;

View File

@ -64,7 +64,8 @@ static char *string_ndup(const char *src, size_t size);
// Class Functions
FileSystemStore::FileSystemStore(FileSystem *fs) : _fs(fs),
_is_initialized(false)
_is_initialized(false), _cfg_fs_path(NULL), _cfg_fs_path_size(0),
_full_path_key(NULL), _cur_inc_data_size(0), _cur_inc_set_handle(NULL)
{
}
@ -534,7 +535,7 @@ int FileSystemStore::iterator_next(iterator_t it, char *key, size_t key_size)
key_it = (key_iterator_handle_t *)it;
if (key_name_size < strlen(key_it->prefix)) {
if ((key_it->prefix != NULL) && (key_name_size < strlen(key_it->prefix))) {
status = MBED_ERROR_INVALID_SIZE;
goto exit_point;
}
@ -579,9 +580,8 @@ int FileSystemStore::iterator_close(iterator_t it)
delete[] key_it->prefix;
}
((Dir *)(key_it->dir_handle))->close();
if (key_it->dir_handle != NULL) {
((Dir *)(key_it->dir_handle))->close();
delete ((Dir *)(key_it->dir_handle));
}
delete key_it;

View File

@ -65,7 +65,7 @@ int KVMap::attach(const char *partition_name, kvstore_config_t *kv_config)
goto exit;
}
kv_partition_name = new char[strlen(partition_name + 1)];
kv_partition_name = new char[strlen(partition_name) + 1];
strcpy(kv_partition_name, partition_name);
_kv_map_table[_kv_num_attached_kvs].partition_name = kv_partition_name;
_kv_map_table[_kv_num_attached_kvs].kv_config = kv_config;
@ -251,10 +251,7 @@ KVStore *KVMap::get_internal_kv_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->internal_store;
@ -269,10 +266,7 @@ KVStore *KVMap::get_external_kv_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->external_store;
@ -287,10 +281,7 @@ KVStore *KVMap::get_main_kv_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->kvstore_main_instance;
@ -305,10 +296,7 @@ BlockDevice *KVMap::get_internal_blockdevice_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->internal_bd;
@ -323,10 +311,7 @@ BlockDevice *KVMap::get_external_blockdevice_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->external_bd;
@ -341,10 +326,7 @@ FileSystem *KVMap::get_external_filesystem_instance(const char *name)
size_t key_index = 0;
int ret = config_lookup(name, &kv_config, &key_index);
if (ret != MBED_SUCCESS) {
goto exit;
}
exit:
_mutex->unlock();
return ret != MBED_SUCCESS ? NULL : kv_config->external_fs;

View File

@ -109,7 +109,7 @@ int encrypt_decrypt_start(mbedtls_aes_context &enc_aes_ctx, uint8_t *iv, const c
int encrypt_decrypt_data(mbedtls_aes_context &enc_aes_ctx, const uint8_t *in_buf,
uint8_t *out_buf, uint32_t chunk_size, uint8_t *ctr_buf, size_t &aes_offs)
{
uint8_t stream_block[enc_block_size];
uint8_t stream_block[enc_block_size] = { 0 };
return mbedtls_aes_crypt_ctr(&enc_aes_ctx, chunk_size, &aes_offs, ctr_buf,
stream_block, in_buf, out_buf);

View File

@ -128,6 +128,12 @@ TDBStore::TDBStore(BlockDevice *bd) : _ram_table(0), _max_keys(0),
_master_record_size(0), _is_initialized(false), _active_area(0), _active_area_version(0), _size(0),
_prog_size(0), _work_buf(0), _key_buf(0), _variant_bd_erase_unit_size(false), _inc_set_handle(0)
{
for (int i = 0; i < _num_areas; i++) {
_area_params[i] = { 0 };
}
for (int i = 0; i < _max_open_iterators; i++) {
_iterator_table[i] = { 0 };
}
}
TDBStore::~TDBStore()
@ -392,8 +398,8 @@ int TDBStore::set_start(set_handle_t *handle, const char *key, size_t final_data
uint32_t create_flags)
{
int ret;
uint32_t offset;
uint32_t hash, ram_table_ind;
uint32_t offset = 0;
uint32_t hash = 0, ram_table_ind = 0;
inc_set_handle_t *ih;
bool need_gc = false;

View File

@ -148,6 +148,9 @@ NVStore::NVStore() : _init_done(0), _init_attempts(0), _active_area(0), _max_key
_active_area_version(0), _free_space_offset(0), _size(0), _mutex(0), _offset_by_key(0), _flash(0),
_min_prog_size(0), _page_buf(0)
{
for (int i = 0; i < NVSTORE_NUM_AREAS; i++) {
_flash_area_params[i] = { 0 };
}
}
NVStore::~NVStore()
@ -859,7 +862,9 @@ int NVStore::init()
if (!_flash) {
return NVSTORE_OS_ERROR;
}
_flash->init();
if (_flash->init() < 0) {
return NVSTORE_OS_ERROR;
}
_min_prog_size = std::max(_flash->get_page_size(), (uint32_t)sizeof(nvstore_record_header_t));
if (_min_prog_size > sizeof(nvstore_record_header_t)) {