Code cleanup: srand, PVS warnings (#1974)
* Remove srand invocation * PVS High priority fixes * PVS High errors part 2 * Furi: heap tracing inheritance * Furi add __builtin_unreachable to furi_thread_catch
This commit is contained in:
@@ -61,15 +61,20 @@ static void gpio_print_pins(void) {
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum { OK, ERR_CMD_SYNTAX, ERR_PIN, ERR_VALUE } GpioParseError;
|
||||
typedef enum {
|
||||
GpioParseReturnOk,
|
||||
GpioParseReturnCmdSyntaxError,
|
||||
GpioParseReturnPinError,
|
||||
GpioParseReturnValueError
|
||||
} GpioParseReturn;
|
||||
|
||||
static GpioParseError gpio_command_parse(FuriString* args, size_t* pin_num, uint8_t* value) {
|
||||
static GpioParseReturn gpio_command_parse(FuriString* args, size_t* pin_num, uint8_t* value) {
|
||||
FuriString* pin_name;
|
||||
pin_name = furi_string_alloc();
|
||||
|
||||
size_t ws = furi_string_search_char(args, ' ');
|
||||
if(ws == FURI_STRING_FAILURE) {
|
||||
return ERR_CMD_SYNTAX;
|
||||
return GpioParseReturnCmdSyntaxError;
|
||||
}
|
||||
|
||||
furi_string_set_n(pin_name, args, 0, ws);
|
||||
@@ -78,7 +83,7 @@ static GpioParseError gpio_command_parse(FuriString* args, size_t* pin_num, uint
|
||||
|
||||
if(!pin_name_to_int(pin_name, pin_num)) {
|
||||
furi_string_free(pin_name);
|
||||
return ERR_PIN;
|
||||
return GpioParseReturnPinError;
|
||||
}
|
||||
|
||||
furi_string_free(pin_name);
|
||||
@@ -88,10 +93,10 @@ static GpioParseError gpio_command_parse(FuriString* args, size_t* pin_num, uint
|
||||
} else if(!furi_string_cmp(args, "1")) {
|
||||
*value = 1;
|
||||
} else {
|
||||
return ERR_VALUE;
|
||||
return GpioParseReturnValueError;
|
||||
}
|
||||
|
||||
return OK;
|
||||
return GpioParseReturnOk;
|
||||
}
|
||||
|
||||
void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) {
|
||||
@@ -101,15 +106,15 @@ void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) {
|
||||
size_t num = 0;
|
||||
uint8_t value = 255;
|
||||
|
||||
GpioParseError err = gpio_command_parse(args, &num, &value);
|
||||
GpioParseReturn err = gpio_command_parse(args, &num, &value);
|
||||
|
||||
if(ERR_CMD_SYNTAX == err) {
|
||||
if(err == GpioParseReturnCmdSyntaxError) {
|
||||
cli_print_usage("gpio mode", "<pin_name> <0|1>", furi_string_get_cstr(args));
|
||||
return;
|
||||
} else if(ERR_PIN == err) {
|
||||
} else if(err == GpioParseReturnPinError) {
|
||||
gpio_print_pins();
|
||||
return;
|
||||
} else if(ERR_VALUE == err) {
|
||||
} else if(err == GpioParseReturnValueError) {
|
||||
printf("Value is invalid. Enter 1 for input or 0 for output");
|
||||
return;
|
||||
}
|
||||
@@ -161,15 +166,15 @@ void cli_command_gpio_set(Cli* cli, FuriString* args, void* context) {
|
||||
|
||||
size_t num = 0;
|
||||
uint8_t value = 0;
|
||||
GpioParseError err = gpio_command_parse(args, &num, &value);
|
||||
GpioParseReturn err = gpio_command_parse(args, &num, &value);
|
||||
|
||||
if(ERR_CMD_SYNTAX == err) {
|
||||
if(err == GpioParseReturnCmdSyntaxError) {
|
||||
cli_print_usage("gpio set", "<pin_name> <0|1>", furi_string_get_cstr(args));
|
||||
return;
|
||||
} else if(ERR_PIN == err) {
|
||||
} else if(err == GpioParseReturnPinError) {
|
||||
gpio_print_pins();
|
||||
return;
|
||||
} else if(ERR_VALUE == err) {
|
||||
} else if(err == GpioParseReturnValueError) {
|
||||
printf("Value is invalid. Enter 1 for high or 0 for low");
|
||||
return;
|
||||
}
|
||||
|
@@ -103,7 +103,7 @@ static int32_t vcp_worker(void* context) {
|
||||
while(1) {
|
||||
uint32_t flags =
|
||||
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_assert((flags & FuriFlagError) == 0);
|
||||
furi_assert(!(flags & FuriFlagError));
|
||||
|
||||
// VCP session opened
|
||||
if(flags & VcpEvtConnect) {
|
||||
@@ -303,7 +303,7 @@ static void vcp_on_cdc_control_line(void* context, uint8_t state) {
|
||||
static void vcp_on_cdc_rx(void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t ret = furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtRx);
|
||||
furi_check((ret & FuriFlagError) == 0);
|
||||
furi_check(!(ret & FuriFlagError));
|
||||
}
|
||||
|
||||
static void vcp_on_cdc_tx_complete(void* context) {
|
||||
|
@@ -167,7 +167,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) {
|
||||
void crypto_cli_has_key(Cli* cli, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
int key_slot = 0;
|
||||
uint8_t iv[16];
|
||||
uint8_t iv[16] = {0};
|
||||
|
||||
do {
|
||||
if(!args_read_int_and_trim(args, &key_slot) || !(key_slot > 0 && key_slot <= 100)) {
|
||||
@@ -249,7 +249,7 @@ void crypto_cli_store_key(Cli* cli, FuriString* args) {
|
||||
}
|
||||
|
||||
if(key_slot > 0) {
|
||||
uint8_t iv[16];
|
||||
uint8_t iv[16] = {0};
|
||||
if(key_slot > 1) {
|
||||
if(!furi_hal_crypto_store_load_key(key_slot - 1, iv)) {
|
||||
printf(
|
||||
|
@@ -436,7 +436,7 @@ void gui_add_framebuffer_callback(Gui* gui, GuiCanvasCommitCallback callback, vo
|
||||
const CanvasCallbackPair p = {callback, context};
|
||||
|
||||
gui_lock(gui);
|
||||
furi_assert(CanvasCallbackPairArray_count(gui->canvas_callback_pair, p) == 0);
|
||||
furi_assert(!CanvasCallbackPairArray_count(gui->canvas_callback_pair, p));
|
||||
CanvasCallbackPairArray_push_back(gui->canvas_callback_pair, p);
|
||||
gui_unlock(gui);
|
||||
|
||||
|
@@ -359,7 +359,7 @@ static int32_t browser_worker(void* context) {
|
||||
|
||||
BrowserWorker*
|
||||
file_browser_worker_alloc(FuriString* path, const char* filter_ext, bool skip_assets) {
|
||||
BrowserWorker* browser = malloc(sizeof(BrowserWorker));
|
||||
BrowserWorker* browser = malloc(sizeof(BrowserWorker)); //-V773
|
||||
|
||||
idx_last_array_init(browser->idx_last);
|
||||
|
||||
|
@@ -60,7 +60,7 @@ WidgetElement* widget_element_button_create(
|
||||
ButtonCallback callback,
|
||||
void* context) {
|
||||
// Allocate and init model
|
||||
GuiButtonModel* model = malloc(sizeof(GuiButtonModel));
|
||||
GuiButtonModel* model = malloc(sizeof(GuiButtonModel)); //-V773
|
||||
model->button_type = button_type;
|
||||
model->callback = callback;
|
||||
model->context = context;
|
||||
|
@@ -23,7 +23,7 @@ void view_dispatcher_free(ViewDispatcher* view_dispatcher) {
|
||||
gui_remove_view_port(view_dispatcher->gui, view_dispatcher->view_port);
|
||||
}
|
||||
// Crash if not all views were freed
|
||||
furi_assert(ViewDict_size(view_dispatcher->views) == 0);
|
||||
furi_assert(!ViewDict_size(view_dispatcher->views));
|
||||
|
||||
ViewDict_clear(view_dispatcher->views);
|
||||
// Free ViewPort
|
||||
@@ -157,7 +157,7 @@ void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_
|
||||
view_dispatcher->ongoing_input_view = NULL;
|
||||
}
|
||||
// Remove view
|
||||
ViewDict_erase(view_dispatcher->views, view_id);
|
||||
furi_check(ViewDict_erase(view_dispatcher->views, view_id));
|
||||
|
||||
view_set_update_callback(view, NULL);
|
||||
view_set_update_callback_context(view, NULL);
|
||||
|
@@ -269,7 +269,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con
|
||||
event.type = LoaderEventTypeApplicationStarted;
|
||||
furi_pubsub_publish(loader_instance->pubsub, &event);
|
||||
|
||||
if(!loader_instance->application->flags & FlipperApplicationFlagInsomniaSafe) {
|
||||
if(!(loader_instance->application->flags & FlipperApplicationFlagInsomniaSafe)) {
|
||||
furi_hal_power_insomnia_enter();
|
||||
}
|
||||
} else if(thread_state == FuriThreadStateStopped) {
|
||||
@@ -284,7 +284,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con
|
||||
loader_instance->application_arguments = NULL;
|
||||
}
|
||||
|
||||
if(!loader_instance->application->flags & FlipperApplicationFlagInsomniaSafe) {
|
||||
if(!(loader_instance->application->flags & FlipperApplicationFlagInsomniaSafe)) {
|
||||
furi_hal_power_insomnia_exit();
|
||||
}
|
||||
loader_unlock(instance);
|
||||
|
@@ -275,7 +275,7 @@ static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args
|
||||
uint32_t buffer_size;
|
||||
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
|
||||
|
||||
if(parsed_count == EOF || parsed_count != 1) {
|
||||
if(parsed_count != 1) {
|
||||
storage_cli_print_usage();
|
||||
} else if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
uint64_t file_size = storage_file_size(file);
|
||||
@@ -315,7 +315,7 @@ static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args
|
||||
uint32_t buffer_size;
|
||||
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
|
||||
|
||||
if(parsed_count == EOF || parsed_count != 1) {
|
||||
if(parsed_count != 1) {
|
||||
storage_cli_print_usage();
|
||||
} else {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
|
@@ -545,8 +545,8 @@ static FS_Error
|
||||
|
||||
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error;
|
||||
const char* new_path_tmp;
|
||||
FuriString* new_path_next;
|
||||
const char* new_path_tmp = NULL;
|
||||
FuriString* new_path_next = NULL;
|
||||
new_path_next = furi_string_alloc();
|
||||
|
||||
FileInfo fileinfo;
|
||||
|
Reference in New Issue
Block a user