From 9363bb778ab4e52da98d742a5ef3354bfceebd7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Rist=20Sk=C3=B8ien?= Date: Mon, 11 Nov 2024 12:32:14 +0100 Subject: [PATCH] Applications: Audio: Resolved coverity issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - OCT-3195 - Resolved Coverity issues and small renaming Signed-off-by: Kristoffer Rist Skøien --- applications/nrf5340_audio/src/modules/lc3_streamer.c | 5 ++++- applications/nrf5340_audio/src/modules/sd_card.c | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/applications/nrf5340_audio/src/modules/lc3_streamer.c b/applications/nrf5340_audio/src/modules/lc3_streamer.c index a3b961e042b0..347f633edb31 100644 --- a/applications/nrf5340_audio/src/modules/lc3_streamer.c +++ b/applications/nrf5340_audio/src/modules/lc3_streamer.c @@ -67,6 +67,9 @@ struct lc3_stream { }; static struct lc3_stream streams[CONFIG_SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS]; +#if (CONFIG_SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS > UINT8_MAX) +#error "CONFIG_SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS is larger than UINT8_MAX" +#endif static bool initialized; @@ -353,7 +356,7 @@ int lc3_streamer_stream_register(const char *const filename, uint8_t *const stre bool free_slot_found = false; - for (int i = 0; i < ARRAY_SIZE(streams); i++) { + for (uint8_t i = 0; i < ARRAY_SIZE(streams); i++) { if (streams[i].state == STREAM_IDLE) { LOG_DBG("Found free stream slot %d", i); *streamer_idx = i; diff --git a/applications/nrf5340_audio/src/modules/sd_card.c b/applications/nrf5340_audio/src/modules/sd_card.c index 91f116b5a6eb..dee80d7e3eb5 100644 --- a/applications/nrf5340_audio/src/modules/sd_card.c +++ b/applications/nrf5340_audio/src/modules/sd_card.c @@ -216,7 +216,7 @@ int sd_card_list_files(char const *const path, char *buf, size_t *buf_size, bool return ret; } } else { - if (strlen(path) > CONFIG_FS_FATFS_MAX_LFN) { + if (strlen(path) > PATH_MAX_LEN) { LOG_ERR("Path is too long"); return -FR_INVALID_NAME; } @@ -290,7 +290,7 @@ int sd_card_open_write_close(char const *const filename, char const *const data, return -ENODEV; } - if (strlen(filename) > CONFIG_FS_FATFS_MAX_LFN) { + if (strlen(filename) > PATH_MAX_LEN) { LOG_ERR("Filename is too long"); return -ENAMETOOLONG; } @@ -338,7 +338,7 @@ int sd_card_open_read_close(char const *const filename, char *const buf, size_t return -ENODEV; } - if (strlen(filename) > CONFIG_FS_FATFS_MAX_LFN) { + if (strlen(filename) > PATH_MAX_LEN) { LOG_ERR("Filename is too long"); return -FR_INVALID_NAME; } @@ -376,7 +376,7 @@ int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry) { int ret; char abs_path_name[PATH_MAX_LEN + 1] = SD_ROOT_PATH; - size_t avilable_path_space = PATH_MAX_LEN - strlen(SD_ROOT_PATH); + size_t available_path_space = PATH_MAX_LEN - strlen(SD_ROOT_PATH); if (!sd_init_success) { return -ENODEV; @@ -392,7 +392,7 @@ int sd_card_open(char const *const filename, struct fs_file_t *f_seg_read_entry) return -EINVAL; } - strncat(abs_path_name, filename, avilable_path_space); + strncat(abs_path_name, filename, available_path_space); LOG_INF("abs path name:\t%s", abs_path_name);