Skip to content

Commit 73b122b

Browse files
Coverity and compilation warnings fixes
1 parent 1fe59b7 commit 73b122b

File tree

13 files changed

+52
-49
lines changed

13 files changed

+52
-49
lines changed

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ static unsigned int local_math_power(int base, int exp);
107107
//***********************
108108
SPIFBlockDevice::SPIFBlockDevice(
109109
PinName mosi, PinName miso, PinName sclk, PinName csel, int freq)
110-
: _spi(mosi, miso, sclk), _cs(csel), _device_size_bytes(0), _is_initialized(false), _init_ref_count(0)
110+
: _spi(mosi, miso, sclk), _cs(csel), _read_instruction(0), _prog_instruction(0), _erase_instruction(0),
111+
_erase4k_inst(0), _page_size_bytes(0), _device_size_bytes(0), _init_ref_count(0), _is_initialized(false)
111112
{
112113
_address_size = SPIF_ADDR_SIZE_3_BYTES;
113114
// Initial SFDP read tables are read with 8 dummy cycles
@@ -205,7 +206,7 @@ int SPIFBlockDevice::init()
205206
_region_high_boundary[0] = _device_size_bytes - 1;
206207

207208
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
208-
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - Parsing Sector Map Table - addr: 0x%lxh, Size: %d", sector_map_table_addr,
209+
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - Parsing Sector Map Table - addr: 0x%" PRIx32 "h, Size: %d", sector_map_table_addr,
209210
sector_map_table_size);
210211
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
211212
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)
296297
uint32_t offset = 0;
297298
uint32_t chunk = 0;
298299

299-
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: program - Buff: 0x%lxh, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
300+
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: program - Buff: 0x%" PRIx32 "h, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
300301

301302
while (size > 0) {
302303

@@ -352,6 +353,10 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
352353
int status = SPIF_BD_ERROR_OK;
353354
// Find region of erased address
354355
int region = _utils_find_addr_region(addr);
356+
if (region < 0) {
357+
tr_error("no region found for address %llu", addr);
358+
return SPIF_BD_ERROR_INVALID_ERASE_PARAMS;
359+
}
355360
// Erase Types of selected region
356361
uint8_t bitfield = _region_erase_types_bitfield[region];
357362

@@ -377,7 +382,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
377382
offset = addr % _erase_type_size_arr[type];
378383
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
379384

380-
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %lu , ",
385+
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , ",
381386
addr, size, cur_erase_inst, chunk);
382387
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - Region: %d, Type:%d",
383388
region, type);
@@ -439,7 +444,7 @@ bd_size_t SPIFBlockDevice::get_erase_size() const
439444
}
440445

441446
// Find minimal erase size supported by the region to which the address belongs to
442-
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr)
447+
bd_size_t SPIFBlockDevice::get_erase_size(bd_addr_t addr) const
443448
{
444449
// Find region of current address
445450
int region = _utils_find_addr_region(addr);
@@ -693,7 +698,7 @@ int SPIFBlockDevice::_sfdp_parse_basic_param_table(uint32_t basic_table_addr, si
693698
(param_table[5] << 8) |
694699
param_table[4]);
695700
_device_size_bytes = (density_bits + 1) / 8;
696-
tr_debug("Density bits: %ld , device size: %llu bytes", density_bits, _device_size_bytes);
701+
tr_debug("Density bits: %" PRIu32 " , device size: %llu bytes", density_bits, _device_size_bytes);
697702

698703
// Set Default read/program/erase Instructions
699704
_read_instruction = SPIF_READ;
@@ -998,7 +1003,7 @@ int SPIFBlockDevice::_set_write_enable()
9981003
/*********************************************/
9991004
/************* Utility Functions *************/
10001005
/*********************************************/
1001-
int SPIFBlockDevice::_utils_find_addr_region(bd_size_t offset)
1006+
int SPIFBlockDevice::_utils_find_addr_region(bd_size_t offset) const
10021007
{
10031008
//Find the region to which the given offset belong to
10041009
if ((offset > _device_size_bytes) || (_regions_count == 0)) {

components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class SPIFBlockDevice : public mbed::BlockDevice {
170170
* @return Size of minimal erase sector size, in given address region, in bytes
171171
* @note Must be a multiple of the program size
172172
*/
173-
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr);
173+
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const;
174174

175175
/** Get the value of storage byte after it was erased
176176
*
@@ -227,7 +227,7 @@ class SPIFBlockDevice : public mbed::BlockDevice {
227227
/* Utilities Functions */
228228
/***********************/
229229
// Find the region to which the given offset belongs to
230-
int _utils_find_addr_region(bd_size_t offset);
230+
int _utils_find_addr_region(bd_size_t offset) const;
231231

232232
// Iterate on all supported Erase Types of the Region to which the offset belongs to.
233233
// Iterates from highest type to lowest

features/netsocket/nsapi_dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ nsapi_value_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const
717717

718718
if (!dns_timer_running) {
719719
if (nsapi_dns_call_in(query->call_in_cb, DNS_TIMER_TIMEOUT, mbed::callback(nsapi_dns_query_async_timeout)) != NSAPI_ERROR_OK) {
720-
delete query->host;
720+
delete[] query->host;
721721
delete query;
722722
dns_mutex->unlock();
723723
return NSAPI_ERROR_NO_MEMORY;

features/storage/blockdevice/BufferedBlockDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static inline uint32_t align_down(bd_size_t val, bd_size_t size)
2828
}
2929

3030
BufferedBlockDevice::BufferedBlockDevice(BlockDevice *bd)
31-
: _bd(bd), _bd_program_size(0), _bd_read_size(0), _write_cache_addr(0), _write_cache_valid(false),
31+
: _bd(bd), _bd_program_size(0), _bd_read_size(0), _bd_size(0), _write_cache_addr(0), _write_cache_valid(false),
3232
_write_cache(0), _read_buf(0), _init_ref_count(0), _is_initialized(false)
3333
{
3434
}

features/storage/filesystem/fat/ChaN/ff.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ void get_fileinfo (
27192719
if (wc == 0) { di = 0; break; } /* Buffer overflow? */
27202720
di += wc;
27212721
#else /* ANSI/OEM output */
2722-
fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
2722+
if (di <= FF_SFN_BUF) fno->altname[di++] = (TCHAR)wc; /* Store it without any conversion */
27232723
#endif
27242724
}
27252725
fno->altname[di] = 0; /* Terminate the SFN (null string means SFN is invalid) */
@@ -4938,7 +4938,7 @@ FRESULT f_mkdir (
49384938
res = sync_fs(fs);
49394939
}
49404940
} else {
4941-
remove_chain(&dj.obj, dcl, 0); /* Could not register, remove cluster chain */
4941+
res = remove_chain(&dj.obj, dcl, 0); /* Could not register, remove cluster chain */
49424942
}
49434943
}
49444944
FREE_NAMBUF();
@@ -4967,7 +4967,8 @@ FRESULT f_rename (
49674967
DEF_NAMBUF
49684968

49694969

4970-
get_ldnumber(&path_new); /* Snip the drive number of new name off */
4970+
int vol = get_ldnumber(&path_new); /* Snip the drive number of new name off */
4971+
if (vol < 0) return FR_INVALID_DRIVE;
49714972
res = find_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
49724973
if (res == FR_OK) {
49734974
djo.obj.fs = fs;

features/storage/filesystem/fat/FATFileSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ extern "C" DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
282282
FATFileSystem::FATFileSystem(const char *name, BlockDevice *bd)
283283
: FileSystem(name), _id(-1)
284284
{
285+
_fs = { 0 };
285286
if (bd) {
286287
mount(bd);
287288
}

features/storage/filesystem/littlefs/LittleFileSystem.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
149149
, _prog_size(prog_size)
150150
, _block_size(block_size)
151151
, _lookahead(lookahead)
152+
, _lfs()
153+
, _config()
154+
, _bd(NULL)
152155
{
153156
if (bd) {
154157
mount(bd);

features/storage/filesystem/littlefs/littlefs/lfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ int lfs_mkdir(lfs_t *lfs, const char *path) {
924924
// build up new directory
925925
lfs_alloc_ack(lfs);
926926

927-
lfs_dir_t dir;
927+
lfs_dir_t dir = { 0 };
928928
err = lfs_dir_alloc(lfs, &dir);
929929
if (err) {
930930
return err;
@@ -2106,7 +2106,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
21062106
lfs_alloc_ack(lfs);
21072107

21082108
// create superblock dir
2109-
lfs_dir_t superdir;
2109+
lfs_dir_t superdir = { 0 };
21102110
err = lfs_dir_alloc(lfs, &superdir);
21112111
if (err) {
21122112
goto cleanup;

features/storage/kvstore/filesystemstore/FileSystemStore.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static char *string_ndup(const char *src, size_t size);
6464

6565
// Class Functions
6666
FileSystemStore::FileSystemStore(FileSystem *fs) : _fs(fs),
67-
_is_initialized(false)
67+
_is_initialized(false), _cfg_fs_path(NULL), _cfg_fs_path_size(0),
68+
_full_path_key(NULL), _cur_inc_data_size(0), _cur_inc_set_handle(NULL)
6869
{
6970

7071
}
@@ -534,7 +535,7 @@ int FileSystemStore::iterator_next(iterator_t it, char *key, size_t key_size)
534535

535536
key_it = (key_iterator_handle_t *)it;
536537

537-
if (key_name_size < strlen(key_it->prefix)) {
538+
if ((key_it->prefix != NULL) && (key_name_size < strlen(key_it->prefix))) {
538539
status = MBED_ERROR_INVALID_SIZE;
539540
goto exit_point;
540541
}
@@ -579,9 +580,8 @@ int FileSystemStore::iterator_close(iterator_t it)
579580
delete[] key_it->prefix;
580581
}
581582

582-
((Dir *)(key_it->dir_handle))->close();
583-
584583
if (key_it->dir_handle != NULL) {
584+
((Dir *)(key_it->dir_handle))->close();
585585
delete ((Dir *)(key_it->dir_handle));
586586
}
587587
delete key_it;

features/storage/kvstore/kv_map/KVMap.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int KVMap::attach(const char *partition_name, kvstore_config_t *kv_config)
6565
goto exit;
6666
}
6767

68-
kv_partition_name = new char[strlen(partition_name + 1)];
68+
kv_partition_name = new char[strlen(partition_name) + 1];
6969
strcpy(kv_partition_name, partition_name);
7070
_kv_map_table[_kv_num_attached_kvs].partition_name = kv_partition_name;
7171
_kv_map_table[_kv_num_attached_kvs].kv_config = kv_config;
@@ -251,10 +251,7 @@ KVStore *KVMap::get_internal_kv_instance(const char *name)
251251
size_t key_index = 0;
252252

253253
int ret = config_lookup(name, &kv_config, &key_index);
254-
if (ret != MBED_SUCCESS) {
255-
goto exit;
256-
}
257-
exit:
254+
258255
_mutex->unlock();
259256

260257
return ret != MBED_SUCCESS ? NULL : kv_config->internal_store;
@@ -269,10 +266,7 @@ KVStore *KVMap::get_external_kv_instance(const char *name)
269266
size_t key_index = 0;
270267

271268
int ret = config_lookup(name, &kv_config, &key_index);
272-
if (ret != MBED_SUCCESS) {
273-
goto exit;
274-
}
275-
exit:
269+
276270
_mutex->unlock();
277271

278272
return ret != MBED_SUCCESS ? NULL : kv_config->external_store;
@@ -287,10 +281,7 @@ KVStore *KVMap::get_main_kv_instance(const char *name)
287281
size_t key_index = 0;
288282

289283
int ret = config_lookup(name, &kv_config, &key_index);
290-
if (ret != MBED_SUCCESS) {
291-
goto exit;
292-
}
293-
exit:
284+
294285
_mutex->unlock();
295286

296287
return ret != MBED_SUCCESS ? NULL : kv_config->kvstore_main_instance;
@@ -305,10 +296,7 @@ BlockDevice *KVMap::get_internal_blockdevice_instance(const char *name)
305296
size_t key_index = 0;
306297

307298
int ret = config_lookup(name, &kv_config, &key_index);
308-
if (ret != MBED_SUCCESS) {
309-
goto exit;
310-
}
311-
exit:
299+
312300
_mutex->unlock();
313301

314302
return ret != MBED_SUCCESS ? NULL : kv_config->internal_bd;
@@ -323,10 +311,7 @@ BlockDevice *KVMap::get_external_blockdevice_instance(const char *name)
323311
size_t key_index = 0;
324312

325313
int ret = config_lookup(name, &kv_config, &key_index);
326-
if (ret != MBED_SUCCESS) {
327-
goto exit;
328-
}
329-
exit:
314+
330315
_mutex->unlock();
331316

332317
return ret != MBED_SUCCESS ? NULL : kv_config->external_bd;
@@ -341,10 +326,7 @@ FileSystem *KVMap::get_external_filesystem_instance(const char *name)
341326
size_t key_index = 0;
342327

343328
int ret = config_lookup(name, &kv_config, &key_index);
344-
if (ret != MBED_SUCCESS) {
345-
goto exit;
346-
}
347-
exit:
329+
348330
_mutex->unlock();
349331

350332
return ret != MBED_SUCCESS ? NULL : kv_config->external_fs;

features/storage/kvstore/securestore/SecureStore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int encrypt_decrypt_start(mbedtls_aes_context &enc_aes_ctx, uint8_t *iv, const c
109109
int encrypt_decrypt_data(mbedtls_aes_context &enc_aes_ctx, const uint8_t *in_buf,
110110
uint8_t *out_buf, uint32_t chunk_size, uint8_t *ctr_buf, size_t &aes_offs)
111111
{
112-
uint8_t stream_block[enc_block_size];
112+
uint8_t stream_block[enc_block_size] = { 0 };
113113

114114
return mbedtls_aes_crypt_ctr(&enc_aes_ctx, chunk_size, &aes_offs, ctr_buf,
115115
stream_block, in_buf, out_buf);

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ TDBStore::TDBStore(BlockDevice *bd) : _ram_table(0), _max_keys(0),
128128
_master_record_size(0), _is_initialized(false), _active_area(0), _active_area_version(0), _size(0),
129129
_prog_size(0), _work_buf(0), _key_buf(0), _variant_bd_erase_unit_size(false), _inc_set_handle(0)
130130
{
131+
for (int i = 0; i < _num_areas; i++) {
132+
_area_params[i] = { 0 };
133+
}
134+
for (int i = 0; i < _max_open_iterators; i++) {
135+
_iterator_table[i] = { 0 };
136+
}
131137
}
132138

133139
TDBStore::~TDBStore()
@@ -392,8 +398,8 @@ int TDBStore::set_start(set_handle_t *handle, const char *key, size_t final_data
392398
uint32_t create_flags)
393399
{
394400
int ret;
395-
uint32_t offset;
396-
uint32_t hash, ram_table_ind;
401+
uint32_t offset = 0;
402+
uint32_t hash = 0, ram_table_ind = 0;
397403
inc_set_handle_t *ih;
398404
bool need_gc = false;
399405

features/storage/nvstore/source/nvstore.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ NVStore::NVStore() : _init_done(0), _init_attempts(0), _active_area(0), _max_key
148148
_active_area_version(0), _free_space_offset(0), _size(0), _mutex(0), _offset_by_key(0), _flash(0),
149149
_min_prog_size(0), _page_buf(0)
150150
{
151+
for (int i = 0; i < NVSTORE_NUM_AREAS; i++) {
152+
_flash_area_params[i] = { 0 };
153+
}
151154
}
152155

153156
NVStore::~NVStore()
@@ -859,7 +862,9 @@ int NVStore::init()
859862
if (!_flash) {
860863
return NVSTORE_OS_ERROR;
861864
}
862-
_flash->init();
865+
if (_flash->init() < 0) {
866+
return NVSTORE_OS_ERROR;
867+
}
863868

864869
_min_prog_size = std::max(_flash->get_page_size(), (uint32_t)sizeof(nvstore_record_header_t));
865870
if (_min_prog_size > sizeof(nvstore_record_header_t)) {

0 commit comments

Comments
 (0)