From 8582670a341030e43ddf277aad625e9063802cd7 Mon Sep 17 00:00:00 2001 From: Georgii Surkov <37121527+gsurkov@users.noreply.github.com> Date: Mon, 26 Dec 2022 15:13:30 +0300 Subject: [PATCH] [FL-2811] Fix PVS-Studio warnings (#2142) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく Co-authored-by: gornekich --- .github/workflows/pvs_studio.yml | 3 +- .pvsconfig | 23 +++++++ .pvsoptions | 2 +- .../unit_tests/float_tools/float_tools_test.c | 60 ++++++++++++++++ applications/debug/unit_tests/test_index.c | 2 + .../main/archive/helpers/archive_apps.c | 2 +- .../main/archive/helpers/archive_favorites.c | 2 +- .../archive/scenes/archive_scene_browser.c | 2 +- applications/main/bad_usb/bad_usb_script.c | 14 ++-- applications/main/fap_loader/fap_loader_app.c | 4 +- applications/main/ibutton/ibutton.c | 6 +- applications/main/infrared/infrared.c | 4 +- .../main/infrared/infrared_brute_force.c | 2 +- applications/main/infrared/infrared_cli.c | 10 +-- applications/main/infrared/infrared_remote.c | 14 ++-- applications/main/infrared/infrared_signal.c | 6 +- .../infrared/scenes/infrared_scene_debug.c | 2 +- applications/main/lfrfid/lfrfid.c | 4 +- applications/main/lfrfid/lfrfid_cli.c | 26 +++---- .../main/nfc/scenes/nfc_scene_emulate_uid.c | 2 +- .../nfc/scenes/nfc_scene_mf_classic_emulate.c | 2 +- .../nfc/scenes/nfc_scene_mf_classic_keys.c | 4 +- .../scenes/nfc_scene_mf_classic_keys_list.c | 2 +- .../nfc_scene_mf_desfire_read_success.c | 6 +- .../scenes/nfc_scene_mf_ultralight_emulate.c | 2 +- .../main/nfc/scenes/nfc_scene_nfc_data_info.c | 8 +-- applications/main/nfc/scenes/nfc_scene_read.c | 2 +- .../main/nfc/scenes/nfc_scene_save_name.c | 2 +- .../subghz_frequency_analyzer_worker.c | 5 +- .../subghz/scenes/subghz_scene_read_raw.c | 3 +- .../subghz/scenes/subghz_scene_save_name.c | 2 +- .../subghz/scenes/subghz_scene_set_type.c | 2 +- applications/main/subghz/subghz_cli.c | 19 +++--- applications/main/subghz/subghz_i.c | 5 +- .../subghz/views/subghz_frequency_analyzer.c | 13 ++-- .../main/subghz/views/subghz_read_raw.c | 4 +- .../main/subghz/views/subghz_test_packet.c | 2 +- applications/main/u2f/scenes/u2f_scene_main.c | 2 +- applications/main/u2f/u2f_data.c | 6 +- applications/main/u2f/u2f_hid.c | 6 +- .../plugins/dap_link/usb/dap_v2_usb.c | 8 +-- .../plugins/hid_app/views/hid_keyboard.c | 21 ++---- .../plugins/music_player/music_player.c | 2 +- .../picopass/lib/loclass/optimized_cipher.c | 35 +++------- .../plugins/picopass/picopass_worker.c | 10 ++- .../scenes/picopass_scene_save_name.c | 2 +- .../scenes/signal_gen_scene_pwm.c | 4 +- .../signal_generator/views/signal_gen_pwm.c | 6 +- applications/plugins/snake_game/snake_game.c | 4 +- .../weather_station/protocols/oregon2.c | 2 +- .../weather_station/protocols/oregon_v1.c | 2 +- .../weather_station/protocols/ws_generic.c | 4 +- .../views/weather_station_receiver_info.c | 5 +- .../weather_station/weather_station_app_i.c | 3 - .../weather_station/weather_station_history.c | 2 +- applications/services/bt/bt_service/bt.c | 6 +- .../services/bt/bt_service/bt_keys_storage.c | 2 +- applications/services/cli/cli.c | 4 +- applications/services/cli/cli_command_gpio.c | 68 +++++++++---------- applications/services/cli/cli_commands.c | 14 ++-- applications/services/crypto/crypto_cli.c | 2 +- .../desktop/animations/animation_manager.c | 10 ++- .../desktop/animations/animation_storage.c | 5 +- .../services/desktop/helpers/slideshow.c | 2 +- .../desktop/views/desktop_view_debug.c | 8 +-- .../desktop/views/desktop_view_lock_menu.c | 6 +- .../desktop/views/desktop_view_pin_timeout.c | 2 +- .../services/dolphin/helpers/dolphin_state.c | 2 +- applications/services/gui/elements.c | 2 +- .../services/gui/modules/button_panel.c | 2 +- .../services/gui/modules/byte_input.c | 9 ++- .../services/gui/modules/file_browser.c | 6 +- .../gui/modules/file_browser_worker.c | 4 +- applications/services/gui/modules/submenu.c | 10 +-- .../services/gui/modules/text_input.c | 15 ++-- .../services/gui/modules/validators.c | 7 +- .../services/gui/modules/variable_item_list.c | 4 +- .../widget_elements/widget_element_button.c | 4 +- .../widget_elements/widget_element_string.c | 2 +- .../widget_element_string_multiline.c | 2 +- .../widget_elements/widget_element_text_box.c | 2 +- .../widget_element_text_scroll.c | 2 +- applications/services/gui/view.c | 4 +- applications/services/input/input.c | 4 +- applications/services/input/input_cli.c | 2 +- applications/services/loader/loader.c | 2 +- .../power/power_service/views/power_off.c | 2 +- applications/services/rpc/rpc_app.c | 22 +++--- applications/services/rpc/rpc_cli.c | 2 +- applications/services/rpc/rpc_debug.c | 14 ++-- applications/services/rpc/rpc_storage.c | 2 +- applications/services/rpc/rpc_system.c | 1 - .../services/storage/storage_external_api.c | 8 +-- applications/services/storage/storage_glue.c | 3 +- .../services/storage/storages/storage_int.c | 46 ++++--------- applications/settings/about/about.c | 4 +- .../scenes/desktop_settings_scene_favorite.c | 2 +- .../desktop_settings_scene_pin_setup_howto.c | 4 +- .../desktop_settings_scene_pin_setup_howto2.c | 4 +- .../power_settings_app/views/battery_info.c | 12 ++-- .../storage_settings_scene_format_confirm.c | 2 - .../scenes/storage_settings_scene_sd_info.c | 2 - .../storage_settings_scene_unmount_confirm.c | 2 - .../updater/util/update_task_worker_backup.c | 2 +- .../updater/util/update_task_worker_flasher.c | 8 +-- debug/gdbinit | 10 +++ firmware/targets/f7/Src/update.c | 2 +- firmware/targets/f7/ble_glue/ble_glue.c | 22 +++--- firmware/targets/f7/ble_glue/gap.c | 4 +- firmware/targets/f7/ble_glue/hid_service.c | 2 +- firmware/targets/f7/ble_glue/hw_ipcc.c | 4 +- firmware/targets/f7/fatfs/stm32_adafruit_sd.c | 10 +-- firmware/targets/f7/furi_hal/furi_hal_bt.c | 2 +- .../targets/f7/furi_hal/furi_hal_bt_hid.c | 6 +- .../targets/f7/furi_hal/furi_hal_i2c_config.c | 4 +- .../targets/f7/furi_hal/furi_hal_memory.c | 6 +- firmware/targets/f7/furi_hal/furi_hal_nfc.c | 10 +-- firmware/targets/f7/furi_hal/furi_hal_os.c | 4 +- firmware/targets/f7/furi_hal/furi_hal_pwm.c | 2 +- firmware/targets/f7/furi_hal/furi_hal_rtc.c | 2 +- firmware/targets/f7/furi_hal/furi_hal_uart.c | 4 +- .../targets/f7/furi_hal/furi_hal_usb_hid.c | 4 +- .../targets/f7/furi_hal/furi_hal_version.c | 2 - furi/core/check.c | 2 +- furi/core/core_defines.h | 2 +- furi/core/event_flag.c | 6 +- furi/core/memmgr_heap.c | 5 +- furi/core/message_queue.c | 5 +- furi/core/mutex.c | 2 + furi/core/stream_buffer.c | 10 ++- furi/core/string.c | 10 +-- furi/core/thread.c | 8 +-- furi/core/timer.c | 44 ++++-------- .../view_modules/popup_vm.cpp | 3 +- lib/drivers/cc1101.c | 2 +- lib/drivers/lp5562.c | 4 +- lib/flipper_application/elf/elf_file.c | 22 +++--- lib/flipper_format/flipper_format_stream.c | 4 +- .../common/infrared_common_decoder.c | 2 +- .../common/infrared_common_encoder.c | 1 - .../common/infrared_common_i.h | 2 +- lib/infrared/worker/infrared_transmit.c | 5 +- lib/infrared/worker/infrared_worker.c | 6 +- lib/infrared/worker/infrared_worker.h | 2 +- lib/lfrfid/lfrfid_raw_worker.c | 5 +- lib/lfrfid/lfrfid_worker.c | 4 +- lib/lfrfid/lfrfid_worker_modes.c | 6 +- lib/lfrfid/protocols/protocol_indala26.c | 2 +- lib/lfrfid/protocols/protocol_pac_stanley.c | 8 +-- lib/lfrfid/tools/bit_lib.c | 10 +-- lib/lfrfid/tools/bit_lib.h | 8 +-- lib/lfrfid/tools/varint_pair.c | 4 +- lib/nfc/helpers/mf_classic_dict.c | 10 +-- lib/nfc/helpers/reader_analyzer.c | 4 +- lib/nfc/nfc_device.c | 4 +- lib/nfc/nfc_worker.c | 22 +++--- lib/nfc/parsers/all_in_one.c | 14 +--- lib/nfc/parsers/plantain_4k_parser.c | 19 +----- lib/nfc/parsers/plantain_parser.c | 19 +----- lib/nfc/parsers/two_cities.c | 18 +---- lib/nfc/protocols/crypto1.c | 3 +- lib/nfc/protocols/mifare_classic.c | 45 +++++------- lib/nfc/protocols/mifare_desfire.c | 16 +++-- lib/nfc/protocols/mifare_ultralight.c | 24 +++---- lib/one_wire/ibutton/ibutton_key.c | 2 - lib/one_wire/ibutton/ibutton_worker_modes.c | 1 - lib/one_wire/ibutton/ibutton_writer.c | 2 +- .../ibutton/protocols/protocol_cyfral.c | 6 +- .../ibutton/protocols/protocol_metakom.c | 8 +-- lib/one_wire/one_wire_slave.c | 12 ++-- lib/print/printf_tiny.c | 2 +- lib/subghz/blocks/generic.c | 2 +- lib/subghz/blocks/math.h | 3 +- lib/subghz/protocols/bett.c | 1 - lib/subghz/protocols/holtek.c | 1 - lib/subghz/protocols/keeloq.c | 9 +-- lib/subghz/protocols/kia.c | 2 +- lib/subghz/protocols/megacode.c | 2 +- lib/subghz/protocols/nero_radio.c | 2 +- lib/subghz/protocols/princeton.c | 2 +- lib/subghz/protocols/princeton_for_testing.c | 4 +- lib/subghz/protocols/scher_khan.c | 4 +- lib/subghz/protocols/secplus_v1.c | 8 +-- lib/subghz/protocols/secplus_v2.c | 20 +++--- lib/subghz/protocols/smc5326.c | 4 +- lib/subghz/subghz_file_encoder_worker.c | 2 +- lib/subghz/subghz_keystore.c | 12 ++-- lib/subghz/subghz_setting.c | 10 ++- lib/toolbox/dir_walk.c | 7 +- lib/toolbox/float_tools.c | 8 +++ lib/toolbox/float_tools.h | 19 ++++++ lib/toolbox/hex.c | 16 ++--- lib/toolbox/md5.c | 12 ++-- lib/toolbox/sha256.c | 10 +-- lib/toolbox/stream/stream.c | 4 +- lib/toolbox/tar/tar_archive.c | 4 +- lib/toolbox/varint.c | 4 +- lib/update_util/dfu_file.c | 2 +- lib/update_util/resources/manifest.c | 2 +- lib/update_util/update_operation.c | 4 +- scripts/fbt_tools/fbt_debugopts.py | 4 +- 201 files changed, 719 insertions(+), 743 deletions(-) create mode 100644 applications/debug/unit_tests/float_tools/float_tools_test.c create mode 100644 debug/gdbinit create mode 100644 lib/toolbox/float_tools.c create mode 100644 lib/toolbox/float_tools.h diff --git a/.github/workflows/pvs_studio.yml b/.github/workflows/pvs_studio.yml index 5bb04afc..c521fbca 100644 --- a/.github/workflows/pvs_studio.yml +++ b/.github/workflows/pvs_studio.yml @@ -50,7 +50,7 @@ jobs: - name: 'Generate compile_comands.json' run: | - ./fbt COMPACT=1 version_json proto_ver icons firmware_cdb dolphin_internal dolphin_blocking _fap_icons + ./fbt COMPACT=1 version_json proto_ver icons firmware_cdb dolphin_internal dolphin_blocking _fap_icons api_syms - name: 'Static code analysis' run: | @@ -58,6 +58,7 @@ jobs: pvs-studio-analyzer credentials ${{ secrets.PVS_STUDIO_CREDENTIALS }} pvs-studio-analyzer analyze \ @.pvsoptions \ + -C gccarm \ -j$(grep -c processor /proc/cpuinfo) \ -f build/f7-firmware-DC/compile_commands.json \ -o PVS-Studio.log diff --git a/.pvsconfig b/.pvsconfig index 5f1ffb7c..a9ab9c9f 100644 --- a/.pvsconfig +++ b/.pvsconfig @@ -1,4 +1,5 @@ # MLib macros we can't do much about. +//-V:M_LET:1048,1044 //-V:M_EACH:1048,1044 //-V:ARRAY_DEF:760,747,568,776,729,712,654 //-V:LIST_DEF:760,747,568,712,729,654,776 @@ -16,8 +17,30 @@ # Potentially null argument warnings //-V:memset:575 //-V:memcpy:575 +//-V:memcmp:575 +//-V:strlen:575 //-V:strcpy:575 +//-V:strncpy:575 //-V:strchr:575 # For loop warning on M_FOREACH //-V:for:1044 + +# Bitwise OR +//-V:bit:792 + +# Do not complain about similar code +//-V::525 + +# Common embedded development pointer operations +//-V::566 +//-V::1032 + +# Warnings about length mismatch +//-V:property_value_out:666 + +# Model-related warnings +//-V:with_view_model:1044,1048 + +# Functions that always return the same error code +//-V:picopass_device_decrypt:1048 diff --git a/.pvsoptions b/.pvsoptions index 4c80ab66..31bc4b80 100644 --- a/.pvsoptions +++ b/.pvsoptions @@ -1 +1 @@ ---rules-config .pvsconfig -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/micro-ecc -e lib/microtar -e lib/mlib -e lib/qrcode -e lib/ST25RFAL002 -e lib/STM32CubeWB -e lib/u8g2 -e */arm-none-eabi/* +--rules-config .pvsconfig -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/micro-ecc -e lib/microtar -e lib/mlib -e lib/qrcode -e lib/ST25RFAL002 -e lib/STM32CubeWB -e lib/u8g2 -e lib/nanopb -e */arm-none-eabi/* -e applications/plugins/dap_link/lib/free-dap diff --git a/applications/debug/unit_tests/float_tools/float_tools_test.c b/applications/debug/unit_tests/float_tools/float_tools_test.c new file mode 100644 index 00000000..fc5b4ecf --- /dev/null +++ b/applications/debug/unit_tests/float_tools/float_tools_test.c @@ -0,0 +1,60 @@ +#include +#include + +#include "../minunit.h" + +MU_TEST(float_tools_equal_test) { + mu_check(float_is_equal(FLT_MAX, FLT_MAX)); + mu_check(float_is_equal(FLT_MIN, FLT_MIN)); + mu_check(float_is_equal(-FLT_MAX, -FLT_MAX)); + mu_check(float_is_equal(-FLT_MIN, -FLT_MIN)); + + mu_check(!float_is_equal(FLT_MIN, FLT_MAX)); + mu_check(!float_is_equal(-FLT_MIN, FLT_MAX)); + mu_check(!float_is_equal(FLT_MIN, -FLT_MAX)); + mu_check(!float_is_equal(-FLT_MIN, -FLT_MAX)); + + const float pi = 3.14159f; + mu_check(float_is_equal(pi, pi)); + mu_check(float_is_equal(-pi, -pi)); + mu_check(!float_is_equal(pi, -pi)); + mu_check(!float_is_equal(-pi, pi)); + + const float one_third = 1.f / 3.f; + const float one_third_dec = 0.3333333f; + mu_check(one_third != one_third_dec); + mu_check(float_is_equal(one_third, one_third_dec)); + + const float big_num = 1.e12f; + const float med_num = 95.389f; + const float smol_num = 1.e-12f; + mu_check(float_is_equal(big_num, big_num)); + mu_check(float_is_equal(med_num, med_num)); + mu_check(float_is_equal(smol_num, smol_num)); + mu_check(!float_is_equal(smol_num, big_num)); + mu_check(!float_is_equal(med_num, smol_num)); + mu_check(!float_is_equal(big_num, med_num)); + + const float more_than_one = 1.f + FLT_EPSILON; + const float less_than_one = 1.f - FLT_EPSILON; + mu_check(!float_is_equal(more_than_one, less_than_one)); + mu_check(!float_is_equal(more_than_one, -less_than_one)); + mu_check(!float_is_equal(-more_than_one, less_than_one)); + mu_check(!float_is_equal(-more_than_one, -less_than_one)); + + const float slightly_more_than_one = 1.f + FLT_EPSILON / 2.f; + const float slightly_less_than_one = 1.f - FLT_EPSILON / 2.f; + mu_check(float_is_equal(slightly_more_than_one, slightly_less_than_one)); + mu_check(float_is_equal(-slightly_more_than_one, -slightly_less_than_one)); + mu_check(!float_is_equal(slightly_more_than_one, -slightly_less_than_one)); + mu_check(!float_is_equal(-slightly_more_than_one, slightly_less_than_one)); +} + +MU_TEST_SUITE(float_tools_suite) { + MU_RUN_TEST(float_tools_equal_test); +} + +int run_minunit_test_float_tools() { + MU_RUN_SUITE(float_tools_suite); + return MU_EXIT_CODE; +} diff --git a/applications/debug/unit_tests/test_index.c b/applications/debug/unit_tests/test_index.c index 5bc53c82..ccf47153 100644 --- a/applications/debug/unit_tests/test_index.c +++ b/applications/debug/unit_tests/test_index.c @@ -24,6 +24,7 @@ int run_minunit_test_protocol_dict(); int run_minunit_test_lfrfid_protocols(); int run_minunit_test_nfc(); int run_minunit_test_bit_lib(); +int run_minunit_test_float_tools(); int run_minunit_test_bt(); typedef int (*UnitTestEntry)(); @@ -50,6 +51,7 @@ const UnitTest unit_tests[] = { {.name = "protocol_dict", .entry = run_minunit_test_protocol_dict}, {.name = "lfrfid", .entry = run_minunit_test_lfrfid_protocols}, {.name = "bit_lib", .entry = run_minunit_test_bit_lib}, + {.name = "float_tools", .entry = run_minunit_test_float_tools}, {.name = "bt", .entry = run_minunit_test_bt}, }; diff --git a/applications/main/archive/helpers/archive_apps.c b/applications/main/archive/helpers/archive_apps.c index 72084f11..c8ad6762 100644 --- a/applications/main/archive/helpers/archive_apps.c +++ b/applications/main/archive/helpers/archive_apps.c @@ -13,7 +13,7 @@ ArchiveAppTypeEnum archive_get_app_type(const char* path) { } app_name++; - for(size_t i = 0; i < COUNT_OF(known_apps); i++) { + for(size_t i = 0; i < COUNT_OF(known_apps); i++) { //-V1008 if(strncmp(app_name, known_apps[i], strlen(known_apps[i])) == 0) { return i; } diff --git a/applications/main/archive/helpers/archive_favorites.c b/applications/main/archive/helpers/archive_favorites.c index 86a294f7..8bbcb521 100644 --- a/applications/main/archive/helpers/archive_favorites.c +++ b/applications/main/archive/helpers/archive_favorites.c @@ -177,7 +177,7 @@ bool archive_favorites_read(void* context) { archive_set_item_count(browser, file_count); - if(need_refresh) { + if(need_refresh) { //-V547 archive_favourites_rescan(); } diff --git a/applications/main/archive/scenes/archive_scene_browser.c b/applications/main/archive/scenes/archive_scene_browser.c index 2f469354..c28f91f5 100644 --- a/applications/main/archive/scenes/archive_scene_browser.c +++ b/applications/main/archive/scenes/archive_scene_browser.c @@ -116,7 +116,7 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) { case ArchiveBrowserEventFileMenuPin: { const char* name = archive_get_name(browser); if(favorites) { - archive_favorites_delete(name); + archive_favorites_delete("%s", name); archive_file_array_rm_selected(browser); archive_show_file_menu(browser, false); } else if(archive_is_known_app(selected->type)) { diff --git a/applications/main/bad_usb/bad_usb_script.c b/applications/main/bad_usb/bad_usb_script.c index aa465351..92c7466f 100644 --- a/applications/main/bad_usb/bad_usb_script.c +++ b/applications/main/bad_usb/bad_usb_script.c @@ -218,8 +218,8 @@ static bool ducky_string(const char* param) { } static uint16_t ducky_get_keycode(const char* param, bool accept_chars) { - for(uint8_t i = 0; i < (sizeof(ducky_keys) / sizeof(ducky_keys[0])); i++) { - uint8_t key_cmd_len = strlen(ducky_keys[i].name); + for(size_t i = 0; i < (sizeof(ducky_keys) / sizeof(ducky_keys[0])); i++) { + size_t key_cmd_len = strlen(ducky_keys[i].name); if((strncmp(param, ducky_keys[i].name, key_cmd_len) == 0) && (ducky_is_line_end(param[key_cmd_len]))) { return ducky_keys[i].keycode; @@ -417,7 +417,7 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil return 0; } else if(delay_val < 0) { // Script error bad_usb->st.error_line = bad_usb->st.line_cur - 1; - FURI_LOG_E(WORKER_TAG, "Unknown command at line %u", bad_usb->st.line_cur - 1); + FURI_LOG_E(WORKER_TAG, "Unknown command at line %u", bad_usb->st.line_cur - 1U); return SCRIPT_STATE_ERROR; } else { return (delay_val + bad_usb->defdelay); @@ -596,7 +596,9 @@ static int32_t bad_usb_worker(void* context) { } bad_usb->st.state = worker_state; continue; - } else if((flags == FuriFlagErrorTimeout) || (flags == FuriFlagErrorResource)) { + } else if( + (flags == (unsigned)FuriFlagErrorTimeout) || + (flags == (unsigned)FuriFlagErrorResource)) { if(delay_val > 0) { bad_usb->st.delay_remain--; continue; @@ -650,7 +652,7 @@ static int32_t bad_usb_worker(void* context) { BadUsbScript* bad_usb_script_open(FuriString* file_path) { furi_assert(file_path); - BadUsbScript* bad_usb = malloc(sizeof(BadUsbScript)); //-V773 + BadUsbScript* bad_usb = malloc(sizeof(BadUsbScript)); bad_usb->file_path = furi_string_alloc(); furi_string_set(bad_usb->file_path, file_path); @@ -660,7 +662,7 @@ BadUsbScript* bad_usb_script_open(FuriString* file_path) { bad_usb->thread = furi_thread_alloc_ex("BadUsbWorker", 2048, bad_usb_worker, bad_usb); furi_thread_start(bad_usb->thread); return bad_usb; -} +} //-V773 void bad_usb_script_close(BadUsbScript* bad_usb) { furi_assert(bad_usb); diff --git a/applications/main/fap_loader/fap_loader_app.c b/applications/main/fap_loader/fap_loader_app.c index 90186674..7911aa06 100644 --- a/applications/main/fap_loader/fap_loader_app.c +++ b/applications/main/fap_loader/fap_loader_app.c @@ -156,7 +156,7 @@ static bool fap_loader_select_app(FapLoader* loader) { } static FapLoader* fap_loader_alloc(const char* path) { - FapLoader* loader = malloc(sizeof(FapLoader)); //-V773 + FapLoader* loader = malloc(sizeof(FapLoader)); //-V799 loader->fap_path = furi_string_alloc_set(path); loader->storage = furi_record_open(RECORD_STORAGE); loader->dialogs = furi_record_open(RECORD_DIALOGS); @@ -167,7 +167,7 @@ static FapLoader* fap_loader_alloc(const char* path) { loader->view_dispatcher, loader->gui, ViewDispatcherTypeFullscreen); view_dispatcher_add_view(loader->view_dispatcher, 0, loading_get_view(loader->loading)); return loader; -} +} //-V773 static void fap_loader_free(FapLoader* loader) { view_dispatcher_remove_view(loader->view_dispatcher, 0); diff --git a/applications/main/ibutton/ibutton.c b/applications/main/ibutton/ibutton.c index b7c8223b..85212f42 100644 --- a/applications/main/ibutton/ibutton.c +++ b/applications/main/ibutton/ibutton.c @@ -278,7 +278,7 @@ bool ibutton_save_key(iButton* ibutton, const char* key_name) { flipper_format_free(file); - if(!result) { + if(!result) { //-V547 dialog_message_show_storage_error(ibutton->dialogs, "Cannot save\nkey file"); } @@ -302,7 +302,7 @@ void ibutton_text_store_set(iButton* ibutton, const char* text, ...) { } void ibutton_text_store_clear(iButton* ibutton) { - memset(ibutton->text_store, 0, IBUTTON_TEXT_STORE_SIZE); + memset(ibutton->text_store, 0, IBUTTON_TEXT_STORE_SIZE + 1); } void ibutton_notification_message(iButton* ibutton, uint32_t message) { @@ -343,7 +343,7 @@ int32_t ibutton_app(void* p) { } else { view_dispatcher_attach_to_gui( ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen); - if(key_loaded) { + if(key_loaded) { //-V547 scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate); DOLPHIN_DEED(DolphinDeedIbuttonEmulate); } else { diff --git a/applications/main/infrared/infrared.c b/applications/main/infrared/infrared.c index f62db14c..9d78a09b 100644 --- a/applications/main/infrared/infrared.c +++ b/applications/main/infrared/infrared.c @@ -360,7 +360,7 @@ void infrared_text_store_set(Infrared* infrared, uint32_t bank, const char* text } void infrared_text_store_clear(Infrared* infrared, uint32_t bank) { - memset(infrared->text_store[bank], 0, INFRARED_TEXT_STORE_SIZE); + memset(infrared->text_store[bank], 0, INFRARED_TEXT_STORE_SIZE + 1); } void infrared_play_notification_message(Infrared* infrared, uint32_t message) { @@ -455,7 +455,7 @@ int32_t infrared_app(void* p) { } else { view_dispatcher_attach_to_gui( infrared->view_dispatcher, infrared->gui, ViewDispatcherTypeFullscreen); - if(is_remote_loaded) { + if(is_remote_loaded) { //-V547 scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote); } else { scene_manager_next_scene(infrared->scene_manager, InfraredSceneStart); diff --git a/applications/main/infrared/infrared_brute_force.c b/applications/main/infrared/infrared_brute_force.c index 3f426f1d..3ca5c409 100644 --- a/applications/main/infrared/infrared_brute_force.c +++ b/applications/main/infrared/infrared_brute_force.c @@ -65,7 +65,7 @@ bool infrared_brute_force_calculate_messages(InfraredBruteForce* brute_force) { while(flipper_format_read_string(ff, "name", signal_name)) { InfraredBruteForceRecord* record = InfraredBruteForceRecordDict_get(brute_force->records, signal_name); - if(record) { + if(record) { //-V547 ++(record->count); } } diff --git a/applications/main/infrared/infrared_cli.c b/applications/main/infrared/infrared_cli.c index 8f35a8fd..5f5e2d4b 100644 --- a/applications/main/infrared/infrared_cli.c +++ b/applications/main/infrared/infrared_cli.c @@ -55,7 +55,7 @@ static void signal_received_callback(void* context, InfraredWorkerSignal* receiv size_t timings_cnt; infrared_worker_get_raw_signal(received_signal, &timings, &timings_cnt); - buf_cnt = snprintf(buf, sizeof(buf), "RAW, %d samples:\r\n", timings_cnt); + buf_cnt = snprintf(buf, sizeof(buf), "RAW, %zu samples:\r\n", timings_cnt); cli_write(cli, (uint8_t*)buf, buf_cnt); for(size_t i = 0; i < timings_cnt; ++i) { buf_cnt = snprintf(buf, sizeof(buf), "%lu ", timings[i]); @@ -276,7 +276,9 @@ static bool infrared_cli_decode_file(FlipperFormat* input_file, FlipperFormat* o } InfraredRawSignal* raw_signal = infrared_signal_get_raw_signal(signal); printf( - "Raw signal: %s, %u samples\r\n", furi_string_get_cstr(tmp), raw_signal->timings_size); + "Raw signal: %s, %zu samples\r\n", + furi_string_get_cstr(tmp), + raw_signal->timings_size); if(!infrared_cli_decode_raw_signal( raw_signal, decoder, output_file, furi_string_get_cstr(tmp))) break; @@ -382,7 +384,7 @@ static void infrared_cli_list_remote_signals(FuriString* remote_name) { while(flipper_format_read_string(ff, "name", signal_name)) { furi_string_set_str(key, furi_string_get_cstr(signal_name)); int* v = dict_signals_get(signals_dict, key); - if(v != NULL) { + if(v != NULL) { //-V547 (*v)++; max = M_MAX(*v, max); } else { @@ -436,7 +438,7 @@ static void break; } - printf("Sending %ld signal(s)...\r\n", record_count); + printf("Sending %lu signal(s)...\r\n", record_count); printf("Press Ctrl-C to stop.\r\n"); int records_sent = 0; diff --git a/applications/main/infrared/infrared_remote.c b/applications/main/infrared/infrared_remote.c index 3a528a65..d3dfc2cc 100644 --- a/applications/main/infrared/infrared_remote.c +++ b/applications/main/infrared/infrared_remote.c @@ -145,15 +145,14 @@ bool infrared_remote_load(InfraredRemote* remote, FuriString* path) { buf = furi_string_alloc(); FURI_LOG_I(TAG, "load file: \'%s\'", furi_string_get_cstr(path)); - bool success = flipper_format_buffered_file_open_existing(ff, furi_string_get_cstr(path)); + bool success = false; - if(success) { + do { + if(!flipper_format_buffered_file_open_existing(ff, furi_string_get_cstr(path))) break; uint32_t version; - success = flipper_format_read_header(ff, buf, &version) && - !furi_string_cmp(buf, "IR signals file") && (version == 1); - } + if(!flipper_format_read_header(ff, buf, &version)) break; + if(!furi_string_equal(buf, "IR signals file") || (version != 1)) break; - if(success) { path_extract_filename(path, buf, true); infrared_remote_clear_buttons(remote); infrared_remote_set_name(remote, furi_string_get_cstr(buf)); @@ -169,7 +168,8 @@ bool infrared_remote_load(InfraredRemote* remote, FuriString* path) { infrared_remote_button_free(button); } } - } + success = true; + } while(false); furi_string_free(buf); flipper_format_free(ff); diff --git a/applications/main/infrared/infrared_signal.c b/applications/main/infrared/infrared_signal.c index d399b958..9154dfbf 100644 --- a/applications/main/infrared/infrared_signal.c +++ b/applications/main/infrared/infrared_signal.c @@ -74,7 +74,7 @@ static bool infrared_signal_is_raw_valid(InfraredRawSignal* raw) { } else if((raw->timings_size <= 0) || (raw->timings_size > MAX_TIMINGS_AMOUNT)) { FURI_LOG_E( TAG, - "Timings amount is out of range (0 - %X): %X", + "Timings amount is out of range (0 - %X): %zX", MAX_TIMINGS_AMOUNT, raw->timings_size); return false; @@ -275,8 +275,8 @@ bool infrared_signal_search_and_read( is_name_found = furi_string_equal(name, tmp); if(is_name_found) break; } - if(!is_name_found) break; - if(!infrared_signal_read_body(signal, ff)) break; + if(!is_name_found) break; //-V547 + if(!infrared_signal_read_body(signal, ff)) break; //-V779 success = true; } while(false); diff --git a/applications/main/infrared/scenes/infrared_scene_debug.c b/applications/main/infrared/scenes/infrared_scene_debug.c index dd0609b5..20497869 100644 --- a/applications/main/infrared/scenes/infrared_scene_debug.c +++ b/applications/main/infrared/scenes/infrared_scene_debug.c @@ -26,7 +26,7 @@ bool infrared_scene_debug_on_event(void* context, SceneManagerEvent event) { InfraredRawSignal* raw = infrared_signal_get_raw_signal(signal); infrared_debug_view_set_text(debug_view, "RAW\n%d samples\n", raw->timings_size); - printf("RAW, %d samples:\r\n", raw->timings_size); + printf("RAW, %zu samples:\r\n", raw->timings_size); for(size_t i = 0; i < raw->timings_size; ++i) { printf("%lu ", raw->timings[i]); } diff --git a/applications/main/lfrfid/lfrfid.c b/applications/main/lfrfid/lfrfid.c index 2207e7e0..85a00eea 100644 --- a/applications/main/lfrfid/lfrfid.c +++ b/applications/main/lfrfid/lfrfid.c @@ -32,7 +32,7 @@ static void rpc_command_callback(RpcAppSystemEvent rpc_event, void* context) { } static LfRfid* lfrfid_alloc() { - LfRfid* lfrfid = malloc(sizeof(LfRfid)); //-V773 + LfRfid* lfrfid = malloc(sizeof(LfRfid)); lfrfid->storage = furi_record_open(RECORD_STORAGE); lfrfid->dialogs = furi_record_open(RECORD_DIALOGS); @@ -100,7 +100,7 @@ static LfRfid* lfrfid_alloc() { lfrfid->view_dispatcher, LfRfidViewRead, lfrfid_view_read_get_view(lfrfid->read_view)); return lfrfid; -} +} //-V773 static void lfrfid_free(LfRfid* lfrfid) { furi_assert(lfrfid); diff --git a/applications/main/lfrfid/lfrfid_cli.c b/applications/main/lfrfid/lfrfid_cli.c index 64027452..ce3e987e 100644 --- a/applications/main/lfrfid/lfrfid_cli.c +++ b/applications/main/lfrfid/lfrfid_cli.c @@ -87,7 +87,7 @@ static void lfrfid_cli_read(Cli* cli, FuriString* args) { uint32_t flags = furi_event_flag_wait(context.event, available_flags, FuriFlagWaitAny, 100); - if(flags != FuriFlagErrorTimeout) { + if(flags != (unsigned)FuriFlagErrorTimeout) { if(FURI_BIT(flags, LFRFIDWorkerReadDone)) { break; } @@ -153,7 +153,7 @@ static bool lfrfid_cli_parse_args(FuriString* args, ProtocolDict* dict, Protocol for(ProtocolId i = 0; i < LFRFIDProtocolMax; i++) { printf( - "\t%s, %d bytes long\r\n", + "\t%s, %zu bytes long\r\n", protocol_dict_get_name(dict, i), protocol_dict_get_data_size(dict, i)); } @@ -165,7 +165,7 @@ static bool lfrfid_cli_parse_args(FuriString* args, ProtocolDict* dict, Protocol // check data arg if(!args_read_hex_bytes(data_text, data, data_size)) { printf( - "%s data needs to be %d bytes long\r\n", + "%s data needs to be %zu bytes long\r\n", protocol_dict_get_name(dict, *protocol), data_size); break; @@ -211,7 +211,7 @@ static void lfrfid_cli_write(Cli* cli, FuriString* args) { while(!cli_cmd_interrupt_received(cli)) { uint32_t flags = furi_event_flag_wait(event, available_flags, FuriFlagWaitAny, 100); - if(flags != FuriFlagErrorTimeout) { + if(flags != (unsigned)FuriFlagErrorTimeout) { if(FURI_BIT(flags, LFRFIDWorkerWriteOK)) { printf("Written!\r\n"); break; @@ -309,9 +309,9 @@ static void lfrfid_cli_raw_analyze(Cli* cli, FuriString* args) { warn = true; } - furi_string_printf(info_string, "[%ld %ld]", pulse, duration); + furi_string_printf(info_string, "[%lu %lu]", pulse, duration); printf("%-16s", furi_string_get_cstr(info_string)); - furi_string_printf(info_string, "[%ld %ld]", pulse, duration - pulse); + furi_string_printf(info_string, "[%lu %lu]", pulse, duration - pulse); printf("%-16s", furi_string_get_cstr(info_string)); if(warn) { @@ -335,7 +335,7 @@ static void lfrfid_cli_raw_analyze(Cli* cli, FuriString* args) { total_pulse += pulse; total_duration += duration; - if(total_protocol != PROTOCOL_NO) { + if(total_protocol != PROTOCOL_NO) { //-V1051 break; } } else { @@ -346,9 +346,9 @@ static void lfrfid_cli_raw_analyze(Cli* cli, FuriString* args) { printf(" Frequency: %f\r\n", (double)frequency); printf(" Duty Cycle: %f\r\n", (double)duty_cycle); - printf(" Warns: %ld\r\n", total_warns); - printf(" Pulse sum: %ld\r\n", total_pulse); - printf("Duration sum: %ld\r\n", total_duration); + printf(" Warns: %lu\r\n", total_warns); + printf(" Pulse sum: %lu\r\n", total_pulse); + printf("Duration sum: %lu\r\n", total_duration); printf(" Average: %f\r\n", (double)((float)total_pulse / (float)total_duration)); printf(" Protocol: "); @@ -435,7 +435,7 @@ static void lfrfid_cli_raw_read(Cli* cli, FuriString* args) { while(true) { uint32_t flags = furi_event_flag_wait(event, available_flags, FuriFlagWaitAny, 100); - if(flags != FuriFlagErrorTimeout) { + if(flags != (unsigned)FuriFlagErrorTimeout) { if(FURI_BIT(flags, LFRFIDWorkerReadRawFileError)) { printf("File is not RFID raw file\r\n"); break; @@ -510,7 +510,7 @@ static void lfrfid_cli_raw_emulate(Cli* cli, FuriString* args) { while(true) { uint32_t flags = furi_event_flag_wait(event, available_flags, FuriFlagWaitAny, 100); - if(flags != FuriFlagErrorTimeout) { + if(flags != (unsigned)FuriFlagErrorTimeout) { if(FURI_BIT(flags, LFRFIDWorkerEmulateRawFileError)) { printf("File is not RFID raw file\r\n"); break; @@ -573,4 +573,4 @@ static void lfrfid_cli(Cli* cli, FuriString* args, void* context) { } furi_string_free(cmd); -} \ No newline at end of file +} diff --git a/applications/main/nfc/scenes/nfc_scene_emulate_uid.c b/applications/main/nfc/scenes/nfc_scene_emulate_uid.c index f9019767..7316eebe 100644 --- a/applications/main/nfc/scenes/nfc_scene_emulate_uid.c +++ b/applications/main/nfc/scenes/nfc_scene_emulate_uid.c @@ -39,7 +39,7 @@ static void nfc_scene_emulate_uid_widget_config(Nfc* nfc, bool data_received) { widget_add_icon_element(widget, 0, 3, &I_NFC_dolphin_emulation_47x61); widget_add_string_element(widget, 57, 13, AlignLeft, AlignTop, FontPrimary, "Emulating UID"); - if(strcmp(nfc->dev->dev_name, "")) { + if(strcmp(nfc->dev->dev_name, "") != 0) { furi_string_printf(info_str, "%s", nfc->dev->dev_name); } else { for(uint8_t i = 0; i < data->uid_len; i++) { diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_emulate.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_emulate.c index 1bd9a85a..8c0f493e 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_emulate.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_emulate.c @@ -18,7 +18,7 @@ void nfc_scene_mf_classic_emulate_on_enter(void* context) { // Setup view Popup* popup = nfc->popup; popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop); - if(strcmp(nfc->dev->dev_name, "")) { + if(strcmp(nfc->dev->dev_name, "") != 0) { nfc_text_store_set(nfc, "%s", nfc->dev->dev_name); } else { nfc_text_store_set(nfc, "MIFARE\nClassic"); diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_keys.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_keys.c index 54cc18d3..dee9553d 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_keys.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_keys.c @@ -28,9 +28,9 @@ void nfc_scene_mf_classic_keys_on_enter(void* context) { widget_add_string_element( nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Mifare Classic Keys"); char temp_str[32]; - snprintf(temp_str, sizeof(temp_str), "Flipper list: %ld", flipper_dict_keys_total); + snprintf(temp_str, sizeof(temp_str), "Flipper list: %lu", flipper_dict_keys_total); widget_add_string_element(nfc->widget, 0, 20, AlignLeft, AlignTop, FontSecondary, temp_str); - snprintf(temp_str, sizeof(temp_str), "User list: %ld", user_dict_keys_total); + snprintf(temp_str, sizeof(temp_str), "User list: %lu", user_dict_keys_total); widget_add_string_element(nfc->widget, 0, 32, AlignLeft, AlignTop, FontSecondary, temp_str); widget_add_button_element( nfc->widget, GuiButtonTypeCenter, "Add", nfc_scene_mf_classic_keys_widget_callback, nfc); diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_keys_list.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_keys_list.c index 19d2f556..57f9fe65 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_keys_list.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_keys_list.c @@ -27,7 +27,7 @@ void nfc_scene_mf_classic_keys_list_prepare(Nfc* nfc, MfClassicDict* dict) { char* current_key = (char*)malloc(sizeof(char) * 13); strncpy(current_key, furi_string_get_cstr(temp_key), 12); MfClassicUserKeys_push_back(nfc->mfc_key_strs, current_key); - FURI_LOG_D("ListKeys", "Key %ld: %s", index, current_key); + FURI_LOG_D("ListKeys", "Key %lu: %s", index, current_key); submenu_add_item( submenu, current_key, index++, nfc_scene_mf_classic_keys_list_submenu_callback, nfc); } diff --git a/applications/main/nfc/scenes/nfc_scene_mf_desfire_read_success.c b/applications/main/nfc/scenes/nfc_scene_mf_desfire_read_success.c index 2ab0355c..39030397 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_desfire_read_success.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_desfire_read_success.c @@ -26,13 +26,13 @@ void nfc_scene_mf_desfire_read_success_on_enter(void* context) { furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]); } - uint32_t bytes_total = 1 << (data->version.sw_storage >> 1); + uint32_t bytes_total = 1UL << (data->version.sw_storage >> 1); uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0; - furi_string_cat_printf(temp_str, "\n%ld", bytes_total); + furi_string_cat_printf(temp_str, "\n%lu", bytes_total); if(data->version.sw_storage & 1) { furi_string_push_back(temp_str, '+'); } - furi_string_cat_printf(temp_str, " bytes, %ld bytes free\n", bytes_free); + furi_string_cat_printf(temp_str, " bytes, %lu bytes free\n", bytes_free); uint16_t n_apps = 0; uint16_t n_files = 0; diff --git a/applications/main/nfc/scenes/nfc_scene_mf_ultralight_emulate.c b/applications/main/nfc/scenes/nfc_scene_mf_ultralight_emulate.c index c9c617cb..9d8f17f9 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_ultralight_emulate.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_ultralight_emulate.c @@ -21,7 +21,7 @@ void nfc_scene_mf_ultralight_emulate_on_enter(void* context) { (type == MfUltralightTypeUnknown); Popup* popup = nfc->popup; popup_set_header(popup, "Emulating", 67, 13, AlignLeft, AlignTop); - if(strcmp(nfc->dev->dev_name, "")) { + if(strcmp(nfc->dev->dev_name, "") != 0) { nfc_text_store_set(nfc, "%s", nfc->dev->dev_name); } else if(is_ultralight) { nfc_text_store_set(nfc, "MIFARE\nUltralight"); diff --git a/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c b/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c index d1767a45..b44ab782 100644 --- a/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c +++ b/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c @@ -57,13 +57,13 @@ void nfc_scene_nfc_data_info_on_enter(void* context) { // Set application specific data if(protocol == NfcDeviceProtocolMifareDesfire) { MifareDesfireData* data = &dev_data->mf_df_data; - uint32_t bytes_total = 1 << (data->version.sw_storage >> 1); + uint32_t bytes_total = 1UL << (data->version.sw_storage >> 1); uint32_t bytes_free = data->free_memory ? data->free_memory->bytes : 0; - furi_string_cat_printf(temp_str, "\n%ld", bytes_total); + furi_string_cat_printf(temp_str, "\n%lu", bytes_total); if(data->version.sw_storage & 1) { furi_string_push_back(temp_str, '+'); } - furi_string_cat_printf(temp_str, " bytes, %ld bytes free\n", bytes_free); + furi_string_cat_printf(temp_str, " bytes, %lu bytes free\n", bytes_free); uint16_t n_apps = 0; uint16_t n_files = 0; @@ -147,4 +147,4 @@ void nfc_scene_nfc_data_info_on_exit(void* context) { Nfc* nfc = context; widget_reset(nfc->widget); -} \ No newline at end of file +} diff --git a/applications/main/nfc/scenes/nfc_scene_read.c b/applications/main/nfc/scenes/nfc_scene_read.c index a64d4d00..2607cbd8 100644 --- a/applications/main/nfc/scenes/nfc_scene_read.c +++ b/applications/main/nfc/scenes/nfc_scene_read.c @@ -71,7 +71,7 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) { } else if(event.event == NfcWorkerEventReadMfUltralight) { notification_message(nfc->notifications, &sequence_success); // Set unlock password input to 0xFFFFFFFF only on fresh read - memset(nfc->byte_input_store, 0xFF, 4); + memset(nfc->byte_input_store, 0xFF, sizeof(nfc->byte_input_store)); scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightReadSuccess); DOLPHIN_DEED(DolphinDeedNfcReadSuccess); consumed = true; diff --git a/applications/main/nfc/scenes/nfc_scene_save_name.c b/applications/main/nfc/scenes/nfc_scene_save_name.c index ca4b1a35..00727422 100644 --- a/applications/main/nfc/scenes/nfc_scene_save_name.c +++ b/applications/main/nfc/scenes/nfc_scene_save_name.c @@ -55,7 +55,7 @@ bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == NfcCustomEventTextInputDone) { - if(strcmp(nfc->dev->dev_name, "")) { + if(strcmp(nfc->dev->dev_name, "") != 0) { nfc_device_delete(nfc->dev, true); } if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetUid)) { diff --git a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c index 7463cfaf..5d1a80a3 100644 --- a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c +++ b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.c @@ -2,6 +2,7 @@ #include #include +#include #define TAG "SubghzFrequencyAnalyzerWorker" @@ -197,7 +198,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { rssi_temp = (rssi_temp + frequency_rssi.rssi_fine) / 2; frequency_temp = frequency_rssi.frequency_fine; - if(instance->filVal) { + if(!float_is_equal(instance->filVal, 0.f)) { frequency_rssi.frequency_fine = subghz_frequency_analyzer_worker_expRunningAverageAdaptive( instance, frequency_rssi.frequency_fine); @@ -219,7 +220,7 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) { instance->sample_hold_counter = 20; rssi_temp = (rssi_temp + frequency_rssi.rssi_coarse) / 2; frequency_temp = frequency_rssi.frequency_coarse; - if(instance->filVal) { + if(!float_is_equal(instance->filVal, 0.f)) { frequency_rssi.frequency_coarse = subghz_frequency_analyzer_worker_expRunningAverageAdaptive( instance, frequency_rssi.frequency_coarse); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index b270dd48..6f95c416 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -3,6 +3,7 @@ #include #include #include +#include #define RAW_FILE_NAME "Raw_signal_" #define TAG "SubGhzSceneReadRAW" @@ -358,7 +359,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { float rssi = furi_hal_subghz_get_rssi(); - if(subghz->txrx->raw_threshold_rssi == SUBGHZ_RAW_TRESHOLD_MIN) { + if(float_is_equal(subghz->txrx->raw_threshold_rssi, SUBGHZ_RAW_TRESHOLD_MIN)) { subghz_read_raw_add_data_rssi(subghz->subghz_read_raw, rssi, true); subghz_protocol_raw_save_to_file_pause( (SubGhzProtocolDecoderRAW*)subghz->txrx->decoder_result, false); diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index 33846c28..255ba228 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -94,7 +94,7 @@ bool subghz_scene_save_name_on_event(void* context, SceneManagerEvent event) { return true; } else if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneSaveName) { - if(strcmp(subghz->file_name_tmp, "")) { + if(strcmp(subghz->file_name_tmp, "") != 0) { furi_string_cat_printf( subghz->file_path, "/%s%s", subghz->file_name_tmp, SUBGHZ_APP_EXTENSION); if(subghz_path_is_file(subghz->file_path_tmp)) { diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index 2ed53719..eaa3ccef 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -46,7 +46,7 @@ bool subghz_scene_set_type_submenu_gen_data_protocol( uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (key >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (key >> (i * 8)) & 0xFF; } if(!flipper_format_update_hex(subghz->txrx->fff_data, "Key", key_data, sizeof(uint64_t))) { FURI_LOG_E(TAG, "Unable to update Key"); diff --git a/applications/main/subghz/subghz_cli.c b/applications/main/subghz/subghz_cli.c index b6471b33..536cb535 100644 --- a/applications/main/subghz/subghz_cli.c +++ b/applications/main/subghz/subghz_cli.c @@ -152,11 +152,11 @@ void subghz_cli_command_tx(Cli* cli, FuriString* args, void* context) { "Protocol: Princeton\n" "Bit: 24\n" "Key: 00 00 00 00 00 %02X %02X %02X\n" - "TE: %ld\n" - "Repeat: %ld\n", - (uint8_t)((key >> 16) & 0xFF), - (uint8_t)((key >> 8) & 0xFF), - (uint8_t)(key & 0xFF), + "TE: %lu\n" + "Repeat: %lu\n", + (uint8_t)((key >> 16) & 0xFFU), + (uint8_t)((key >> 8) & 0xFFU), + (uint8_t)(key & 0xFFU), te, repeat); FlipperFormat* flipper_format = flipper_format_string_alloc(); @@ -300,7 +300,7 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) { furi_hal_power_suppress_charge_exit(); - printf("\r\nPackets received %u\r\n", instance->packet_count); + printf("\r\nPackets received %zu\r\n", instance->packet_count); // Cleanup subghz_receiver_free(receiver); @@ -787,8 +787,9 @@ static bool subghz_on_system_start_istream_decode_band( } region->bands_count += 1; - region = - realloc(region, sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count); + region = realloc( //-V701 + region, + sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count); size_t pos = region->bands_count - 1; region->bands[pos].start = band.start; region->bands[pos].end = band.end; @@ -798,7 +799,7 @@ static bool subghz_on_system_start_istream_decode_band( FURI_LOG_I( "SubGhzOnStart", - "Add allowed band: start %ldHz, stop %ldHz, power_limit %ddBm, duty_cycle %d%%", + "Add allowed band: start %luHz, stop %luHz, power_limit %ddBm, duty_cycle %u%%", band.start, band.end, band.power_limit, diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 0bcd7006..7de020a5 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -164,7 +164,7 @@ bool subghz_tx_start(SubGhz* subghz, FlipperFormat* flipper_format) { if(subghz->txrx->transmitter) { if(subghz_transmitter_deserialize(subghz->txrx->transmitter, flipper_format)) { - if(strcmp(furi_string_get_cstr(subghz->txrx->preset->name), "")) { + if(strcmp(furi_string_get_cstr(subghz->txrx->preset->name), "") != 0) { subghz_begin( subghz, subghz_setting_get_preset_data_by_name( @@ -544,11 +544,8 @@ void subghz_hopper_update(SubGhz* subghz) { switch(subghz->txrx->hopper_state) { case SubGhzHopperStateOFF: - return; - break; case SubGhzHopperStatePause: return; - break; case SubGhzHopperStateRSSITimeOut: if(subghz->txrx->hopper_timeout != 0) { subghz->txrx->hopper_timeout--; diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 12989840..94419084 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -11,6 +11,7 @@ #include "../helpers/subghz_frequency_analyzer_log_item_array.h" #include +#include #define LOG_FREQUENCY_MAX_ITEMS 60 // uint8_t (limited by 'seq' of SubGhzFrequencyAnalyzerLogItem) @@ -47,7 +48,8 @@ typedef struct { } SubGhzFrequencyAnalyzerModel; static inline uint8_t rssi_sanitize(float rssi) { - return (rssi ? (uint8_t)(rssi - SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) : 0); + return ( + !float_is_equal(rssi, 0.f) ? (uint8_t)(rssi - SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) : 0); } void subghz_frequency_analyzer_set_callback( @@ -294,9 +296,6 @@ static bool subghz_frequency_analyzer_log_frequency_insert(SubGhzFrequencyAnalyz if(items_count < LOG_FREQUENCY_MAX_ITEMS) { SubGhzFrequencyAnalyzerLogItem_t* item = SubGhzFrequencyAnalyzerLogItemArray_push_new(model->log_frequency); - if(item == NULL) { - return false; - } (*item)->frequency = model->frequency; (*item)->count = 1; (*item)->rssi_max = model->rssi; @@ -340,7 +339,7 @@ void subghz_frequency_analyzer_pair_callback( float rssi, bool signal) { SubGhzFrequencyAnalyzer* instance = context; - if((rssi == 0.f) && (instance->locked)) { + if(float_is_equal(rssi, 0.f) && instance->locked) { if(instance->callback) { instance->callback(SubGhzCustomEventSceneAnalyzerUnlock, instance->context); } @@ -355,13 +354,13 @@ void subghz_frequency_analyzer_pair_callback( model->history_frequency[0] = model->frequency; }, false); - } else if((rssi != 0.f) && (!instance->locked)) { + } else if(!float_is_equal(rssi, 0.f) && !instance->locked) { if(instance->callback) { instance->callback(SubGhzCustomEventSceneAnalyzerLock, instance->context); } } - instance->locked = (rssi != 0.f); + instance->locked = !float_is_equal(rssi, 0.f); with_view_model( instance->view, SubGhzFrequencyAnalyzerModel * model, diff --git a/applications/main/subghz/views/subghz_read_raw.c b/applications/main/subghz/views/subghz_read_raw.c index 6120a210..87c8a308 100644 --- a/applications/main/subghz/views/subghz_read_raw.c +++ b/applications/main/subghz/views/subghz_read_raw.c @@ -91,7 +91,7 @@ void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) with_view_model( instance->view, SubGhzReadRAWModel * model, - { furi_string_printf(model->sample_write, "%d spl.", sample); }, + { furi_string_printf(model->sample_write, "%zu spl.", sample); }, false); } @@ -161,7 +161,7 @@ void subghz_read_raw_draw_sin(Canvas* canvas, SubGhzReadRAWModel* model) { canvas_draw_line( canvas, i + 1, - 32 - subghz_read_raw_tab_sin((i + model->ind_sin * 16)) / SUBGHZ_RAW_SIN_AMPLITUDE, + 32 - subghz_read_raw_tab_sin(i + model->ind_sin * 16) / SUBGHZ_RAW_SIN_AMPLITUDE, i + 2, 32 + subghz_read_raw_tab_sin((i + model->ind_sin * 16 + 1) * 2) / SUBGHZ_RAW_SIN_AMPLITUDE); diff --git a/applications/main/subghz/views/subghz_test_packet.c b/applications/main/subghz/views/subghz_test_packet.c index a42898f7..43502180 100644 --- a/applications/main/subghz/views/subghz_test_packet.c +++ b/applications/main/subghz/views/subghz_test_packet.c @@ -114,7 +114,7 @@ static void subghz_test_packet_draw(Canvas* canvas, SubGhzTestPacketModel* model snprintf(buffer, sizeof(buffer), "Path: %d - %s", model->path, path_name); canvas_draw_str(canvas, 0, 31, buffer); - snprintf(buffer, sizeof(buffer), "Packets: %d", model->packets); + snprintf(buffer, sizeof(buffer), "Packets: %zu", model->packets); canvas_draw_str(canvas, 0, 42, buffer); if(model->status == SubGhzTestPacketModelStatusRx) { diff --git a/applications/main/u2f/scenes/u2f_scene_main.c b/applications/main/u2f/scenes/u2f_scene_main.c index 60ed71c7..af7f1159 100644 --- a/applications/main/u2f/scenes/u2f_scene_main.c +++ b/applications/main/u2f/scenes/u2f_scene_main.c @@ -58,7 +58,7 @@ bool u2f_scene_main_on_event(void* context, SceneManagerEvent event) { app->event_cur = event.event; if(event.event == U2fCustomEventRegister) u2f_view_set_state(app->u2f_view, U2fMsgRegister); - else if(event.event == U2fCustomEventAuth) + else if(event.event == U2fCustomEventAuth) //-V547 u2f_view_set_state(app->u2f_view, U2fMsgAuth); notification_message(app->notifications, &sequence_display_backlight_on); notification_message(app->notifications, &sequence_single_vibro); diff --git a/applications/main/u2f/u2f_data.c b/applications/main/u2f/u2f_data.c index 900af462..66604d16 100644 --- a/applications/main/u2f/u2f_data.c +++ b/applications/main/u2f/u2f_data.c @@ -402,9 +402,9 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) { FURI_LOG_E(TAG, "Unable to load encryption key"); break; } - memset(&cnt, 0, 32); - if(!furi_hal_crypto_decrypt(cnt_encr, (uint8_t*)&cnt, 32)) { - memset(&cnt, 0, 32); + memset(&cnt, 0, sizeof(U2fCounterData)); + if(!furi_hal_crypto_decrypt(cnt_encr, (uint8_t*)&cnt, sizeof(U2fCounterData))) { + memset(&cnt, 0, sizeof(U2fCounterData)); FURI_LOG_E(TAG, "Decryption failed"); break; } diff --git a/applications/main/u2f/u2f_hid.c b/applications/main/u2f/u2f_hid.c index 6e1a51f3..9b625c1f 100644 --- a/applications/main/u2f/u2f_hid.c +++ b/applications/main/u2f/u2f_hid.c @@ -94,7 +94,7 @@ static void u2f_hid_send_response(U2fHid* u2f_hid) { uint16_t data_ptr = 0; memset(packet_buf, 0, HID_U2F_PACKET_LEN); - memcpy(packet_buf, &(u2f_hid->packet.cid), 4); + memcpy(packet_buf, &(u2f_hid->packet.cid), sizeof(uint32_t)); //-V1086 // Init packet packet_buf[4] = u2f_hid->packet.cmd; @@ -166,7 +166,7 @@ static bool u2f_hid_parse_request(U2fHid* u2f_hid) { return false; u2f_hid->packet.len = 17; uint32_t random_cid = furi_hal_random_get(); - memcpy(&(u2f_hid->packet.payload[8]), &random_cid, 4); + memcpy(&(u2f_hid->packet.payload[8]), &random_cid, sizeof(uint32_t)); //-V1086 u2f_hid->packet.payload[12] = 2; // Protocol version u2f_hid->packet.payload[13] = 1; // Device version major u2f_hid->packet.payload[14] = 0; // Device version minor @@ -177,7 +177,7 @@ static bool u2f_hid_parse_request(U2fHid* u2f_hid) { } else if(u2f_hid->packet.cmd == U2F_HID_WINK) { // WINK - notify user if(u2f_hid->packet.len != 0) return false; u2f_wink(u2f_hid->u2f_instance); - u2f_hid->packet.len = 0; + u2f_hid->packet.len = 0; //-V1048 u2f_hid_send_response(u2f_hid); } else return false; diff --git a/applications/plugins/dap_link/usb/dap_v2_usb.c b/applications/plugins/dap_link/usb/dap_v2_usb.c index b42df283..cba78664 100644 --- a/applications/plugins/dap_link/usb/dap_v2_usb.c +++ b/applications/plugins/dap_link/usb/dap_v2_usb.c @@ -568,12 +568,12 @@ void dap_common_usb_set_state_callback(DapStateCallback callback) { static void* dap_usb_alloc_string_descr(const char* str) { furi_assert(str); - uint8_t len = strlen(str); - uint8_t wlen = (len + 1) * sizeof(uint16_t); + size_t len = strlen(str); + size_t wlen = (len + 1) * sizeof(uint16_t); struct usb_string_descriptor* dev_str_desc = malloc(wlen); dev_str_desc->bLength = wlen; dev_str_desc->bDescriptorType = USB_DTYPE_STRING; - for(uint8_t i = 0; i < len; i++) { + for(size_t i = 0; i < len; i++) { dev_str_desc->wString[i] = str[i]; } @@ -974,4 +974,4 @@ static usbd_respond hid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_cal } return usbd_fail; -} \ No newline at end of file +} diff --git a/applications/plugins/hid_app/views/hid_keyboard.c b/applications/plugins/hid_app/views/hid_keyboard.c index dff4a7df..3e3b6328 100644 --- a/applications/plugins/hid_app/views/hid_keyboard.c +++ b/applications/plugins/hid_app/views/hid_keyboard.c @@ -249,30 +249,19 @@ static void hid_keyboard_draw_callback(Canvas* canvas, void* context) { static uint8_t hid_keyboard_get_selected_key(HidKeyboardModel* model) { HidKeyboardKey key = hid_keyboard_keyset[model->y][model->x]; - // Use upper case if shift is toggled - bool useUppercase = model->shift; - // Check if the key has an upper case version - bool hasUppercase = key.shift_key != 0; - if(useUppercase && hasUppercase) - return key.value; - else - return key.value; + return key.value; } static void hid_keyboard_get_select_key(HidKeyboardModel* model, HidKeyboardPoint delta) { // Keep going until a valid spot is found, this allows for nulls and zero width keys in the map do { - if(((int8_t)model->y) + delta.y < 0) - model->y = ROW_COUNT - 1; - else - model->y = (model->y + delta.y) % ROW_COUNT; + const int delta_sum = model->y + delta.y; + model->y = delta_sum < 0 ? ROW_COUNT - 1 : delta_sum % ROW_COUNT; } while(delta.y != 0 && hid_keyboard_keyset[model->y][model->x].value == 0); do { - if(((int8_t)model->x) + delta.x < 0) - model->x = COLUMN_COUNT - 1; - else - model->x = (model->x + delta.x) % COLUMN_COUNT; + const int delta_sum = model->x + delta.x; + model->x = delta_sum < 0 ? COLUMN_COUNT - 1 : delta_sum % COLUMN_COUNT; } while(delta.x != 0 && hid_keyboard_keyset[model->y][model->x].width == 0); // Skip zero width keys, pretend they are one key } diff --git a/applications/plugins/music_player/music_player.c b/applications/plugins/music_player/music_player.c index 07d4e2df..28127a57 100644 --- a/applications/plugins/music_player/music_player.c +++ b/applications/plugins/music_player/music_player.c @@ -180,7 +180,7 @@ static void render_callback(Canvas* canvas, void* ctx) { // note stack view_port x_pos = 73; - y_pos = 0; + y_pos = 0; //-V1048 canvas_set_color(canvas, ColorBlack); canvas_set_font(canvas, FontPrimary); canvas_draw_frame(canvas, x_pos, y_pos, 49, 64); diff --git a/applications/plugins/picopass/lib/loclass/optimized_cipher.c b/applications/plugins/picopass/lib/loclass/optimized_cipher.c index eba95538..94df07ba 100644 --- a/applications/plugins/picopass/lib/loclass/optimized_cipher.c +++ b/applications/plugins/picopass/lib/loclass/optimized_cipher.c @@ -111,9 +111,9 @@ static void init_opt_select_LUT(void) { ***********************************************************************************/ #define loclass_opt__select(x, y, r) \ - (4 & (((r & (r << 2)) >> 5) ^ ((r & ~(r << 2)) >> 4) ^ ((r | r << 2) >> 3))) | \ - (2 & (((r | r << 2) >> 6) ^ ((r | r << 2) >> 1) ^ (r >> 5) ^ r ^ ((x ^ y) << 1))) | \ - (1 & (((r & ~(r << 2)) >> 4) ^ ((r & (r << 2)) >> 3) ^ r ^ x)) + (4 & ((((r) & ((r) << 2)) >> 5) ^ (((r) & ~((r) << 2)) >> 4) ^ (((r) | (r) << 2) >> 3))) | \ + (2 & ((((r) | (r) << 2) >> 6) ^ (((r) | (r) << 2) >> 1) ^ ((r) >> 5) ^ (r) ^ (((x) ^ (y)) << 1))) | \ + (1 & ((((r) & ~((r) << 2)) >> 4) ^ (((r) & ((r) << 2)) >> 3) ^ (r) ^ (x))) static void loclass_opt_successor(const uint8_t* k, LoclassState_t* s, uint8_t y) { uint16_t Tt = s->t & 0xc533; @@ -149,30 +149,11 @@ static void loclass_opt_suc( uint8_t length, bool add32Zeroes) { for(int i = 0; i < length; i++) { - uint8_t head; - head = in[i]; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); - - head >>= 1; - loclass_opt_successor(k, s, head); + uint8_t head = in[i]; + for(int j = 0; j < 8; j++) { + loclass_opt_successor(k, s, head); + head >>= 1; + } } //For tag MAC, an additional 32 zeroes if(add32Zeroes) { diff --git a/applications/plugins/picopass/picopass_worker.c b/applications/plugins/picopass/picopass_worker.c index c2a32cb6..bb1e513a 100644 --- a/applications/plugins/picopass/picopass_worker.c +++ b/applications/plugins/picopass/picopass_worker.c @@ -143,7 +143,7 @@ ReturnCode picopass_read_preauth(PicopassBlock* AA1) { AA1[PICOPASS_CSN_BLOCK_INDEX].data[7]); rfalPicoPassReadBlockRes cfg = {0}; - err = rfalPicoPassPollerReadBlock(PICOPASS_CONFIG_BLOCK_INDEX, &cfg); + rfalPicoPassPollerReadBlock(PICOPASS_CONFIG_BLOCK_INDEX, &cfg); memcpy(AA1[PICOPASS_CONFIG_BLOCK_INDEX].data, cfg.data, sizeof(cfg.data)); FURI_LOG_D( TAG, @@ -158,7 +158,7 @@ ReturnCode picopass_read_preauth(PicopassBlock* AA1) { AA1[PICOPASS_CONFIG_BLOCK_INDEX].data[7]); rfalPicoPassReadBlockRes aia; - err = rfalPicoPassPollerReadBlock(PICOPASS_AIA_BLOCK_INDEX, &aia); + rfalPicoPassPollerReadBlock(PICOPASS_AIA_BLOCK_INDEX, &aia); memcpy(AA1[PICOPASS_AIA_BLOCK_INDEX].data, aia.data, sizeof(aia.data)); FURI_LOG_D( TAG, @@ -221,7 +221,7 @@ ReturnCode picopass_auth(PicopassBlock* AA1, PicopassPacs* pacs) { while(iclass_elite_dict_get_next_key(dict, key)) { FURI_LOG_D( TAG, - "Try to auth with key %d %02x%02x%02x%02x%02x%02x%02x%02x", + "Try to auth with key %zu %02x%02x%02x%02x%02x%02x%02x%02x", index++, key[0], key[1], @@ -249,9 +249,7 @@ ReturnCode picopass_auth(PicopassBlock* AA1, PicopassPacs* pacs) { } } - if(dict) { - iclass_elite_dict_free(dict); - } + iclass_elite_dict_free(dict); return err; } diff --git a/applications/plugins/picopass/scenes/picopass_scene_save_name.c b/applications/plugins/picopass/scenes/picopass_scene_save_name.c index 17ad5927..59f33c79 100644 --- a/applications/plugins/picopass/scenes/picopass_scene_save_name.c +++ b/applications/plugins/picopass/scenes/picopass_scene_save_name.c @@ -54,7 +54,7 @@ bool picopass_scene_save_name_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == PicopassCustomEventTextInputDone) { - if(strcmp(picopass->dev->dev_name, "")) { + if(strcmp(picopass->dev->dev_name, "") != 0) { // picopass_device_delete(picopass->dev, true); } strlcpy( diff --git a/applications/plugins/signal_generator/scenes/signal_gen_scene_pwm.c b/applications/plugins/signal_generator/scenes/signal_gen_scene_pwm.c index f302c023..7ac3fadd 100644 --- a/applications/plugins/signal_generator/scenes/signal_gen_scene_pwm.c +++ b/applications/plugins/signal_generator/scenes/signal_gen_scene_pwm.c @@ -15,12 +15,12 @@ static void app->pwm_freq = freq; app->pwm_duty = duty; - if(app->pwm_ch != pwm_ch_id[channel_id]) { + if(app->pwm_ch != pwm_ch_id[channel_id]) { //-V1051 app->pwm_ch_prev = app->pwm_ch; app->pwm_ch = pwm_ch_id[channel_id]; view_dispatcher_send_custom_event(app->view_dispatcher, SignalGenPwmEventChannelChange); } else { - app->pwm_ch = pwm_ch_id[channel_id]; + app->pwm_ch = pwm_ch_id[channel_id]; //-V1048 view_dispatcher_send_custom_event(app->view_dispatcher, SignalGenPwmEventUpdate); } } diff --git a/applications/plugins/signal_generator/views/signal_gen_pwm.c b/applications/plugins/signal_generator/views/signal_gen_pwm.c index 8e618f8a..b6ba47ab 100644 --- a/applications/plugins/signal_generator/views/signal_gen_pwm.c +++ b/applications/plugins/signal_generator/views/signal_gen_pwm.c @@ -127,12 +127,12 @@ static void signal_gen_pwm_draw_callback(Canvas* canvas, void* _model) { char* line_label = NULL; char val_text[16]; - for(uint8_t line = 0; line < LineIndexTotalCount; line++) { + for(size_t line = 0; line < LineIndexTotalCount; line++) { if(line == LineIndexChannel) { line_label = "GPIO Pin"; } else if(line == LineIndexFrequency) { line_label = "Frequency"; - } else if(line == LineIndexDuty) { + } else if(line == LineIndexDuty) { //-V547 line_label = "Pulse width"; } @@ -169,7 +169,7 @@ static void signal_gen_pwm_draw_callback(Canvas* canvas, void* _model) { canvas_draw_icon(canvas, icon_x, text_y - 9, &I_SmallArrowUp_3x5); canvas_draw_icon(canvas, icon_x, text_y + 5, &I_SmallArrowDown_3x5); } - } else if(line == LineIndexDuty) { + } else if(line == LineIndexDuty) { //-V547 snprintf(val_text, sizeof(val_text), "%d%%", model->duty); canvas_draw_str_aligned(canvas, VALUE_X, text_y, AlignCenter, AlignCenter, val_text); if(model->duty != 0) { diff --git a/applications/plugins/snake_game/snake_game.c b/applications/plugins/snake_game/snake_game.c index ef4ae2ee..f9b4d30a 100644 --- a/applications/plugins/snake_game/snake_game.c +++ b/applications/plugins/snake_game/snake_game.c @@ -130,7 +130,7 @@ static void snake_game_render_callback(Canvas* const canvas, void* ctx) { canvas_set_font(canvas, FontSecondary); char buffer[12]; - snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len - 7); + snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len - 7U); canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer); } @@ -153,7 +153,7 @@ static void snake_game_update_timer_callback(FuriMessageQueue* event_queue) { static void snake_game_init_game(SnakeState* const snake_state) { Point p[] = {{8, 6}, {7, 6}, {6, 6}, {5, 6}, {4, 6}, {3, 6}, {2, 6}}; - memcpy(snake_state->points, p, sizeof(p)); + memcpy(snake_state->points, p, sizeof(p)); //-V1086 snake_state->len = 7; diff --git a/applications/plugins/weather_station/protocols/oregon2.c b/applications/plugins/weather_station/protocols/oregon2.c index 8779e959..8ca80bbe 100644 --- a/applications/plugins/weather_station/protocols/oregon2.c +++ b/applications/plugins/weather_station/protocols/oregon2.c @@ -343,7 +343,7 @@ bool ws_protocol_decoder_oregon2_deserialize(void* context, FlipperFormat* flipp flipper_format, "VarData", (uint8_t*)&instance->var_data, - sizeof(instance->var_data))) { + sizeof(instance->var_data))) { //-V1051 FURI_LOG_E(TAG, "Missing VarData"); break; } diff --git a/applications/plugins/weather_station/protocols/oregon_v1.c b/applications/plugins/weather_station/protocols/oregon_v1.c index d1cc4c7a..1ed9da20 100644 --- a/applications/plugins/weather_station/protocols/oregon_v1.c +++ b/applications/plugins/weather_station/protocols/oregon_v1.c @@ -147,7 +147,7 @@ static void ws_protocol_oregon_v1_remote_controller(WSBlockGeneric* instance) { instance->temp = -temp_raw; } - instance->battery_low = !(instance->data >> 23) & 1; + instance->battery_low = !((instance->data >> 23) & 1ULL); instance->btn = WS_NO_BTN; instance->humidity = WS_NO_HUMIDITY; diff --git a/applications/plugins/weather_station/protocols/ws_generic.c b/applications/plugins/weather_station/protocols/ws_generic.c index dcacda2e..8a88ed52 100644 --- a/applications/plugins/weather_station/protocols/ws_generic.c +++ b/applications/plugins/weather_station/protocols/ws_generic.c @@ -79,7 +79,7 @@ bool ws_block_generic_serialize( uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->data >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->data >> (i * 8)) & 0xFF; } if(!flipper_format_write_hex(flipper_format, "Data", key_data, sizeof(uint64_t))) { @@ -208,4 +208,4 @@ bool ws_block_generic_deserialize(WSBlockGeneric* instance, FlipperFormat* flipp } while(0); return res; -} +} \ No newline at end of file diff --git a/applications/plugins/weather_station/views/weather_station_receiver_info.c b/applications/plugins/weather_station/views/weather_station_receiver_info.c index 55d239aa..b3b3f219 100644 --- a/applications/plugins/weather_station/views/weather_station_receiver_info.c +++ b/applications/plugins/weather_station/views/weather_station_receiver_info.c @@ -4,8 +4,7 @@ #include "../protocols/ws_generic.h" #include #include - -#define abs(x) ((x) > 0 ? (x) : -(x)) +#include struct WSReceiverInfo { View* view; @@ -79,7 +78,7 @@ void ws_view_receiver_info_draw(Canvas* canvas, WSReceiverInfoModel* model) { elements_bold_rounded_frame(canvas, 0, 38, 127, 25); canvas_set_font(canvas, FontPrimary); - if(model->generic->temp != WS_NO_TEMPERATURE) { + if(!float_is_equal(model->generic->temp, WS_NO_TEMPERATURE)) { canvas_draw_icon(canvas, 6, 43, &I_Therm_7x16); uint8_t temp_x1 = 0; diff --git a/applications/plugins/weather_station/weather_station_app_i.c b/applications/plugins/weather_station/weather_station_app_i.c index 052bb853..712634a2 100644 --- a/applications/plugins/weather_station/weather_station_app_i.c +++ b/applications/plugins/weather_station/weather_station_app_i.c @@ -111,11 +111,8 @@ void ws_hopper_update(WeatherStationApp* app) { switch(app->txrx->hopper_state) { case WSHopperStateOFF: - return; - break; case WSHopperStatePause: return; - break; case WSHopperStateRSSITimeOut: if(app->txrx->hopper_timeout != 0) { app->txrx->hopper_timeout--; diff --git a/applications/plugins/weather_station/weather_station_history.c b/applications/plugins/weather_station/weather_station_history.c index b37009c4..9adff39c 100644 --- a/applications/plugins/weather_station/weather_station_history.c +++ b/applications/plugins/weather_station/weather_station_history.c @@ -186,7 +186,7 @@ WSHistoryStateAddKey } // or add new record - if(!sensor_found) { + if(!sensor_found) { //-V547 WSHistoryItem* item = WSHistoryItemArray_push_raw(instance->history->data); item->preset = malloc(sizeof(SubGhzRadioPreset)); item->type = decoder_base->protocol->type; diff --git a/applications/services/bt/bt_service/bt.c b/applications/services/bt/bt_service/bt.c index 024cb6e5..9e578269 100644 --- a/applications/services/bt/bt_service/bt.c +++ b/applications/services/bt/bt_service/bt.c @@ -36,7 +36,7 @@ static void bt_pin_code_view_port_draw_callback(Canvas* canvas, void* context) { Bt* bt = context; char pin_code_info[24]; canvas_draw_icon(canvas, 0, 0, &I_BLE_Pairing_128x64); - snprintf(pin_code_info, sizeof(pin_code_info), "Pairing code\n%06ld", bt->pin_code); + snprintf(pin_code_info, sizeof(pin_code_info), "Pairing code\n%06lu", bt->pin_code); elements_multiline_text_aligned(canvas, 64, 4, AlignCenter, AlignTop, pin_code_info); elements_button_left(canvas, "Quit"); } @@ -78,7 +78,7 @@ static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) { notification_message(bt->notification, &sequence_display_backlight_on); FuriString* pin_str; dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0); - pin_str = furi_string_alloc_printf("Verify code\n%06ld", pin); + pin_str = furi_string_alloc_printf("Verify code\n%06lu", pin); dialog_message_set_text( bt->dialog_message, furi_string_get_cstr(pin_str), 64, 4, AlignCenter, AlignTop); dialog_message_set_buttons(bt->dialog_message, "Cancel", "OK", NULL); @@ -163,7 +163,7 @@ static uint16_t bt_serial_event_callback(SerialServiceEvent event, void* context rpc_session_feed(bt->rpc_session, event.data.buffer, event.data.size, 1000); if(bytes_processed != event.data.size) { FURI_LOG_E( - TAG, "Only %d of %d bytes processed by RPC", bytes_processed, event.data.size); + TAG, "Only %zu of %u bytes processed by RPC", bytes_processed, event.data.size); } ret = rpc_session_get_available_size(bt->rpc_session); } else if(event.event == SerialServiceEventTypeDataSent) { diff --git a/applications/services/bt/bt_service/bt_keys_storage.c b/applications/services/bt/bt_service/bt_keys_storage.c index 7cff9994..215f19a8 100644 --- a/applications/services/bt/bt_service/bt_keys_storage.c +++ b/applications/services/bt/bt_service/bt_keys_storage.c @@ -115,7 +115,7 @@ bool bt_keys_storage_update(BtKeysStorage* instance, uint8_t* start_addr, uint32 FURI_LOG_I( TAG, - "Base address: %p. Start update address: %p. Size changed: %ld", + "Base address: %p. Start update address: %p. Size changed: %lu", (void*)instance->nvm_sram_buff, start_addr, size); diff --git a/applications/services/cli/cli.c b/applications/services/cli/cli.c index f29dca9c..384d1780 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -225,7 +225,7 @@ static void cli_handle_enter(Cli* cli) { furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); CliCommand* cli_command_ptr = CliCommandTree_get(cli->commands, command); - if(cli_command_ptr) { + if(cli_command_ptr) { //-V547 CliCommand cli_command; memcpy(&cli_command, cli_command_ptr, sizeof(CliCommand)); furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); @@ -353,7 +353,7 @@ void cli_process_input(Cli* cli) { cli_handle_backspace(cli); } else if(in_chr == CliSymbolAsciiCR) { cli_handle_enter(cli); - } else if(in_chr >= 0x20 && in_chr < 0x7F) { + } else if(in_chr >= 0x20 && in_chr < 0x7F) { //-V560 if(cli->cursor_position == furi_string_size(cli->line)) { furi_string_push_back(cli->line, in_chr); cli_putc(cli, in_chr); diff --git a/applications/services/cli/cli_command_gpio.c b/applications/services/cli/cli_command_gpio.c index 0b29f485..f0d487be 100644 --- a/applications/services/cli/cli_command_gpio.c +++ b/applications/services/cli/cli_command_gpio.c @@ -1,5 +1,6 @@ #include "cli_command_gpio.h" +#include "core/string.h" #include #include #include @@ -36,26 +37,24 @@ void cli_command_gpio_print_usage() { } static bool pin_name_to_int(FuriString* pin_name, size_t* result) { - bool found = false; - bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug); + bool is_debug_mode = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug); for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) { - if(!furi_string_cmp(pin_name, cli_command_gpio_pins[i].name)) { - if(!cli_command_gpio_pins[i].debug || debug) { + if(furi_string_equal(pin_name, cli_command_gpio_pins[i].name)) { + if(!cli_command_gpio_pins[i].debug || is_debug_mode) { *result = i; - found = true; - break; + return true; } } } - return found; + return false; } static void gpio_print_pins(void) { printf("Wrong pin name. Available pins: "); - bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug); + bool is_debug_mode = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug); for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) { - if(!cli_command_gpio_pins[i].debug || debug) { + if(!cli_command_gpio_pins[i].debug || is_debug_mode) { printf("%s ", cli_command_gpio_pins[i].name); } } @@ -69,34 +68,29 @@ typedef enum { } GpioParseReturn; static GpioParseReturn gpio_command_parse(FuriString* args, size_t* pin_num, uint8_t* value) { - FuriString* pin_name; - pin_name = furi_string_alloc(); + GpioParseReturn ret = GpioParseReturnOk; + FuriString* pin_name = furi_string_alloc(); - size_t ws = furi_string_search_char(args, ' '); - if(ws == FURI_STRING_FAILURE) { - return GpioParseReturnCmdSyntaxError; - } + do { + if(!args_read_string_and_trim(args, pin_name)) { + ret = GpioParseReturnCmdSyntaxError; + break; + } else if(!pin_name_to_int(pin_name, pin_num)) { + ret = GpioParseReturnPinError; + break; + } - furi_string_set_n(pin_name, args, 0, ws); - furi_string_right(args, ws); - furi_string_trim(args); + int pin_mode; //-V779 + if(!args_read_int_and_trim(args, &pin_mode) || pin_mode < 0 || pin_mode > 1) { + ret = GpioParseReturnValueError; + break; + } - if(!pin_name_to_int(pin_name, pin_num)) { - furi_string_free(pin_name); - return GpioParseReturnPinError; - } + *value = pin_mode; + } while(false); furi_string_free(pin_name); - - if(!furi_string_cmp(args, "0")) { - *value = 0; - } else if(!furi_string_cmp(args, "1")) { - *value = 1; - } else { - return GpioParseReturnValueError; - } - - return GpioParseReturnOk; + return ret; } void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) { @@ -111,7 +105,7 @@ void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) { if(err == GpioParseReturnCmdSyntaxError) { cli_print_usage("gpio mode", " <0|1>", furi_string_get_cstr(args)); return; - } else if(err == GpioParseReturnPinError) { + } else if(err == GpioParseReturnPinError) { //-V547 gpio_print_pins(); return; } else if(err == GpioParseReturnValueError) { @@ -119,7 +113,7 @@ void cli_command_gpio_mode(Cli* cli, FuriString* args, void* context) { return; } - if(cli_command_gpio_pins[num].debug) { + if(cli_command_gpio_pins[num].debug) { //-V779 printf( "Changing this pin mode may damage hardware. Are you sure you want to continue? (y/n)?\r\n"); char c = cli_getc(cli); @@ -149,7 +143,7 @@ void cli_command_gpio_read(Cli* cli, FuriString* args, void* context) { return; } - if(LL_GPIO_MODE_INPUT != + if(LL_GPIO_MODE_INPUT != //-V779 LL_GPIO_GetPinMode( cli_command_gpio_pins[num].pin->port, cli_command_gpio_pins[num].pin->pin)) { printf("Err: pin %s is not set as an input.", cli_command_gpio_pins[num].name); @@ -171,7 +165,7 @@ void cli_command_gpio_set(Cli* cli, FuriString* args, void* context) { if(err == GpioParseReturnCmdSyntaxError) { cli_print_usage("gpio set", " <0|1>", furi_string_get_cstr(args)); return; - } else if(err == GpioParseReturnPinError) { + } else if(err == GpioParseReturnPinError) { //-V547 gpio_print_pins(); return; } else if(err == GpioParseReturnValueError) { @@ -179,7 +173,7 @@ void cli_command_gpio_set(Cli* cli, FuriString* args, void* context) { return; } - if(LL_GPIO_MODE_OUTPUT != + if(LL_GPIO_MODE_OUTPUT != //-V779 LL_GPIO_GetPinMode( cli_command_gpio_pins[num].pin->port, cli_command_gpio_pins[num].pin->pin)) { printf("Err: pin %s is not set as an output.", cli_command_gpio_pins[num].name); diff --git a/applications/services/cli/cli_commands.c b/applications/services/cli/cli_commands.c index 3534a541..4414d365 100644 --- a/applications/services/cli/cli_commands.c +++ b/applications/services/cli/cli_commands.c @@ -354,7 +354,7 @@ void cli_command_ps(Cli* cli, FuriString* args, void* context) { for(uint8_t i = 0; i < thread_num; i++) { TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i]; printf( - "%-20s 0x%-12lx %-8d %-8ld %-8ld\r\n", + "%-20s 0x%-12lx %-8zu %-8lu %-8lu\r\n", furi_thread_get_name(threads_ids[i]), (uint32_t)tcb->pxStack, memmgr_heap_get_thread_memory(threads_ids[i]), @@ -369,13 +369,13 @@ void cli_command_free(Cli* cli, FuriString* args, void* context) { UNUSED(args); UNUSED(context); - printf("Free heap size: %d\r\n", memmgr_get_free_heap()); - printf("Total heap size: %d\r\n", memmgr_get_total_heap()); - printf("Minimum heap size: %d\r\n", memmgr_get_minimum_free_heap()); - printf("Maximum heap block: %d\r\n", memmgr_heap_get_max_free_block()); + printf("Free heap size: %zu\r\n", memmgr_get_free_heap()); + printf("Total heap size: %zu\r\n", memmgr_get_total_heap()); + printf("Minimum heap size: %zu\r\n", memmgr_get_minimum_free_heap()); + printf("Maximum heap block: %zu\r\n", memmgr_heap_get_max_free_block()); - printf("Pool free: %d\r\n", memmgr_pool_get_free()); - printf("Maximum pool block: %d\r\n", memmgr_pool_get_max_block()); + printf("Pool free: %zu\r\n", memmgr_pool_get_free()); + printf("Maximum pool block: %zu\r\n", memmgr_pool_get_max_block()); } void cli_command_free_blocks(Cli* cli, FuriString* args, void* context) { diff --git a/applications/services/crypto/crypto_cli.c b/applications/services/crypto/crypto_cli.c index 1b26ba9f..a286f445 100644 --- a/applications/services/crypto/crypto_cli.c +++ b/applications/services/crypto/crypto_cli.c @@ -142,7 +142,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) { if(args_read_hex_bytes(hex_input, input, size)) { if(furi_hal_crypto_decrypt(input, output, size)) { printf("Decrypted data:\r\n"); - printf("%s\r\n", output); + printf("%s\r\n", output); //-V576 } else { printf("Failed to decrypt\r\n"); } diff --git a/applications/services/desktop/animations/animation_manager.c b/applications/services/desktop/animations/animation_manager.c index 9c22d131..f4c8f17a 100644 --- a/applications/services/desktop/animations/animation_manager.c +++ b/applications/services/desktop/animations/animation_manager.c @@ -244,10 +244,8 @@ static bool animation_manager_check_blocking(AnimationManager* animation_manager furi_record_close(RECORD_DOLPHIN); if(!blocking_animation && stats.level_up_is_pending) { blocking_animation = animation_storage_find_animation(NEW_MAIL_ANIMATION_NAME); - furi_assert(blocking_animation); - if(blocking_animation) { - animation_manager->levelup_pending = true; - } + furi_check(blocking_animation); + animation_manager->levelup_pending = true; } if(blocking_animation) { @@ -448,7 +446,7 @@ void animation_manager_unload_and_stall_animation(AnimationManager* animation_ma if(animation_manager->state == AnimationManagerStateBlocked) { animation_manager->state = AnimationManagerStateFreezedBlocked; - } else if(animation_manager->state == AnimationManagerStateIdle) { + } else if(animation_manager->state == AnimationManagerStateIdle) { //-V547 animation_manager->state = AnimationManagerStateFreezedIdle; animation_manager->freezed_animation_time_left = @@ -491,7 +489,7 @@ void animation_manager_load_and_continue_animation(AnimationManager* animation_m furi_assert(restore_animation); animation_manager_replace_current_animation(animation_manager, restore_animation); animation_manager->state = AnimationManagerStateBlocked; - } else if(animation_manager->state == AnimationManagerStateFreezedIdle) { + } else if(animation_manager->state == AnimationManagerStateFreezedIdle) { //-V547 /* check if we missed some system notifications, and set current_animation */ bool blocked = animation_manager_check_blocking(animation_manager); if(!blocked) { diff --git a/applications/services/desktop/animations/animation_storage.c b/applications/services/desktop/animations/animation_storage.c index 0727fd6a..2c16cf72 100644 --- a/applications/services/desktop/animations/animation_storage.c +++ b/applications/services/desktop/animations/animation_storage.c @@ -360,7 +360,6 @@ static bool animation_storage_load_bubbles(BubbleAnimation* animation, FlipperFo if(u32value > 20) break; animation->frame_bubble_sequences_count = u32value; if(animation->frame_bubble_sequences_count == 0) { - animation->frame_bubble_sequences = NULL; success = true; break; } @@ -481,7 +480,7 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) { if(!animation_storage_load_frames(storage, name, animation, u32array, width, height)) break; - if(!flipper_format_read_uint32(ff, "Active cycles", &u32value, 1)) break; + if(!flipper_format_read_uint32(ff, "Active cycles", &u32value, 1)) break; //-V779 animation->active_cycles = u32value; if(!flipper_format_read_uint32(ff, "Frame rate", &u32value, 1)) break; FURI_CONST_ASSIGN(animation->icon_animation.frame_rate, u32value); @@ -500,7 +499,7 @@ static BubbleAnimation* animation_storage_load_animation(const char* name) { free(u32array); } - if(!success) { + if(!success) { //-V547 if(animation->frame_order) { free((void*)animation->frame_order); } diff --git a/applications/services/desktop/helpers/slideshow.c b/applications/services/desktop/helpers/slideshow.c index b4d85cb9..a8e13277 100644 --- a/applications/services/desktop/helpers/slideshow.c +++ b/applications/services/desktop/helpers/slideshow.c @@ -41,7 +41,7 @@ Slideshow* slideshow_alloc() { void slideshow_free(Slideshow* slideshow) { Icon* icon = &slideshow->icon; - if(icon) { + if(icon) { //-V547 for(int frame_idx = 0; frame_idx < icon->frame_count; ++frame_idx) { uint8_t* frame_data = (uint8_t*)icon->frames[frame_idx]; free(frame_data); diff --git a/applications/services/desktop/views/desktop_view_debug.c b/applications/services/desktop/views/desktop_view_debug.c index f9c8aedc..e679cf63 100644 --- a/applications/services/desktop/views/desktop_view_debug.c +++ b/applications/services/desktop/views/desktop_view_debug.c @@ -52,7 +52,7 @@ void desktop_debug_render(Canvas* canvas, void* model) { #ifdef SRV_BT c2_ver = ble_glue_get_c2_info(); #endif - if(!ver) { + if(!ver) { //-V1051 canvas_draw_str(canvas, 0, 30 + STATUS_BAR_Y_SHIFT, "No info"); return; } @@ -88,19 +88,19 @@ void desktop_debug_render(Canvas* canvas, void* model) { uint32_t remaining = dolphin_state_xp_to_levelup(m->icounter); canvas_set_font(canvas, FontSecondary); - snprintf(buffer, sizeof(buffer), "Icounter: %ld Butthurt %ld", m->icounter, m->butthurt); + snprintf(buffer, sizeof(buffer), "Icounter: %lu Butthurt %lu", m->icounter, m->butthurt); canvas_draw_str(canvas, 5, 19 + STATUS_BAR_Y_SHIFT, buffer); snprintf( buffer, sizeof(buffer), - "Level: %ld To level up: %ld", + "Level: %lu To level up: %lu", current_lvl, (remaining == (uint32_t)(-1) ? remaining : 0)); canvas_draw_str(canvas, 5, 29 + STATUS_BAR_Y_SHIFT, buffer); // even if timestamp is uint64_t, it's safe to cast it to uint32_t, because furi_hal_rtc_datetime_to_timestamp only returns uint32_t - snprintf(buffer, sizeof(buffer), "%ld", (uint32_t)m->timestamp); + snprintf(buffer, sizeof(buffer), "%lu", (uint32_t)m->timestamp); canvas_draw_str(canvas, 5, 39 + STATUS_BAR_Y_SHIFT, buffer); canvas_draw_str(canvas, 0, 49 + STATUS_BAR_Y_SHIFT, "[< >] icounter value [ok] save"); diff --git a/applications/services/desktop/views/desktop_view_lock_menu.c b/applications/services/desktop/views/desktop_view_lock_menu.c index 486be23b..52570f8c 100644 --- a/applications/services/desktop/views/desktop_view_lock_menu.c +++ b/applications/services/desktop/views/desktop_view_lock_menu.c @@ -53,7 +53,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { canvas_draw_icon(canvas, 116, 0 + STATUS_BAR_Y_SHIFT, &I_DoorRight_70x55); canvas_set_font(canvas, FontSecondary); - for(uint8_t i = 0; i < DesktopLockMenuIndexTotalCount; ++i) { + for(size_t i = 0; i < DesktopLockMenuIndexTotalCount; ++i) { const char* str = NULL; if(i == DesktopLockMenuIndexLock) { @@ -64,7 +64,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { } else { str = "Set PIN"; } - } else if(i == DesktopLockMenuIndexDummy) { + } else if(i == DesktopLockMenuIndexDummy) { //-V547 if(m->dummy_mode) { str = "Brainiac Mode"; } else { @@ -72,7 +72,7 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) { } } - if(str) + if(str) //-V547 canvas_draw_str_aligned( canvas, 64, 9 + (i * 17) + STATUS_BAR_Y_SHIFT, AlignCenter, AlignCenter, str); diff --git a/applications/services/desktop/views/desktop_view_pin_timeout.c b/applications/services/desktop/views/desktop_view_pin_timeout.c index 6e1e807f..e64c264f 100644 --- a/applications/services/desktop/views/desktop_view_pin_timeout.c +++ b/applications/services/desktop/views/desktop_view_pin_timeout.c @@ -67,7 +67,7 @@ static void desktop_view_pin_timeout_draw(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontSecondary); char str[30] = {0}; - snprintf(str, sizeof(str), "Timeout: %lds", model->time_left); + snprintf(str, sizeof(str), "Timeout: %lus", model->time_left); canvas_draw_str_aligned(canvas, 64, 38, AlignCenter, AlignCenter, str); } diff --git a/applications/services/dolphin/helpers/dolphin_state.c b/applications/services/dolphin/helpers/dolphin_state.c index 10cb85c2..14f08046 100644 --- a/applications/services/dolphin/helpers/dolphin_state.c +++ b/applications/services/dolphin/helpers/dolphin_state.c @@ -171,7 +171,7 @@ void dolphin_state_on_deed(DolphinState* dolphin_state, DolphinDeed deed) { FURI_LOG_D( TAG, - "icounter %ld, butthurt %ld", + "icounter %lu, butthurt %ld", dolphin_state->data.icounter, dolphin_state->data.butthurt); } diff --git a/applications/services/gui/elements.c b/applications/services/gui/elements.c index 6b796ed5..cd4c105a 100644 --- a/applications/services/gui/elements.c +++ b/applications/services/gui/elements.c @@ -291,11 +291,11 @@ void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* t end = strchr(start, '\n'); if(end) { furi_string_set_strn(str, start, end - start); + start = end + 1; } else { furi_string_set(str, start); } canvas_draw_str(canvas, x, y, furi_string_get_cstr(str)); - start = end + 1; y += font_height; } while(end && y < 64); furi_string_free(str); diff --git a/applications/services/gui/modules/button_panel.c b/applications/services/gui/modules/button_panel.c index 47b6ed48..8f29c654 100644 --- a/applications/services/gui/modules/button_panel.c +++ b/applications/services/gui/modules/button_panel.c @@ -172,7 +172,7 @@ void button_panel_add_item( void* callback_context) { furi_assert(button_panel); - with_view_model( + with_view_model( //-V773 button_panel->view, ButtonPanelModel * model, { diff --git a/applications/services/gui/modules/byte_input.c b/applications/services/gui/modules/byte_input.c index bc19f0ee..82de129f 100644 --- a/applications/services/gui/modules/byte_input.c +++ b/applications/services/gui/modules/byte_input.c @@ -71,11 +71,13 @@ static uint8_t byte_input_get_row_size(uint8_t row_index) { switch(row_index + 1) { case 1: - row_size = sizeof(keyboard_keys_row_1) / sizeof(ByteInputKey); + row_size = COUNT_OF(keyboard_keys_row_1); break; case 2: - row_size = sizeof(keyboard_keys_row_2) / sizeof(ByteInputKey); + row_size = COUNT_OF(keyboard_keys_row_2); break; + default: + furi_crash(NULL); } return row_size; @@ -97,6 +99,8 @@ static const ByteInputKey* byte_input_get_row(uint8_t row_index) { case 2: row = keyboard_keys_row_2; break; + default: + furi_crash(NULL); } return row; @@ -383,6 +387,7 @@ static void byte_input_dec_selected_byte(ByteInputModel* model) { if(model->selected_byte > 0) { model->selected_byte -= 1; + furi_assert(model->selected_byte >= model->first_visible_byte); if(model->selected_byte - model->first_visible_byte < 1) { if(model->first_visible_byte > 0) { model->first_visible_byte--; diff --git a/applications/services/gui/modules/file_browser.c b/applications/services/gui/modules/file_browser.c index 57e0018e..d21a48b5 100644 --- a/applications/services/gui/modules/file_browser.c +++ b/applications/services/gui/modules/file_browser.c @@ -514,7 +514,7 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) { scroll_counter = 0; } - if(custom_icon_data) { + if(custom_icon_data) { //-V547 // Currently only 10*10 icons are supported canvas_draw_bitmap( canvas, 2, Y_OFFSET + 1 + i * FRAME_HEIGHT, 10, 10, custom_icon_data); @@ -657,9 +657,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) { if(!is_root && !file_browser_worker_is_in_start_folder(browser->worker)) { consumed = true; - if(!is_root) { - file_browser_worker_folder_exit(browser->worker); - } + file_browser_worker_folder_exit(browser->worker); } } } diff --git a/applications/services/gui/modules/file_browser_worker.c b/applications/services/gui/modules/file_browser_worker.c index d8b515d0..a97a4d71 100644 --- a/applications/services/gui/modules/file_browser_worker.c +++ b/applications/services/gui/modules/file_browser_worker.c @@ -375,7 +375,7 @@ BrowserWorker* file_browser_worker_alloc( const char* filter_ext, bool skip_assets, bool hide_dot_files) { - BrowserWorker* browser = malloc(sizeof(BrowserWorker)); //-V773 + BrowserWorker* browser = malloc(sizeof(BrowserWorker)); idx_last_array_init(browser->idx_last); @@ -395,7 +395,7 @@ BrowserWorker* file_browser_worker_alloc( furi_thread_start(browser->thread); return browser; -} +} //-V773 void file_browser_worker_free(BrowserWorker* browser) { furi_assert(browser); diff --git a/applications/services/gui/modules/submenu.c b/applications/services/gui/modules/submenu.c index b7152a3d..f8af44fd 100644 --- a/applications/services/gui/modules/submenu.c +++ b/applications/services/gui/modules/submenu.c @@ -225,8 +225,11 @@ void submenu_set_selected_item(Submenu* submenu, uint32_t index) { if(items_size <= items_on_screen) { model->window_position = 0; - } else if(model->window_position >= items_size - items_on_screen) { - model->window_position = items_size - items_on_screen; + } else { + const size_t pos = items_size - items_on_screen; + if(model->window_position > pos) { + model->window_position = pos; + } } }, true); @@ -242,8 +245,7 @@ void submenu_process_up(Submenu* submenu) { if(model->position > 0) { model->position--; - if((model->position - model->window_position < 1) && - (model->window_position > 0)) { + if((model->position == model->window_position) && (model->window_position > 0)) { model->window_position--; } } else { diff --git a/applications/services/gui/modules/text_input.c b/applications/services/gui/modules/text_input.c index 540e4b7c..7c419d96 100644 --- a/applications/services/gui/modules/text_input.c +++ b/applications/services/gui/modules/text_input.c @@ -92,14 +92,16 @@ static uint8_t get_row_size(uint8_t row_index) { switch(row_index + 1) { case 1: - row_size = sizeof(keyboard_keys_row_1) / sizeof(TextInputKey); + row_size = COUNT_OF(keyboard_keys_row_1); break; case 2: - row_size = sizeof(keyboard_keys_row_2) / sizeof(TextInputKey); + row_size = COUNT_OF(keyboard_keys_row_2); break; case 3: - row_size = sizeof(keyboard_keys_row_3) / sizeof(TextInputKey); + row_size = COUNT_OF(keyboard_keys_row_3); break; + default: + furi_crash(NULL); } return row_size; @@ -118,6 +120,8 @@ static const TextInputKey* get_row(uint8_t row_index) { case 3: row = keyboard_keys_row_3; break; + default: + furi_crash(NULL); } return row; @@ -184,7 +188,7 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontKeyboard); - for(uint8_t row = 0; row <= keyboard_row_count; row++) { + for(uint8_t row = 0; row < keyboard_row_count; row++) { const uint8_t column_count = get_row_size(row); const TextInputKey* keys = get_row(row); @@ -303,7 +307,7 @@ static void text_input_handle_right(TextInput* text_input, TextInputModel* model static void text_input_handle_ok(TextInput* text_input, TextInputModel* model, bool shift) { char selected = get_selected_char(model); - uint8_t text_length = strlen(model->text_buffer); + size_t text_length = strlen(model->text_buffer); if(shift) { selected = char_to_uppercase(selected); @@ -481,7 +485,6 @@ void text_input_reset(TextInput* text_input) { text_input->view, TextInputModel * model, { - model->text_buffer_size = 0; model->header = ""; model->selected_row = 0; model->selected_column = 0; diff --git a/applications/services/gui/modules/validators.c b/applications/services/gui/modules/validators.c index 0463b1c2..9c5d0be8 100644 --- a/applications/services/gui/modules/validators.c +++ b/applications/services/gui/modules/validators.c @@ -18,15 +18,12 @@ bool validator_is_file_callback(const char* text, FuriString* error, void* conte } } - bool ret = true; FuriString* path = furi_string_alloc_printf( "%s/%s%s", instance->app_path_folder, text, instance->app_extension); Storage* storage = furi_record_open(RECORD_STORAGE); - if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) { - ret = false; + const bool ret = storage_common_stat(storage, furi_string_get_cstr(path), NULL) != FSE_OK; + if(!ret) { furi_string_printf(error, "This name\nexists!\nChoose\nanother one."); - } else { - ret = true; } furi_string_free(path); furi_record_close(RECORD_STORAGE); diff --git a/applications/services/gui/modules/variable_item_list.c b/applications/services/gui/modules/variable_item_list.c index a9b89d63..5060985e 100644 --- a/applications/services/gui/modules/variable_item_list.c +++ b/applications/services/gui/modules/variable_item_list.c @@ -188,8 +188,8 @@ void variable_item_list_process_up(VariableItemList* variable_item_list) { uint8_t items_on_screen = 4; if(model->position > 0) { model->position--; - if(((model->position - model->window_position) < 1) && - model->window_position > 0) { + + if((model->position == model->window_position) && (model->window_position > 0)) { model->window_position--; } } else { diff --git a/applications/services/gui/modules/widget_elements/widget_element_button.c b/applications/services/gui/modules/widget_elements/widget_element_button.c index e3267058..3bfae9df 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_button.c +++ b/applications/services/gui/modules/widget_elements/widget_element_button.c @@ -60,7 +60,7 @@ WidgetElement* widget_element_button_create( ButtonCallback callback, void* context) { // Allocate and init model - GuiButtonModel* model = malloc(sizeof(GuiButtonModel)); //-V773 + GuiButtonModel* model = malloc(sizeof(GuiButtonModel)); model->button_type = button_type; model->callback = callback; model->context = context; @@ -75,4 +75,4 @@ WidgetElement* widget_element_button_create( gui_button->model = model; return gui_button; -} +} //-V773 diff --git a/applications/services/gui/modules/widget_elements/widget_element_string.c b/applications/services/gui/modules/widget_elements/widget_element_string.c index feb22ad1..4bf7dd69 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_string.c +++ b/applications/services/gui/modules/widget_elements/widget_element_string.c @@ -62,4 +62,4 @@ WidgetElement* widget_element_string_create( gui_string->model = model; return gui_string; -} +} //-V773 diff --git a/applications/services/gui/modules/widget_elements/widget_element_string_multiline.c b/applications/services/gui/modules/widget_elements/widget_element_string_multiline.c index 9ad2a1a8..3fc6b309 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_string_multiline.c +++ b/applications/services/gui/modules/widget_elements/widget_element_string_multiline.c @@ -63,4 +63,4 @@ WidgetElement* widget_element_string_multiline_create( gui_string->model = model; return gui_string; -} +} //-V773 diff --git a/applications/services/gui/modules/widget_elements/widget_element_text_box.c b/applications/services/gui/modules/widget_elements/widget_element_text_box.c index 2c694820..98f8e83d 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_text_box.c +++ b/applications/services/gui/modules/widget_elements/widget_element_text_box.c @@ -71,4 +71,4 @@ WidgetElement* widget_element_text_box_create( gui_string->model = model; return gui_string; -} +} //-V773 diff --git a/applications/services/gui/modules/widget_elements/widget_element_text_scroll.c b/applications/services/gui/modules/widget_elements/widget_element_text_scroll.c index a4d76638..d8fc1131 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_text_scroll.c +++ b/applications/services/gui/modules/widget_elements/widget_element_text_scroll.c @@ -241,4 +241,4 @@ WidgetElement* widget_element_text_scroll_create( text_scroll->model_mutex = furi_mutex_alloc(FuriMutexTypeNormal); return text_scroll; -} +} //-V773 diff --git a/applications/services/gui/view.c b/applications/services/gui/view.c index 7ab6d15b..50c05a40 100644 --- a/applications/services/gui/view.c +++ b/applications/services/gui/view.c @@ -86,7 +86,7 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) { model->data = malloc(size); view->model = model; } else { - furi_assert(false); + furi_crash(NULL); } } @@ -103,7 +103,7 @@ void view_free_model(View* view) { free(model); view->model = NULL; } else { - furi_assert(false); + furi_crash(NULL); } } diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 1d02df1e..e1e581c9 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -80,9 +80,7 @@ int32_t input_srv(void* p) { #ifdef SRV_CLI input->cli = furi_record_open(RECORD_CLI); - if(input->cli) { - cli_add_command(input->cli, "input", CliCommandFlagParallelSafe, input_cli, input); - } + cli_add_command(input->cli, "input", CliCommandFlagParallelSafe, input_cli, input); #endif input->pin_states = malloc(input_pins_count * sizeof(InputPinState)); diff --git a/applications/services/input/input_cli.c b/applications/services/input/input_cli.c index d9a8eaeb..f7e904b1 100644 --- a/applications/services/input/input_cli.c +++ b/applications/services/input/input_cli.c @@ -89,7 +89,7 @@ static void input_cli_send(Cli* cli, FuriString* args, Input* input) { parsed = true; } while(false); - if(parsed) { + if(parsed) { //-V547 furi_pubsub_publish(input->event_pubsub, &event); } else { input_cli_send_print_usage(); diff --git a/applications/services/loader/loader.c b/applications/services/loader/loader.c index 93171972..97d1e6e4 100644 --- a/applications/services/loader/loader.c +++ b/applications/services/loader/loader.c @@ -280,7 +280,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con furi_hal_power_insomnia_enter(); } } else if(thread_state == FuriThreadStateStopped) { - FURI_LOG_I(TAG, "Application stopped. Free heap: %d", memmgr_get_free_heap()); + FURI_LOG_I(TAG, "Application stopped. Free heap: %zu", memmgr_get_free_heap()); if(loader_instance->application_arguments) { free(loader_instance->application_arguments); diff --git a/applications/services/power/power_service/views/power_off.c b/applications/services/power/power_service/views/power_off.c index f14a18d7..3a1addba 100644 --- a/applications/services/power/power_service/views/power_off.c +++ b/applications/services/power/power_service/views/power_off.c @@ -26,7 +26,7 @@ static void power_off_draw_callback(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontSecondary); if(model->response == PowerOffResponseDefault) { - snprintf(buff, sizeof(buff), "Charge me!\nOff in %lds!", model->time_left_sec); + snprintf(buff, sizeof(buff), "Charge me!\nOff in %lus!", model->time_left_sec); elements_multiline_text_aligned(canvas, 70, 23, AlignLeft, AlignTop, buff); elements_button_left(canvas, "Cancel"); diff --git a/applications/services/rpc/rpc_app.c b/applications/services/rpc/rpc_app.c index b96f043a..cc18b6ce 100644 --- a/applications/services/rpc/rpc_app.c +++ b/applications/services/rpc/rpc_app.c @@ -39,9 +39,9 @@ static void rpc_system_app_start_process(const PB_Main* request, void* context) furi_assert(!rpc_app->last_id); furi_assert(!rpc_app->last_data); - FURI_LOG_D(TAG, "StartProcess: id %ld", request->command_id); + FURI_LOG_D(TAG, "StartProcess: id %lu", request->command_id); - PB_CommandStatus result = PB_CommandStatus_ERROR_APP_CANT_START; + PB_CommandStatus result; Loader* loader = furi_record_open(RECORD_LOADER); const char* app_name = request->content.app_start_request.name; @@ -62,7 +62,7 @@ static void rpc_system_app_start_process(const PB_Main* request, void* context) } else if(status == LoaderStatusOk) { result = PB_CommandStatus_OK; } else { - furi_crash("Programming Error"); + furi_crash(NULL); } } else { result = PB_CommandStatus_ERROR_INVALID_PARAMETERS; @@ -70,7 +70,7 @@ static void rpc_system_app_start_process(const PB_Main* request, void* context) furi_record_close(RECORD_LOADER); - FURI_LOG_D(TAG, "StartProcess: response id %ld, result %d", request->command_id, result); + FURI_LOG_D(TAG, "StartProcess: response id %lu, result %d", request->command_id, result); rpc_send_and_release_empty(session, request->command_id, result); } @@ -117,7 +117,7 @@ static void rpc_system_app_exit_request(const PB_Main* request, void* context) { PB_CommandStatus status; if(rpc_app->app_callback) { - FURI_LOG_D(TAG, "ExitRequest: id %ld", request->command_id); + FURI_LOG_D(TAG, "ExitRequest: id %lu", request->command_id); furi_assert(!rpc_app->last_id); furi_assert(!rpc_app->last_data); rpc_app->last_id = request->command_id; @@ -125,7 +125,7 @@ static void rpc_system_app_exit_request(const PB_Main* request, void* context) { } else { status = PB_CommandStatus_ERROR_APP_NOT_RUNNING; FURI_LOG_E( - TAG, "ExitRequest: APP_NOT_RUNNING, id %ld, status: %d", request->command_id, status); + TAG, "ExitRequest: APP_NOT_RUNNING, id %lu, status: %d", request->command_id, status); rpc_send_and_release_empty(session, request->command_id, status); } } @@ -142,7 +142,7 @@ static void rpc_system_app_load_file(const PB_Main* request, void* context) { PB_CommandStatus status; if(rpc_app->app_callback) { - FURI_LOG_D(TAG, "LoadFile: id %ld", request->command_id); + FURI_LOG_D(TAG, "LoadFile: id %lu", request->command_id); furi_assert(!rpc_app->last_id); furi_assert(!rpc_app->last_data); rpc_app->last_id = request->command_id; @@ -151,7 +151,7 @@ static void rpc_system_app_load_file(const PB_Main* request, void* context) { } else { status = PB_CommandStatus_ERROR_APP_NOT_RUNNING; FURI_LOG_E( - TAG, "LoadFile: APP_NOT_RUNNING, id %ld, status: %d", request->command_id, status); + TAG, "LoadFile: APP_NOT_RUNNING, id %lu, status: %d", request->command_id, status); rpc_send_and_release_empty(session, request->command_id, status); } } @@ -177,7 +177,7 @@ static void rpc_system_app_button_press(const PB_Main* request, void* context) { } else { status = PB_CommandStatus_ERROR_APP_NOT_RUNNING; FURI_LOG_E( - TAG, "ButtonPress: APP_NOT_RUNNING, id %ld, status: %d", request->command_id, status); + TAG, "ButtonPress: APP_NOT_RUNNING, id %lu, status: %d", request->command_id, status); rpc_send_and_release_empty(session, request->command_id, status); } } @@ -202,7 +202,7 @@ static void rpc_system_app_button_release(const PB_Main* request, void* context) } else { status = PB_CommandStatus_ERROR_APP_NOT_RUNNING; FURI_LOG_E( - TAG, "ButtonRelease: APP_NOT_RUNNING, id %ld, status: %d", request->command_id, status); + TAG, "ButtonRelease: APP_NOT_RUNNING, id %lu, status: %d", request->command_id, status); rpc_send_and_release_empty(session, request->command_id, status); } } @@ -300,7 +300,7 @@ void rpc_system_app_confirm(RpcAppSystem* rpc_app, RpcAppSystemEvent event, bool free(rpc_app->last_data); rpc_app->last_data = NULL; } - FURI_LOG_D(TAG, "AppConfirm: event %d last_id %ld status %d", event, last_id, status); + FURI_LOG_D(TAG, "AppConfirm: event %d last_id %lu status %d", event, last_id, status); rpc_send_and_release_empty(session, last_id, status); break; default: diff --git a/applications/services/rpc/rpc_cli.c b/applications/services/rpc/rpc_cli.c index 82023e31..d14b8eee 100644 --- a/applications/services/rpc/rpc_cli.c +++ b/applications/services/rpc/rpc_cli.c @@ -44,7 +44,7 @@ void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context) { Rpc* rpc = context; uint32_t mem_before = memmgr_get_free_heap(); - FURI_LOG_D(TAG, "Free memory %ld", mem_before); + FURI_LOG_D(TAG, "Free memory %lu", mem_before); furi_hal_usb_lock(); RpcSession* rpc_session = rpc_session_open(rpc); diff --git a/applications/services/rpc/rpc_debug.c b/applications/services/rpc/rpc_debug.c index 8eb81dec..edc2b002 100644 --- a/applications/services/rpc/rpc_debug.c +++ b/applications/services/rpc/rpc_debug.c @@ -10,7 +10,7 @@ static size_t rpc_debug_print_file_msg( for(size_t i = 0; i < msg_files_size; ++i, ++msg_file) { furi_string_cat_printf( str, - "%s[%c] size: %5ld", + "%s[%c] size: %5lu", prefix, msg_file->type == PB_Storage_File_FileType_DIR ? 'd' : 'f', msg_file->size); @@ -40,7 +40,7 @@ void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size) { str = furi_string_alloc(); furi_string_reserve(str, 100 + size * 5); - furi_string_cat_printf(str, "\r\n%s DEC(%d): {", prefix, size); + furi_string_cat_printf(str, "\r\n%s DEC(%zu): {", prefix, size); for(size_t i = 0; i < size; ++i) { furi_string_cat_printf(str, "%d, ", buffer[i]); } @@ -50,7 +50,7 @@ void rpc_debug_print_data(const char* prefix, uint8_t* buffer, size_t size) { furi_string_reset(str); furi_string_reserve(str, 100 + size * 3); - furi_string_cat_printf(str, "%s HEX(%d): {", prefix, size); + furi_string_cat_printf(str, "%s HEX(%zu): {", prefix, size); for(size_t i = 0; i < size; ++i) { furi_string_cat_printf(str, "%02X", buffer[i]); } @@ -66,7 +66,7 @@ void rpc_debug_print_message(const PB_Main* message) { furi_string_cat_printf( str, - "PB_Main: {\r\n\tresult: %d cmd_id: %ld (%s)\r\n", + "PB_Main: {\r\n\tresult: %d cmd_id: %lu (%s)\r\n", message->command_status, message->command_id, message->has_next ? "has_next" : "last"); @@ -110,9 +110,9 @@ void rpc_debug_print_message(const PB_Main* message) { } case PB_Main_storage_md5sum_response_tag: { furi_string_cat_printf(str, "\tmd5sum_response {\r\n"); - const char* path = message->content.storage_md5sum_response.md5sum; - if(path) { - furi_string_cat_printf(str, "\t\tmd5sum: %s\r\n", path); + const char* md5sum = message->content.storage_md5sum_response.md5sum; + if(md5sum) { //-V547 + furi_string_cat_printf(str, "\t\tmd5sum: %s\r\n", md5sum); } break; } diff --git a/applications/services/rpc/rpc_storage.c b/applications/services/rpc/rpc_storage.c index 3c6ff7f9..c4493cc7 100644 --- a/applications/services/rpc/rpc_storage.c +++ b/applications/services/rpc/rpc_storage.c @@ -597,7 +597,7 @@ static void rpc_system_storage_md5sum_process(const PB_Main* request, void* cont char* md5sum = response.content.storage_md5sum_response.md5sum; size_t md5sum_size = sizeof(response.content.storage_md5sum_response.md5sum); (void)md5sum_size; - furi_assert(hash_size <= ((md5sum_size - 1) / 2)); + furi_assert(hash_size <= ((md5sum_size - 1) / 2)); //-V547 for(uint8_t i = 0; i < hash_size; i++) { md5sum += snprintf(md5sum, md5sum_size, "%02x", hash[i]); } diff --git a/applications/services/rpc/rpc_system.c b/applications/services/rpc/rpc_system.c index a17be7d2..77dca4a1 100644 --- a/applications/services/rpc/rpc_system.c +++ b/applications/services/rpc/rpc_system.c @@ -30,7 +30,6 @@ static void rpc_system_system_ping_process(const PB_Main* request, void* context } PB_Main response = PB_Main_init_default; - response.has_next = false; response.command_status = PB_CommandStatus_OK; response.command_id = request->command_id; response.which_content = PB_Main_system_ping_response_tag; diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index 2c3a7bfc..6929a9cb 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -385,9 +385,7 @@ FS_Error storage_common_remove(Storage* storage, const char* path) { FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path) { FS_Error error = storage_common_copy(storage, old_path, new_path); if(error == FSE_OK) { - if(storage_simply_remove_recursive(storage, old_path)) { - error = FSE_OK; - } else { + if(!storage_simply_remove_recursive(storage, old_path)) { error = FSE_INTERNAL; } } @@ -743,7 +741,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) { return true; } - char* name = malloc(MAX_NAME_LENGTH + 1); + char* name = malloc(MAX_NAME_LENGTH + 1); //-V799 File* dir = storage_file_alloc(storage); cur_dir = furi_string_alloc_set(path); bool go_deeper = false; @@ -790,7 +788,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) { furi_string_free(cur_dir); free(name); return result; -} +} //-V773 bool storage_simply_remove(Storage* storage, const char* path) { FS_Error result; diff --git a/applications/services/storage/storage_glue.c b/applications/services/storage/storage_glue.c index c6ff08bd..22f2e3df 100644 --- a/applications/services/storage/storage_glue.c +++ b/applications/services/storage/storage_glue.c @@ -17,7 +17,7 @@ void storage_file_init_set(StorageFile* obj, const StorageFile* src) { obj->path = furi_string_alloc_set(src->path); } -void storage_file_set(StorageFile* obj, const StorageFile* src) { +void storage_file_set(StorageFile* obj, const StorageFile* src) { //-V524 obj->file = src->file; obj->type = src->type; obj->file_data = src->file_data; @@ -172,7 +172,6 @@ void storage_push_storage_file( StorageType type, StorageData* storage) { StorageFile* storage_file = StorageFileList_push_new(storage->files); - furi_check(storage_file != NULL); file->file_id = (uint32_t)storage_file; storage_file->file = file; diff --git a/applications/services/storage/storages/storage_int.c b/applications/services/storage/storages/storage_int.c index 4fa5d130..2534d47a 100644 --- a/applications/services/storage/storages/storage_int.c +++ b/applications/services/storage/storages/storage_int.c @@ -77,7 +77,7 @@ static int storage_int_device_read( FURI_LOG_T( TAG, - "Device read: block %ld, off %ld, buffer: %p, size %ld, translated address: %p", + "Device read: block %lu, off %lu, buffer: %p, size %lu, translated address: %p", block, off, buffer, @@ -100,7 +100,7 @@ static int storage_int_device_prog( FURI_LOG_T( TAG, - "Device prog: block %ld, off %ld, buffer: %p, size %ld, translated address: %p", + "Device prog: block %lu, off %lu, buffer: %p, size %lu, translated address: %p", block, off, buffer, @@ -122,7 +122,7 @@ static int storage_int_device_erase(const struct lfs_config* c, lfs_block_t bloc LFSData* lfs_data = c->context; size_t page = lfs_data->start_page + block; - FURI_LOG_D(TAG, "Device erase: page %ld, translated page: %x", block, page); + FURI_LOG_D(TAG, "Device erase: page %lu, translated page: %zx", block, page); furi_hal_flash_erase(page); return 0; @@ -240,56 +240,38 @@ static void storage_int_lfs_mount(LFSData* lfs_data, StorageData* storage) { /****************** Common Functions ******************/ static FS_Error storage_int_parse_error(int error) { - FS_Error result = FSE_INTERNAL; + FS_Error result; if(error >= LFS_ERR_OK) { result = FSE_OK; } else { switch(error) { - case LFS_ERR_IO: - result = FSE_INTERNAL; - break; - case LFS_ERR_CORRUPT: - result = FSE_INTERNAL; - break; case LFS_ERR_NOENT: result = FSE_NOT_EXIST; break; case LFS_ERR_EXIST: result = FSE_EXIST; break; - case LFS_ERR_NOTDIR: - result = FSE_INVALID_NAME; - break; - case LFS_ERR_ISDIR: - result = FSE_INVALID_NAME; - break; case LFS_ERR_NOTEMPTY: result = FSE_DENIED; break; - case LFS_ERR_BADF: - result = FSE_INVALID_NAME; - break; - case LFS_ERR_FBIG: - result = FSE_INTERNAL; - break; case LFS_ERR_INVAL: - result = FSE_INVALID_PARAMETER; - break; - case LFS_ERR_NOSPC: - result = FSE_INTERNAL; - break; - case LFS_ERR_NOMEM: - result = FSE_INTERNAL; - break; case LFS_ERR_NOATTR: result = FSE_INVALID_PARAMETER; break; + case LFS_ERR_BADF: + case LFS_ERR_ISDIR: + case LFS_ERR_NOTDIR: case LFS_ERR_NAMETOOLONG: result = FSE_INVALID_NAME; break; + case LFS_ERR_IO: + case LFS_ERR_FBIG: + case LFS_ERR_NOSPC: + case LFS_ERR_NOMEM: + case LFS_ERR_CORRUPT: default: - break; + result = FSE_INTERNAL; } } @@ -740,7 +722,7 @@ void storage_int_init(StorageData* storage) { LFSData* lfs_data = storage_int_lfs_data_alloc(); FURI_LOG_I( TAG, - "Config: start %p, read %ld, write %ld, page size: %ld, page count: %ld, cycles: %ld", + "Config: start %p, read %lu, write %lu, page size: %lu, page count: %lu, cycles: %ld", (void*)lfs_data->start_address, lfs_data->config.read_size, lfs_data->config.prog_size, diff --git a/applications/settings/about/about.c b/applications/settings/about/about.c index 1719e188..560a683c 100644 --- a/applications/settings/about/about.c +++ b/applications/settings/about/about.c @@ -119,7 +119,7 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* c2_ver = ble_glue_get_c2_info(); #endif - if(!ver) { + if(!ver) { //-V1051 furi_string_cat_printf(buffer, "No info\n"); } else { furi_string_cat_printf( @@ -208,4 +208,4 @@ int32_t about_settings_app(void* p) { furi_record_close(RECORD_GUI); return 0; -} \ No newline at end of file +} diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index cf474c54..94c5ee9f 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -84,7 +84,7 @@ bool desktop_settings_scene_favorite_on_event(void* context, SceneManagerEvent e scene_manager_get_scene_state(app->scene_manager, DesktopSettingsAppSceneFavorite); if(event.type == SceneManagerEventTypeCustom) { - if(strcmp(FLIPPER_APPS[event.event].name, FAP_LOADER_APP_NAME)) { + if(strcmp(FLIPPER_APPS[event.event].name, FAP_LOADER_APP_NAME) != 0) { if(primary_favorite) { app->settings.favorite_primary.is_external = false; strncpy( diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto.c index b8d630f2..ec128246 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto.c @@ -32,9 +32,7 @@ bool desktop_settings_scene_pin_setup_howto_on_event(void* context, SceneManager consumed = true; break; default: - furi_assert(0); - consumed = true; - break; + furi_crash(NULL); } } return consumed; diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto2.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto2.c index 477d1f27..44b8e1bf 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto2.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup_howto2.c @@ -52,9 +52,7 @@ bool desktop_settings_scene_pin_setup_howto2_on_event(void* context, SceneManage break; } default: - furi_assert(0); - consumed = true; - break; + furi_crash(NULL); } } return consumed; diff --git a/applications/settings/power_settings_app/views/battery_info.c b/applications/settings/power_settings_app/views/battery_info.c index d760164b..5353a2e2 100644 --- a/applications/settings/power_settings_app/views/battery_info.c +++ b/applications/settings/power_settings_app/views/battery_info.c @@ -49,7 +49,7 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { snprintf( value, sizeof(value), - "%ld.%ldV %ldmA", + "%lu.%luV %lumA", (uint32_t)(data->vbus_voltage), (uint32_t)(data->vbus_voltage * 10) % 10, charge_current); @@ -75,7 +75,7 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { snprintf( value, sizeof(value), - "%ld.%ldV", + "%lu.%luV", (uint32_t)(data->charging_voltage), (uint32_t)(data->charging_voltage * 10) % 10); } else { @@ -100,14 +100,14 @@ static void battery_info_draw_callback(Canvas* canvas, void* context) { char voltage[10]; char health[10]; - snprintf(batt_level, sizeof(batt_level), "%ld%%", (uint32_t)model->charge); - snprintf(temperature, sizeof(temperature), "%ld C", (uint32_t)model->gauge_temperature); + snprintf(batt_level, sizeof(batt_level), "%lu%%", (uint32_t)model->charge); + snprintf(temperature, sizeof(temperature), "%lu C", (uint32_t)model->gauge_temperature); snprintf( voltage, sizeof(voltage), - "%ld.%01ld V", + "%lu.%01lu V", (uint32_t)model->gauge_voltage, - (uint32_t)(model->gauge_voltage * 10) % 10); + (uint32_t)(model->gauge_voltage * 10) % 10UL); snprintf(health, sizeof(health), "%d%%", model->health); draw_stat(canvas, 8, 42, &I_Battery_16x16, batt_level); diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_format_confirm.c b/applications/settings/storage_settings/scenes/storage_settings_scene_format_confirm.c index 261ef199..8af065bf 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_format_confirm.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_format_confirm.c @@ -40,8 +40,6 @@ bool storage_settings_scene_format_confirm_on_event(void* context, SceneManagerE if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case DialogExResultLeft: - consumed = scene_manager_previous_scene(app->scene_manager); - break; case DialogExResultCenter: consumed = scene_manager_previous_scene(app->scene_manager); break; diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c index ede610d0..0c398ed5 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_sd_info.c @@ -47,8 +47,6 @@ bool storage_settings_scene_sd_info_on_event(void* context, SceneManagerEvent ev if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case DialogExResultLeft: - consumed = scene_manager_previous_scene(app->scene_manager); - break; case DialogExResultCenter: consumed = scene_manager_previous_scene(app->scene_manager); break; diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_unmount_confirm.c b/applications/settings/storage_settings/scenes/storage_settings_scene_unmount_confirm.c index 2b485b7f..0c15116b 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_unmount_confirm.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_unmount_confirm.c @@ -41,8 +41,6 @@ bool storage_settings_scene_unmount_confirm_on_event(void* context, SceneManager if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { case DialogExResultCenter: - consumed = scene_manager_previous_scene(app->scene_manager); - break; case DialogExResultLeft: consumed = scene_manager_previous_scene(app->scene_manager); break; diff --git a/applications/system/updater/util/update_task_worker_backup.c b/applications/system/updater/util/update_task_worker_backup.c index ce62da2a..1f88d4f4 100644 --- a/applications/system/updater/util/update_task_worker_backup.c +++ b/applications/system/updater/util/update_task_worker_backup.c @@ -176,7 +176,7 @@ int32_t update_task_worker_backup_restore(void* context) { if(boot_mode == FuriHalRtcBootModePreUpdate) { success = update_task_pre_update(update_task); - } else if(boot_mode == FuriHalRtcBootModePostUpdate) { + } else if(boot_mode == FuriHalRtcBootModePostUpdate) { //-V547 success = update_task_post_update(update_task); if(success) { update_operation_disarm(); diff --git a/applications/system/updater/util/update_task_worker_flasher.c b/applications/system/updater/util/update_task_worker_flasher.c index 7358a633..63024ced 100644 --- a/applications/system/updater/util/update_task_worker_flasher.c +++ b/applications/system/updater/util/update_task_worker_flasher.c @@ -143,7 +143,6 @@ static void update_task_wait_for_restart(UpdateTask* update_task) { } static bool update_task_write_stack(UpdateTask* update_task) { - bool success = false; UpdateManifest* manifest = update_task->manifest; do { FURI_LOG_W(TAG, "Writing stack"); @@ -162,13 +161,11 @@ static bool update_task_write_stack(UpdateTask* update_task) { update_task_set_progress(update_task, UpdateTaskStageRadioInstall, 100); /* ...system will restart here. */ update_task_wait_for_restart(update_task); - success = true; } while(false); - return success; + return false; /* will return only in the case of failure */ } static bool update_task_remove_stack(UpdateTask* update_task) { - bool success = false; do { FURI_LOG_W(TAG, "Removing stack"); update_task_set_progress(update_task, UpdateTaskStageRadioErase, 30); @@ -178,9 +175,8 @@ static bool update_task_remove_stack(UpdateTask* update_task) { update_task_set_progress(update_task, UpdateTaskStageRadioErase, 100); /* ...system will restart here. */ update_task_wait_for_restart(update_task); - success = true; } while(false); - return success; + return false; /* will return only in the case of failure */ } static bool update_task_manage_radiostack(UpdateTask* update_task) { diff --git a/debug/gdbinit b/debug/gdbinit new file mode 100644 index 00000000..cba5d6b1 --- /dev/null +++ b/debug/gdbinit @@ -0,0 +1,10 @@ +set confirm off +set pagination off +set print pretty on +set print object on +set print static-members on +set print vtbl on +set print demangle on +set demangle-style gnu-v3 +set print sevenbit-strings off + diff --git a/firmware/targets/f7/Src/update.c b/firmware/targets/f7/Src/update.c index 722a7b61..a68a8b7a 100644 --- a/firmware/targets/f7/Src/update.c +++ b/firmware/targets/f7/Src/update.c @@ -149,7 +149,7 @@ static UpdateManifest* flipper_update_process_manifest(const FuriString* manifes do { uint16_t size_read = 0; - if(f_read(&file, manifest_data + bytes_read, MAX_READ, &size_read) != FR_OK) { + if(f_read(&file, manifest_data + bytes_read, MAX_READ, &size_read) != FR_OK) { //-V769 break; } bytes_read += size_read; diff --git a/firmware/targets/f7/ble_glue/ble_glue.c b/firmware/targets/f7/ble_glue/ble_glue.c index b3752f17..83562c73 100644 --- a/firmware/targets/f7/ble_glue/ble_glue.c +++ b/firmware/targets/f7/ble_glue/ble_glue.c @@ -456,17 +456,15 @@ BleGlueCommandResult ble_glue_fus_get_status() { BleGlueCommandResult ble_glue_fus_wait_operation() { furi_check(ble_glue->c2_info.mode == BleGlueC2ModeFUS); - bool wip; - do { - BleGlueCommandResult fus_status = ble_glue_fus_get_status(); - if(fus_status == BleGlueCommandResultError) { - return BleGlueCommandResultError; - } - wip = fus_status == BleGlueCommandResultOperationOngoing; - if(wip) { - furi_delay_ms(20); - } - } while(wip); - return BleGlueCommandResultOK; + while(true) { + BleGlueCommandResult fus_status = ble_glue_fus_get_status(); + if(fus_status == BleGlueCommandResultOperationOngoing) { + furi_delay_ms(20); + } else if(fus_status == BleGlueCommandResultError) { + return BleGlueCommandResultError; + } else { + return BleGlueCommandResultOK; + } + } } diff --git a/firmware/targets/f7/ble_glue/gap.c b/firmware/targets/f7/ble_glue/gap.c index 3e29527e..8ef037d6 100644 --- a/firmware/targets/f7/ble_glue/gap.c +++ b/firmware/targets/f7/ble_glue/gap.c @@ -227,7 +227,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) { case EVT_BLUE_GAP_NUMERIC_COMPARISON_VALUE: { uint32_t pin = ((aci_gap_numeric_comparison_value_event_rp0*)(blue_evt->data))->Numeric_Value; - FURI_LOG_I(TAG, "Verify numeric comparison: %06ld", pin); + FURI_LOG_I(TAG, "Verify numeric comparison: %06lu", pin); GapEvent event = {.type = GapEventTypePinCodeVerify, .data.pin_code = pin}; bool result = gap->on_event_cb(event, gap->context); aci_gap_numeric_comparison_value_confirm_yesno(gap->service.connection_handle, result); @@ -245,7 +245,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) { } else { FURI_LOG_I(TAG, "Pairing complete"); GapEvent event = {.type = GapEventTypeConnected}; - gap->on_event_cb(event, gap->context); + gap->on_event_cb(event, gap->context); //-V595 } break; diff --git a/firmware/targets/f7/ble_glue/hid_service.c b/firmware/targets/f7/ble_glue/hid_service.c index d0ca9685..47d242d4 100644 --- a/firmware/targets/f7/ble_glue/hid_service.c +++ b/firmware/targets/f7/ble_glue/hid_service.c @@ -87,7 +87,7 @@ void hid_svc_start() { #if(HID_SVC_REPORT_COUNT != 0) for(uint8_t i = 0; i < HID_SVC_REPORT_COUNT; i++) { - if(i < HID_SVC_INPUT_REPORT_COUNT) { + if(i < HID_SVC_INPUT_REPORT_COUNT) { //-V547 uint8_t buf[2] = {i + 1, 1}; // 1 input char_uuid.Char_UUID_16 = REPORT_CHAR_UUID; status = aci_gatt_add_char( diff --git a/firmware/targets/f7/ble_glue/hw_ipcc.c b/firmware/targets/f7/ble_glue/hw_ipcc.c index 64dd9ef9..7c84df09 100644 --- a/firmware/targets/f7/ble_glue/hw_ipcc.c +++ b/firmware/targets/f7/ble_glue/hw_ipcc.c @@ -24,9 +24,9 @@ /* Global variables ---------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ #define HW_IPCC_TX_PENDING(channel) \ - (!(LL_C1_IPCC_IsActiveFlag_CHx(IPCC, channel))) && (((~(IPCC->C1MR)) & (channel << 16U))) + (!(LL_C1_IPCC_IsActiveFlag_CHx(IPCC, channel))) && (((~(IPCC->C1MR)) & ((channel) << 16U))) #define HW_IPCC_RX_PENDING(channel) \ - (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, channel)) && (((~(IPCC->C1MR)) & (channel << 0U))) + (LL_C2_IPCC_IsActiveFlag_CHx(IPCC, channel)) && (((~(IPCC->C1MR)) & ((channel) << 0U))) /* Private macros ------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ diff --git a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c index 07cae31f..b9b65f06 100644 --- a/firmware/targets/f7/fatfs/stm32_adafruit_sd.c +++ b/firmware/targets/f7/fatfs/stm32_adafruit_sd.c @@ -405,9 +405,9 @@ uint8_t BSP_SD_GetCardInfo(SD_CardInfo* pCardInfo) { pCardInfo->LogBlockNbr = (pCardInfo->CardCapacity) / (pCardInfo->LogBlockSize); } else { pCardInfo->CardCapacity = (pCardInfo->Csd.version.v1.DeviceSize + 1); - pCardInfo->CardCapacity *= (1 << (pCardInfo->Csd.version.v1.DeviceSizeMul + 2)); + pCardInfo->CardCapacity *= (1UL << (pCardInfo->Csd.version.v1.DeviceSizeMul + 2)); pCardInfo->LogBlockSize = 512; - pCardInfo->CardBlockSize = 1 << (pCardInfo->Csd.RdBlockLen); + pCardInfo->CardBlockSize = 1UL << (pCardInfo->Csd.RdBlockLen); pCardInfo->CardCapacity *= pCardInfo->CardBlockSize; pCardInfo->LogBlockNbr = (pCardInfo->CardCapacity) / (pCardInfo->LogBlockSize); } @@ -982,7 +982,8 @@ uint8_t SD_GoIdleState(void) { SD_IO_WriteByte(SD_DUMMY_BYTE); /* Send ACMD41 (SD_CMD_SD_APP_OP_COND) to initialize SDHC or SDXC cards: R1 response (0x00: no errors) */ - response = SD_SendCmd(SD_CMD_SD_APP_OP_COND, 0x00000000, 0xFF, SD_ANSWER_R1_EXPECTED); + response = //-V519 + SD_SendCmd(SD_CMD_SD_APP_OP_COND, 0x00000000, 0xFF, SD_ANSWER_R1_EXPECTED); SD_IO_CSState(1); SD_IO_WriteByte(SD_DUMMY_BYTE); if(counter >= SD_MAX_TRY) { @@ -1001,7 +1002,8 @@ uint8_t SD_GoIdleState(void) { SD_IO_WriteByte(SD_DUMMY_BYTE); /* Send ACMD41 (SD_CMD_SD_APP_OP_COND) to initialize SDHC or SDXC cards: R1 response (0x00: no errors) */ - response = SD_SendCmd(SD_CMD_SD_APP_OP_COND, 0x40000000, 0xFF, SD_ANSWER_R1_EXPECTED); + response = //-V519 + SD_SendCmd(SD_CMD_SD_APP_OP_COND, 0x40000000, 0xFF, SD_ANSWER_R1_EXPECTED); SD_IO_CSState(1); SD_IO_WriteByte(SD_DUMMY_BYTE); if(counter >= SD_MAX_TRY) { diff --git a/firmware/targets/f7/furi_hal/furi_hal_bt.c b/firmware/targets/f7/furi_hal/furi_hal_bt.c index fc1c25c7..0857fe4e 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_bt.c +++ b/firmware/targets/f7/furi_hal/furi_hal_bt.c @@ -415,7 +415,7 @@ float furi_hal_bt_get_rssi() { val += 6.0; rssi >>= 1; } - val += (417 * rssi + 18080) >> 10; + val += (float)((417 * rssi + 18080) >> 10); } return val; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c b/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c index 22415199..ab3855f4 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c +++ b/firmware/targets/f7/furi_hal/furi_hal_bt_hid.c @@ -216,7 +216,7 @@ bool furi_hal_bt_hid_kb_release_all() { bool furi_hal_bt_hid_consumer_key_press(uint16_t button) { furi_assert(consumer_report); - for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { + for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { //-V1008 if(consumer_report->key[i] == 0) { consumer_report->key[i] = button; break; @@ -228,7 +228,7 @@ bool furi_hal_bt_hid_consumer_key_press(uint16_t button) { bool furi_hal_bt_hid_consumer_key_release(uint16_t button) { furi_assert(consumer_report); - for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { + for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { //-V1008 if(consumer_report->key[i] == button) { consumer_report->key[i] = 0; break; @@ -240,7 +240,7 @@ bool furi_hal_bt_hid_consumer_key_release(uint16_t button) { bool furi_hal_bt_hid_consumer_key_release_all() { furi_assert(consumer_report); - for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { + for(uint8_t i = 0; i < FURI_HAL_BT_HID_CONSUMER_MAX_KEYS; i++) { //-V1008 consumer_report->key[i] = 0; } return hid_svc_update_input_report( diff --git a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c index d832c4f6..678eb296 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c +++ b/firmware/targets/f7/furi_hal/furi_hal_i2c_config.c @@ -108,7 +108,7 @@ void furi_hal_i2c_bus_handle_power_event( GpioSpeedLow, GpioAltFn4I2C1); - LL_I2C_InitTypeDef I2C_InitStruct = {0}; + LL_I2C_InitTypeDef I2C_InitStruct; I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; I2C_InitStruct.DigitalFilter = 0; @@ -152,7 +152,7 @@ void furi_hal_i2c_bus_handle_external_event( furi_hal_gpio_init_ex( &gpio_ext_pc1, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3); - LL_I2C_InitTypeDef I2C_InitStruct = {0}; + LL_I2C_InitTypeDef I2C_InitStruct; I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C; I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE; I2C_InitStruct.DigitalFilter = 0; diff --git a/firmware/targets/f7/furi_hal/furi_hal_memory.c b/firmware/targets/f7/furi_hal/furi_hal_memory.c index ec71e666..9716f1e5 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_memory.c +++ b/firmware/targets/f7/furi_hal/furi_hal_memory.c @@ -55,9 +55,9 @@ void furi_hal_memory_init() { memory->region[SRAM_B].size = sram2b_unprotected_size; FURI_LOG_I( - TAG, "SRAM2A: 0x%p, %ld", memory->region[SRAM_A].start, memory->region[SRAM_A].size); + TAG, "SRAM2A: 0x%p, %lu", memory->region[SRAM_A].start, memory->region[SRAM_A].size); FURI_LOG_I( - TAG, "SRAM2B: 0x%p, %ld", memory->region[SRAM_B].start, memory->region[SRAM_B].size); + TAG, "SRAM2B: 0x%p, %lu", memory->region[SRAM_B].start, memory->region[SRAM_B].size); if((memory->region[SRAM_A].size > 0) || (memory->region[SRAM_B].size > 0)) { if((memory->region[SRAM_A].size > 0)) { @@ -120,4 +120,4 @@ size_t furi_hal_memory_max_pool_block() { } } return max; -} \ No newline at end of file +} diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc.c b/firmware/targets/f7/furi_hal/furi_hal_nfc.c index 75c695af..6381d1a9 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc.c @@ -425,7 +425,7 @@ bool furi_hal_nfc_emulate_nfca( buff_rx_len = 0; buff_tx_len = 0; uint32_t flag = furi_event_flag_wait(event, EVENT_FLAG_ALL, FuriFlagWaitAny, timeout); - if(flag == FuriFlagErrorTimeout || flag == EVENT_FLAG_STOP) { + if(flag == (unsigned)FuriFlagErrorTimeout || flag == EVENT_FLAG_STOP) { break; } bool data_received = false; @@ -609,9 +609,9 @@ static uint16_t furi_hal_nfc_data_and_parity_to_bitstream( out[curr_bit_pos / 8] = next_par_bit; curr_bit_pos++; } else { - out[curr_bit_pos / 8] |= data[i] << curr_bit_pos % 8; + out[curr_bit_pos / 8] |= data[i] << (curr_bit_pos % 8); out[curr_bit_pos / 8 + 1] = data[i] >> (8 - curr_bit_pos % 8); - out[curr_bit_pos / 8 + 1] |= next_par_bit << curr_bit_pos % 8; + out[curr_bit_pos / 8 + 1] |= next_par_bit << (curr_bit_pos % 8); curr_bit_pos += 9; } } @@ -635,7 +635,7 @@ uint16_t furi_hal_nfc_bitstream_to_data_and_parity( uint16_t bit_processed = 0; memset(out_parity, 0, in_buff_bits / 9); while(bit_processed < in_buff_bits) { - out_data[curr_byte] = in_buff[bit_processed / 8] >> bit_processed % 8; + out_data[curr_byte] = in_buff[bit_processed / 8] >> (bit_processed % 8); out_data[curr_byte] |= in_buff[bit_processed / 8 + 1] << (8 - bit_processed % 8); out_parity[curr_byte / 8] |= FURI_BIT(in_buff[bit_processed / 8 + 1], bit_processed % 8) << (7 - curr_byte % 8); @@ -802,4 +802,4 @@ FuriHalNfcReturn furi_hal_nfc_ll_txrx_bits( void furi_hal_nfc_ll_poll() { rfalWorker(); -} \ No newline at end of file +} diff --git a/firmware/targets/f7/furi_hal/furi_hal_os.c b/firmware/targets/f7/furi_hal/furi_hal_os.c index 97d022c9..ee9743e6 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_os.c +++ b/firmware/targets/f7/furi_hal/furi_hal_os.c @@ -15,8 +15,8 @@ #define FURI_HAL_IDLE_TIMER_CLK_HZ 32768 #define FURI_HAL_OS_TICK_HZ configTICK_RATE_HZ -#define FURI_HAL_OS_IDLE_CNT_TO_TICKS(x) ((x * FURI_HAL_OS_TICK_HZ) / FURI_HAL_IDLE_TIMER_CLK_HZ) -#define FURI_HAL_OS_TICKS_TO_IDLE_CNT(x) ((x * FURI_HAL_IDLE_TIMER_CLK_HZ) / FURI_HAL_OS_TICK_HZ) +#define FURI_HAL_OS_IDLE_CNT_TO_TICKS(x) (((x)*FURI_HAL_OS_TICK_HZ) / FURI_HAL_IDLE_TIMER_CLK_HZ) +#define FURI_HAL_OS_TICKS_TO_IDLE_CNT(x) (((x)*FURI_HAL_IDLE_TIMER_CLK_HZ) / FURI_HAL_OS_TICK_HZ) #define FURI_HAL_IDLE_TIMER_TICK_PER_EPOCH (FURI_HAL_OS_IDLE_CNT_TO_TICKS(FURI_HAL_IDLE_TIMER_MAX)) #define FURI_HAL_OS_MAX_SLEEP (FURI_HAL_IDLE_TIMER_TICK_PER_EPOCH - 1) diff --git a/firmware/targets/f7/furi_hal/furi_hal_pwm.c b/firmware/targets/f7/furi_hal/furi_hal_pwm.c index e484808d..e47f752a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_pwm.c +++ b/firmware/targets/f7/furi_hal/furi_hal_pwm.c @@ -110,7 +110,7 @@ void furi_hal_pwm_set_params(FuriHalPwmOutputId channel, uint32_t freq, uint8_t bool clock_lse = false; do { - period = freq_div / (1 << prescaler); + period = freq_div / (1UL << prescaler); if(period <= 0xFFFF) { break; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_rtc.c b/firmware/targets/f7/furi_hal/furi_hal_rtc.c index e5fa8c76..e011406a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_rtc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_rtc.c @@ -154,7 +154,7 @@ void furi_hal_rtc_deinit_early() { } void furi_hal_rtc_init() { - LL_RTC_InitTypeDef RTC_InitStruct = {0}; + LL_RTC_InitTypeDef RTC_InitStruct; RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR; RTC_InitStruct.AsynchPrescaler = 127; RTC_InitStruct.SynchPrescaler = 255; diff --git a/firmware/targets/f7/furi_hal/furi_hal_uart.c b/firmware/targets/f7/furi_hal/furi_hal_uart.c index cb44b6d1..54232e67 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_uart.c +++ b/firmware/targets/f7/furi_hal/furi_hal_uart.c @@ -26,7 +26,7 @@ static void furi_hal_usart_init(uint32_t baud) { GpioSpeedVeryHigh, GpioAltFn7USART1); - LL_USART_InitTypeDef USART_InitStruct = {0}; + LL_USART_InitTypeDef USART_InitStruct; USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; USART_InitStruct.BaudRate = baud; USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; @@ -62,7 +62,7 @@ static void furi_hal_lpuart_init(uint32_t baud) { GpioSpeedVeryHigh, GpioAltFn8LPUART1); - LL_LPUART_InitTypeDef LPUART_InitStruct = {0}; + LL_LPUART_InitTypeDef LPUART_InitStruct; LPUART_InitStruct.PrescalerValue = LL_LPUART_PRESCALER_DIV1; LPUART_InitStruct.BaudRate = 115200; LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B; diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c index a7253223..fc1ce024 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c +++ b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c @@ -360,11 +360,11 @@ bool furi_hal_hid_consumer_key_release(uint16_t button) { static void* hid_set_string_descr(char* str) { furi_assert(str); - uint8_t len = strlen(str); + size_t len = strlen(str); struct usb_string_descriptor* dev_str_desc = malloc(len * 2 + 2); dev_str_desc->bLength = len * 2 + 2; dev_str_desc->bDescriptorType = USB_DTYPE_STRING; - for(uint8_t i = 0; i < len; i++) dev_str_desc->wString[i] = str[i]; + for(size_t i = 0; i < len; i++) dev_str_desc->wString[i] = str[i]; return dev_str_desc; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_version.c b/firmware/targets/f7/furi_hal/furi_hal_version.c index 697d6593..b7827ac7 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_version.c +++ b/firmware/targets/f7/furi_hal/furi_hal_version.c @@ -174,8 +174,6 @@ static void furi_hal_version_load_otp_v2() { void furi_hal_version_init() { switch(furi_hal_version_get_otp_version()) { case FuriHalVersionOtpVersionUnknown: - furi_hal_version_load_otp_default(); - break; case FuriHalVersionOtpVersionEmpty: furi_hal_version_load_otp_default(); break; diff --git a/furi/core/check.c b/furi/core/check.c index 1c2a005f..910527ce 100644 --- a/furi/core/check.c +++ b/furi/core/check.c @@ -117,7 +117,7 @@ FURI_NORETURN void __furi_crash() { if(debug) { furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n"); furi_hal_console_puts("\033[0m\r\n"); - RESTORE_REGISTERS_AND_HALT_MCU(debug); + RESTORE_REGISTERS_AND_HALT_MCU(true); } else { furi_hal_rtc_set_fault_data((uint32_t)__furi_check_message); furi_hal_console_puts("\r\nRebooting system.\r\n"); diff --git a/furi/core/core_defines.h b/furi/core/core_defines.h index 487fe2ca..a0f50aff 100644 --- a/furi/core/core_defines.h +++ b/furi/core/core_defines.h @@ -93,7 +93,7 @@ extern "C" { #endif #ifndef FURI_BIT_CLEAR -#define FURI_BIT_CLEAR(x, n) ((x) &= ~(1 << (n))) +#define FURI_BIT_CLEAR(x, n) ((x) &= ~(1UL << (n))) #endif #define FURI_SW_MEMBARRIER() asm volatile("" : : : "memory") diff --git a/furi/core/event_flag.c b/furi/core/event_flag.c index 07dd30a1..87de65f2 100644 --- a/furi/core/event_flag.c +++ b/furi/core/event_flag.c @@ -9,7 +9,11 @@ FuriEventFlag* furi_event_flag_alloc() { furi_assert(!FURI_IS_IRQ_MODE()); - return ((FuriEventFlag*)xEventGroupCreate()); + + EventGroupHandle_t handle = xEventGroupCreate(); + furi_check(handle); + + return ((FuriEventFlag*)handle); } void furi_event_flag_free(FuriEventFlag* instance) { diff --git a/furi/core/memmgr_heap.c b/furi/core/memmgr_heap.c index 01153fe5..ca206cd3 100644 --- a/furi/core/memmgr_heap.c +++ b/furi/core/memmgr_heap.c @@ -212,7 +212,8 @@ static inline void traceFREE(void* pointer, size_t size) { MemmgrHeapThreadDict_get(memmgr_heap_thread_dict, (uint32_t)thread_id); if(alloc_dict) { // In some cases thread may want to release memory that was not allocated by it - (void)MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer); + const bool res = MemmgrHeapAllocDict_erase(*alloc_dict, (uint32_t)pointer); + UNUSED(res); } memmgr_heap_thread_trace_depth--; } @@ -520,8 +521,8 @@ void vPortFree(void* pv) { { furi_assert((size_t)pv >= SRAM_BASE); furi_assert((size_t)pv < SRAM_BASE + 1024 * 256); + furi_assert(pxLink->xBlockSize >= xHeapStructSize); furi_assert((pxLink->xBlockSize - xHeapStructSize) < 1024 * 256); - furi_assert((int32_t)(pxLink->xBlockSize - xHeapStructSize) >= 0); /* Add this block to the list of free blocks. */ xFreeBytesRemaining += pxLink->xBlockSize; diff --git a/furi/core/message_queue.c b/furi/core/message_queue.c index 2658d6ff..9a41f877 100644 --- a/furi/core/message_queue.c +++ b/furi/core/message_queue.c @@ -7,7 +7,10 @@ FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) { furi_assert((furi_is_irq_context() == 0U) && (msg_count > 0U) && (msg_size > 0U)); - return ((FuriMessageQueue*)xQueueCreate(msg_count, msg_size)); + QueueHandle_t handle = xQueueCreate(msg_count, msg_size); + furi_check(handle); + + return ((FuriMessageQueue*)handle); } void furi_message_queue_free(FuriMessageQueue* instance) { diff --git a/furi/core/mutex.c b/furi/core/mutex.c index ab66b0f1..9fb964a1 100644 --- a/furi/core/mutex.c +++ b/furi/core/mutex.c @@ -30,6 +30,8 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) { void furi_mutex_free(FuriMutex* instance) { furi_assert(!FURI_IS_IRQ_MODE()); + furi_assert(instance); + vSemaphoreDelete((SemaphoreHandle_t)((uint32_t)instance & ~1U)); } diff --git a/furi/core/stream_buffer.c b/furi/core/stream_buffer.c index 2df84fa5..bf483948 100644 --- a/furi/core/stream_buffer.c +++ b/furi/core/stream_buffer.c @@ -1,18 +1,26 @@ #include "base.h" +#include "check.h" #include "stream_buffer.h" #include "common_defines.h" #include #include FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) { - return xStreamBufferCreate(size, trigger_level); + furi_assert(size != 0); + + StreamBufferHandle_t handle = xStreamBufferCreate(size, trigger_level); + furi_check(handle); + + return handle; }; void furi_stream_buffer_free(FuriStreamBuffer* stream_buffer) { + furi_assert(stream_buffer); vStreamBufferDelete(stream_buffer); }; bool furi_stream_set_trigger_level(FuriStreamBuffer* stream_buffer, size_t trigger_level) { + furi_assert(stream_buffer); return xStreamBufferSetTriggerLevel(stream_buffer, trigger_level) == pdTRUE; }; diff --git a/furi/core/string.c b/furi/core/string.c index 901b1f62..4384fe06 100644 --- a/furi/core/string.c +++ b/furi/core/string.c @@ -29,16 +29,16 @@ FuriString* furi_string_alloc() { } FuriString* furi_string_alloc_set(const FuriString* s) { - FuriString* string = malloc(sizeof(FuriString)); //-V773 + FuriString* string = malloc(sizeof(FuriString)); //-V799 string_init_set(string->string, s->string); return string; -} +} //-V773 FuriString* furi_string_alloc_set_str(const char cstr[]) { - FuriString* string = malloc(sizeof(FuriString)); //-V773 + FuriString* string = malloc(sizeof(FuriString)); //-V799 string_init_set(string->string, cstr); return string; -} +} //-V773 FuriString* furi_string_alloc_printf(const char format[], ...) { va_list args; @@ -299,4 +299,4 @@ void furi_string_utf8_decode(char c, FuriStringUTF8State* state, FuriStringUnico m_str1ng_utf8_state_e m_state = furi_state_to_state(*state); m_str1ng_utf8_decode(c, &m_state, unicode); *state = state_to_furi_state(m_state); -} \ No newline at end of file +} diff --git a/furi/core/thread.c b/furi/core/thread.c index 34cc7d98..c966dd57 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -49,9 +49,9 @@ static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, s static int32_t __furi_thread_stdout_flush(FuriThread* thread); /** Catch threads that are trying to exit wrong way */ -__attribute__((__noreturn__)) void furi_thread_catch() { +__attribute__((__noreturn__)) void furi_thread_catch() { //-V1082 asm volatile("nop"); // extra magic - furi_crash("You are doing it wrong"); + furi_crash("You are doing it wrong"); //-V779 __builtin_unreachable(); } @@ -84,10 +84,10 @@ static void furi_thread_body(void* context) { if(thread->heap_trace_enabled == true) { furi_delay_ms(33); thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)task_handle); - furi_log_print_format( + furi_log_print_format( //-V576 thread->heap_size ? FuriLogLevelError : FuriLogLevelInfo, TAG, - "%s allocation balance: %d", + "%s allocation balance: %u", thread->name ? thread->name : "Thread", thread->heap_size); memmgr_heap_disable_thread_trace((FuriThreadId)task_handle); diff --git a/furi/core/timer.c b/furi/core/timer.c index c42b0c2a..be7efebe 100644 --- a/furi/core/timer.c +++ b/furi/core/timer.c @@ -32,44 +32,28 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co TimerHandle_t hTimer; TimerCallback_t* callb; UBaseType_t reload; - uint32_t callb_dyn; hTimer = NULL; - callb = NULL; - callb_dyn = 0U; /* Dynamic memory allocation is available: if memory for callback and */ /* its context is not provided, allocate it from dynamic memory pool */ - if(callb == NULL) { - callb = (TimerCallback_t*)malloc(sizeof(TimerCallback_t)); + callb = (TimerCallback_t*)malloc(sizeof(TimerCallback_t)); - if(callb != NULL) { - /* Callback memory was allocated from dynamic pool, set flag */ - callb_dyn = 1U; - } + callb->func = func; + callb->context = context; + + if(type == FuriTimerTypeOnce) { + reload = pdFALSE; + } else { + reload = pdTRUE; } - if(callb != NULL) { - callb->func = func; - callb->context = context; - - if(type == FuriTimerTypeOnce) { - reload = pdFALSE; - } else { - reload = pdTRUE; - } - - /* Store callback memory dynamic allocation flag */ - callb = (TimerCallback_t*)((uint32_t)callb | callb_dyn); - // TimerCallback function is always provided as a callback and is used to call application - // specified function with its context both stored in structure callb. - hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback); - if((hTimer == NULL) && (callb != NULL) && (callb_dyn == 1U)) { - /* Failed to create a timer, release allocated resources */ - callb = (TimerCallback_t*)((uint32_t)callb & ~1U); - free(callb); - } - } + /* Store callback memory dynamic allocation flag */ + callb = (TimerCallback_t*)((uint32_t)callb | 1U); + // TimerCallback function is always provided as a callback and is used to call application + // specified function with its context both stored in structure callb. + hTimer = xTimerCreate(NULL, 1, reload, callb, TimerCallback); + furi_check(hTimer); /* Return timer ID */ return ((FuriTimer*)hTimer); diff --git a/lib/app-scened-template/view_modules/popup_vm.cpp b/lib/app-scened-template/view_modules/popup_vm.cpp index c378d9cc..e2c8732e 100644 --- a/lib/app-scened-template/view_modules/popup_vm.cpp +++ b/lib/app-scened-template/view_modules/popup_vm.cpp @@ -1,4 +1,5 @@ #include "popup_vm.h" +#include "gui/modules/popup.h" PopupVM::PopupVM() { popup = popup_alloc(); } @@ -50,5 +51,5 @@ void PopupVM::enable_timeout() { } void PopupVM::disable_timeout() { - popup_enable_timeout(popup); + popup_disable_timeout(popup); } diff --git a/lib/drivers/cc1101.c b/lib/drivers/cc1101.c index f28165e8..d563c30c 100644 --- a/lib/drivers/cc1101.c +++ b/lib/drivers/cc1101.c @@ -121,7 +121,7 @@ uint32_t cc1101_set_intermediate_frequency(FuriHalSpiBusHandle* handle, uint32_t } void cc1101_set_pa_table(FuriHalSpiBusHandle* handle, const uint8_t value[8]) { - uint8_t tx[9] = {CC1101_PATABLE | CC1101_BURST}; + uint8_t tx[9] = {CC1101_PATABLE | CC1101_BURST}; //-V1009 CC1101Status rx[9] = {0}; memcpy(&tx[1], &value[0], 8); diff --git a/lib/drivers/lp5562.c b/lib/drivers/lp5562.c index f5d765fa..e755d2d6 100644 --- a/lib/drivers/lp5562.c +++ b/lib/drivers/lp5562.c @@ -105,7 +105,7 @@ void lp5562_set_channel_src(FuriHalI2cBusHandle* handle, LP5562Channel channel, reg_val &= ~(0x3 << bit_offset); reg_val |= ((src & 0x03) << bit_offset); furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x70, reg_val, LP5562_I2C_TIMEOUT); - } while(channel); + } while(channel != 0); } void lp5562_execute_program( @@ -166,7 +166,7 @@ void lp5562_stop_program(FuriHalI2cBusHandle* handle, LP5562Engine eng) { bit_offset = (3 - eng) * 2; furi_hal_i2c_read_reg_8(handle, LP5562_ADDRESS, 0x01, ®_val, LP5562_I2C_TIMEOUT); reg_val &= ~(0x3 << bit_offset); - reg_val |= (0x00 << bit_offset); // Disabled + // Not setting lowest 2 bits here furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x01, reg_val, LP5562_I2C_TIMEOUT); } diff --git a/lib/flipper_application/elf/elf_file.c b/lib/flipper_application/elf/elf_file.c index 2082e550..bf98650a 100644 --- a/lib/flipper_application/elf/elf_file.c +++ b/lib/flipper_application/elf/elf_file.c @@ -6,8 +6,8 @@ #define TAG "elf" #define ELF_NAME_BUFFER_LEN 32 -#define SECTION_OFFSET(e, n) (e->section_table + n * sizeof(Elf32_Shdr)) -#define IS_FLAGS_SET(v, m) ((v & m) == m) +#define SECTION_OFFSET(e, n) ((e)->section_table + (n) * sizeof(Elf32_Shdr)) +#define IS_FLAGS_SET(v, m) (((v) & (m)) == (m)) #define RESOLVER_THREAD_YIELD_STEP 30 // #define ELF_DEBUG_LOG 1 @@ -758,15 +758,13 @@ ELFFileLoadStatus elf_file_load_sections(ELFFile* elf) { AddressCache_init(elf->relocation_cache); - if(status == ELFFileLoadStatusSuccess) { - for(ELFSectionDict_it(it, elf->sections); !ELFSectionDict_end_p(it); - ELFSectionDict_next(it)) { - ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it); - FURI_LOG_D(TAG, "Relocating section '%s'", itref->key); - if(!elf_relocate_section(elf, &itref->value)) { - FURI_LOG_E(TAG, "Error relocating section '%s'", itref->key); - status = ELFFileLoadStatusMissingImports; - } + for(ELFSectionDict_it(it, elf->sections); !ELFSectionDict_end_p(it); + ELFSectionDict_next(it)) { + ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it); + FURI_LOG_D(TAG, "Relocating section '%s'", itref->key); + if(!elf_relocate_section(elf, &itref->value)) { + FURI_LOG_E(TAG, "Error relocating section '%s'", itref->key); + status = ELFFileLoadStatusMissingImports; } } @@ -793,7 +791,7 @@ ELFFileLoadStatus elf_file_load_sections(ELFFile* elf) { ELFSectionDict_itref_t* itref = ELFSectionDict_ref(it); total_size += itref->value.size; } - FURI_LOG_I(TAG, "Total size of loaded sections: %u", total_size); + FURI_LOG_I(TAG, "Total size of loaded sections: %u", total_size); //-V576 } return status; diff --git a/lib/flipper_format/flipper_format_stream.c b/lib/flipper_format/flipper_format_stream.c index 9cce95d4..405b819a 100644 --- a/lib/flipper_format/flipper_format_stream.c +++ b/lib/flipper_format/flipper_format_stream.c @@ -298,7 +298,7 @@ bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteDa }; break; case FlipperStreamValueUint32: { const uint32_t* data = write_data->data; - furi_string_printf(value, "%" PRId32, data[i]); + furi_string_printf(value, "%" PRIu32, data[i]); }; break; case FlipperStreamValueHexUint64: { const uint64_t* data = write_data->data; @@ -396,7 +396,7 @@ bool flipper_format_stream_read_value_line( }; break; case FlipperStreamValueUint32: { uint32_t* data = _data; - scan_values = sscanf(furi_string_get_cstr(value), "%" PRId32, &data[i]); + scan_values = sscanf(furi_string_get_cstr(value), "%" PRIu32, &data[i]); }; break; case FlipperStreamValueHexUint64: { uint64_t* data = _data; diff --git a/lib/infrared/encoder_decoder/common/infrared_common_decoder.c b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c index 7f1c3a4f..8acb6751 100644 --- a/lib/infrared/encoder_decoder/common/infrared_common_decoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c @@ -107,7 +107,7 @@ static InfraredStatus infrared_common_decode_bits(InfraredCommonDecoder* decoder decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1); /* check if largest protocol version can be decoded */ - if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) && + if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) && //-V1051 !timings->min_split_time) { status = InfraredStatusReady; break; diff --git a/lib/infrared/encoder_decoder/common/infrared_common_encoder.c b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c index dcf63acc..9c774617 100644 --- a/lib/infrared/encoder_decoder/common/infrared_common_encoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c @@ -94,7 +94,6 @@ InfraredStatus case InfraredCommonEncoderStateSilence: *duration = encoder->protocol->timings.silence_time; *level = false; - status = InfraredStatusOk; encoder->state = InfraredCommonEncoderStatePreamble; ++encoder->timings_encoded; encoder->timings_sum = 0; diff --git a/lib/infrared/encoder_decoder/common/infrared_common_i.h b/lib/infrared/encoder_decoder/common/infrared_common_i.h index 20dbeb79..f34e81ed 100644 --- a/lib/infrared/encoder_decoder/common/infrared_common_i.h +++ b/lib/infrared/encoder_decoder/common/infrared_common_i.h @@ -4,7 +4,7 @@ #include "infrared.h" #include "infrared_i.h" -#define MATCH_TIMING(x, v, delta) (((x) < (v + delta)) && ((x) > (v - delta))) +#define MATCH_TIMING(x, v, delta) (((x) < ((v) + (delta))) && ((x) > ((v) - (delta)))) typedef struct InfraredCommonDecoder InfraredCommonDecoder; typedef struct InfraredCommonEncoder InfraredCommonEncoder; diff --git a/lib/infrared/worker/infrared_transmit.c b/lib/infrared/worker/infrared_transmit.c index 695be8d1..1a508301 100644 --- a/lib/infrared/worker/infrared_transmit.c +++ b/lib/infrared/worker/infrared_transmit.c @@ -67,7 +67,7 @@ void infrared_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool star FuriHalInfraredTxGetDataState infrared_get_data_callback(void* context, uint32_t* duration, bool* level) { - FuriHalInfraredTxGetDataState state = FuriHalInfraredTxGetDataStateLastDone; + FuriHalInfraredTxGetDataState state; InfraredEncoderHandler* handler = context; InfraredStatus status = InfraredStatusError; @@ -82,9 +82,10 @@ FuriHalInfraredTxGetDataState } else if(status == InfraredStatusOk) { state = FuriHalInfraredTxGetDataStateOk; } else if(status == InfraredStatusDone) { - state = FuriHalInfraredTxGetDataStateDone; if(--infrared_tx_number_of_transmissions == 0) { state = FuriHalInfraredTxGetDataStateLastDone; + } else { + state = FuriHalInfraredTxGetDataStateDone; } } else { furi_crash(NULL); diff --git a/lib/infrared/worker/infrared_worker.c b/lib/infrared/worker/infrared_worker.c index 57288f3c..033dba52 100644 --- a/lib/infrared/worker/infrared_worker.c +++ b/lib/infrared/worker/infrared_worker.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -397,8 +398,9 @@ static bool infrared_get_new_signal(InfraredWorker* instance) { } instance->tx.tx_raw_cnt = 0; - instance->tx.need_reinitialization = (new_tx_frequency != instance->tx.frequency) || - (new_tx_duty_cycle != instance->tx.duty_cycle); + instance->tx.need_reinitialization = + (new_tx_frequency != instance->tx.frequency) || + !float_is_equal(new_tx_duty_cycle, instance->tx.duty_cycle); instance->tx.frequency = new_tx_frequency; instance->tx.duty_cycle = new_tx_duty_cycle; if(instance->signal.decoded) { diff --git a/lib/infrared/worker/infrared_worker.h b/lib/infrared/worker/infrared_worker.h index 26919c4f..1a8cd9a7 100644 --- a/lib/infrared/worker/infrared_worker.h +++ b/lib/infrared/worker/infrared_worker.h @@ -7,7 +7,7 @@ extern "C" { #endif -#define MAX_TIMINGS_AMOUNT 1024 +#define MAX_TIMINGS_AMOUNT 1024U /** Interface struct of infrared worker */ typedef struct InfraredWorker InfraredWorker; diff --git a/lib/lfrfid/lfrfid_raw_worker.c b/lib/lfrfid/lfrfid_raw_worker.c index 8c69aced..22c0bbd0 100644 --- a/lib/lfrfid/lfrfid_raw_worker.c +++ b/lib/lfrfid/lfrfid_raw_worker.c @@ -114,7 +114,6 @@ void lfrfid_raw_worker_stop(LFRFIDRawWorker* worker) { worker->emulate_callback = NULL; worker->context = NULL; worker->read_callback = NULL; - worker->context = NULL; furi_event_flag_set(worker->events, 1 << LFRFIDRawWorkerEventStop); furi_thread_join(worker->thread); } @@ -335,7 +334,7 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) { } if(data->ctx.overrun_count) { - FURI_LOG_E(TAG_EMULATE, "overruns: %u", data->ctx.overrun_count); + FURI_LOG_E(TAG_EMULATE, "overruns: %zu", data->ctx.overrun_count); } furi_stream_buffer_free(data->ctx.stream); @@ -344,4 +343,4 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) { free(data); return 0; -} \ No newline at end of file +} diff --git a/lib/lfrfid/lfrfid_worker.c b/lib/lfrfid/lfrfid_worker.c index f33c1aed..1e491c6b 100644 --- a/lib/lfrfid/lfrfid_worker.c +++ b/lib/lfrfid/lfrfid_worker.c @@ -139,7 +139,7 @@ static int32_t lfrfid_worker_thread(void* thread_context) { while(true) { uint32_t flags = furi_thread_flags_wait(LFRFIDEventAll, FuriFlagWaitAny, FuriWaitForever); - if(flags != FuriFlagErrorTimeout) { + if(flags != (unsigned)FuriFlagErrorTimeout) { // stop thread if(flags & LFRFIDEventStopThread) break; @@ -161,4 +161,4 @@ static int32_t lfrfid_worker_thread(void* thread_context) { } return 0; -} \ No newline at end of file +} diff --git a/lib/lfrfid/lfrfid_worker_modes.c b/lib/lfrfid/lfrfid_worker_modes.c index 1fbae04c..9b6f16eb 100644 --- a/lib/lfrfid/lfrfid_worker_modes.c +++ b/lib/lfrfid/lfrfid_worker_modes.c @@ -276,7 +276,7 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal( FURI_LOG_D( TAG, - "%s, %d, [%s]", + "%s, %zu, [%s]", protocol_dict_get_name(worker->protocols, protocol), last_read_count, furi_string_get_cstr(string_info)); @@ -335,9 +335,9 @@ static LFRFIDWorkerReadState lfrfid_worker_read_internal( } static void lfrfid_worker_mode_read_process(LFRFIDWorker* worker) { - LFRFIDFeature feature = LFRFIDFeatureASK; ProtocolId read_result = PROTOCOL_NO; LFRFIDWorkerReadState state; + LFRFIDFeature feature; if(worker->read_type == LFRFIDWorkerReadTypePSKOnly) { feature = LFRFIDFeaturePSK; @@ -635,4 +635,4 @@ const LFRFIDWorkerModeType lfrfid_worker_modes[] = { [LFRFIDWorkerEmulate] = {.process = lfrfid_worker_mode_emulate_process}, [LFRFIDWorkerReadRaw] = {.process = lfrfid_worker_mode_read_raw_process}, [LFRFIDWorkerEmulateRaw] = {.process = lfrfid_worker_mode_emulate_raw_process}, -}; \ No newline at end of file +}; diff --git a/lib/lfrfid/protocols/protocol_indala26.c b/lib/lfrfid/protocols/protocol_indala26.c index cafc5848..8319f0a9 100644 --- a/lib/lfrfid/protocols/protocol_indala26.c +++ b/lib/lfrfid/protocols/protocol_indala26.c @@ -353,4 +353,4 @@ const ProtocolBase protocol_indala26 = { .render_data = (ProtocolRenderData)protocol_indala26_render_data, .render_brief_data = (ProtocolRenderData)protocol_indala26_render_brief_data, .write_data = (ProtocolWriteData)protocol_indala26_write_data, -}; \ No newline at end of file +}; diff --git a/lib/lfrfid/protocols/protocol_pac_stanley.c b/lib/lfrfid/protocols/protocol_pac_stanley.c index 59aaf1e6..11c64240 100644 --- a/lib/lfrfid/protocols/protocol_pac_stanley.c +++ b/lib/lfrfid/protocols/protocol_pac_stanley.c @@ -12,7 +12,7 @@ #define PAC_STANLEY_ENCODED_BYTE_FULL_SIZE \ (PAC_STANLEY_ENCODED_BYTE_SIZE + PAC_STANLEY_PREAMBLE_BYTE_SIZE) #define PAC_STANLEY_BYTE_LENGTH (10) // start bit, 7 data bits, parity bit, stop bit -#define PAC_STANLEY_DATA_START_INDEX 8 + (3 * PAC_STANLEY_BYTE_LENGTH) + 1 +#define PAC_STANLEY_DATA_START_INDEX (8 + (3 * PAC_STANLEY_BYTE_LENGTH) + 1) #define PAC_STANLEY_DECODED_DATA_SIZE (4) #define PAC_STANLEY_ENCODED_DATA_SIZE (sizeof(ProtocolPACStanley)) @@ -128,7 +128,7 @@ bool protocol_pac_stanley_decoder_feed(ProtocolPACStanley* protocol, bool level, } bool protocol_pac_stanley_encoder_start(ProtocolPACStanley* protocol) { - memset(protocol->encoded_data, 0, PAC_STANLEY_ENCODED_BYTE_SIZE); + memset(protocol->encoded_data, 0, sizeof(protocol->encoded_data)); uint8_t idbytes[10]; idbytes[0] = '2'; @@ -137,7 +137,7 @@ bool protocol_pac_stanley_encoder_start(ProtocolPACStanley* protocol) { uint8_to_hex_chars(protocol->data, &idbytes[2], 8); // insert start and stop bits - for(size_t i = 0; i < 16; i++) protocol->encoded_data[i] = 0x40 >> (i + 3) % 5 * 2; + for(size_t i = 0; i < 16; i++) protocol->encoded_data[i] = 0x40 >> ((i + 3) % 5 * 2); protocol->encoded_data[0] = 0xFF; // mark + stop protocol->encoded_data[1] = 0x20; // start + reflect8(STX) @@ -228,4 +228,4 @@ const ProtocolBase protocol_pac_stanley = { .render_data = (ProtocolRenderData)protocol_pac_stanley_render_data, .render_brief_data = (ProtocolRenderData)protocol_pac_stanley_render_data, .write_data = (ProtocolWriteData)protocol_pac_stanley_write_data, -}; \ No newline at end of file +}; diff --git a/lib/lfrfid/tools/bit_lib.c b/lib/lfrfid/tools/bit_lib.c index c84f4b7e..54decb3e 100644 --- a/lib/lfrfid/tools/bit_lib.c +++ b/lib/lfrfid/tools/bit_lib.c @@ -25,7 +25,7 @@ void bit_lib_set_bits(uint8_t* data, size_t position, uint8_t byte, uint8_t leng for(uint8_t i = 0; i < length; ++i) { uint8_t shift = (length - 1) - i; - bit_lib_set_bit(data, position + i, (byte >> shift) & 1); + bit_lib_set_bit(data, position + i, (byte >> shift) & 1); //-V610 } } @@ -69,9 +69,9 @@ uint32_t bit_lib_get_bits_32(const uint8_t* data, size_t position, uint8_t lengt value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16); value |= bit_lib_get_bits(data, position + 16, length - 16); } else { - value = bit_lib_get_bits(data, position, 8) << (length - 8); - value |= bit_lib_get_bits(data, position + 8, 8) << (length - 16); - value |= bit_lib_get_bits(data, position + 16, 8) << (length - 24); + value = (uint32_t)bit_lib_get_bits(data, position, 8) << (length - 8); + value |= (uint32_t)bit_lib_get_bits(data, position + 8, 8) << (length - 16); + value |= (uint32_t)bit_lib_get_bits(data, position + 16, 8) << (length - 24); value |= bit_lib_get_bits(data, position + 24, length - 24); } @@ -364,4 +364,4 @@ uint16_t bit_lib_crc16( crc ^= xor_out; return crc; -} \ No newline at end of file +} diff --git a/lib/lfrfid/tools/bit_lib.h b/lib/lfrfid/tools/bit_lib.h index 1b048db3..bae95462 100644 --- a/lib/lfrfid/tools/bit_lib.h +++ b/lib/lfrfid/tools/bit_lib.h @@ -7,7 +7,7 @@ extern "C" { #endif -#define TOPBIT(X) (1 << (X - 1)) +#define TOPBIT(X) (1 << ((X)-1)) typedef enum { BitLibParityEven, @@ -26,13 +26,13 @@ typedef enum { * @param data value to test * @param index bit index to test */ -#define bit_lib_bit_is_set(data, index) ((data & (1 << (index))) != 0) +#define bit_lib_bit_is_set(data, index) (((data) & (1 << (index))) != 0) /** @brief Test if a bit is not set. * @param data value to test * @param index bit index to test */ -#define bit_lib_bit_is_not_set(data, index) ((data & (1 << (index))) == 0) +#define bit_lib_bit_is_not_set(data, index) (((data) & (1 << (index))) == 0) /** @brief Push a bit into a byte array. * @param data array to push bit into @@ -269,4 +269,4 @@ uint16_t bit_lib_crc16( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/lfrfid/tools/varint_pair.c b/lib/lfrfid/tools/varint_pair.c index c59ba55b..1e6c82ee 100644 --- a/lib/lfrfid/tools/varint_pair.c +++ b/lib/lfrfid/tools/varint_pair.c @@ -28,11 +28,9 @@ bool varint_pair_pack(VarintPair* pair, bool first, uint32_t value) { pair->data_length = 0; } } else { - if(pair->data_length > 0) { + if(pair->data_length != 0) { pair->data_length += varint_uint32_pack(value, pair->data + pair->data_length); result = true; - } else { - pair->data_length = 0; } } diff --git a/lib/nfc/helpers/mf_classic_dict.c b/lib/nfc/helpers/mf_classic_dict.c index 690bba61..98076479 100644 --- a/lib/nfc/helpers/mf_classic_dict.c +++ b/lib/nfc/helpers/mf_classic_dict.c @@ -90,7 +90,7 @@ MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type) { } FURI_LOG_T( TAG, - "Read line: %s, len: %d", + "Read line: %s, len: %zu", furi_string_get_cstr(next_line), furi_string_size(next_line)); if(furi_string_get_char(next_line, 0) == '#') continue; @@ -101,7 +101,7 @@ MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type) { stream_rewind(dict->stream); dict_loaded = true; - FURI_LOG_I(TAG, "Loaded dictionary with %ld keys", dict->total_keys); + FURI_LOG_I(TAG, "Loaded dictionary with %lu keys", dict->total_keys); } while(false); if(!dict_loaded) { @@ -136,7 +136,7 @@ static void mf_classic_dict_str_to_int(FuriString* key_str, uint64_t* key_int) { for(uint8_t i = 0; i < 12; i += 2) { args_char_to_hex( furi_string_get_char(key_str, i), furi_string_get_char(key_str, i + 1), &key_byte_tmp); - *key_int |= (uint64_t)key_byte_tmp << 8 * (5 - i / 2); + *key_int |= (uint64_t)key_byte_tmp << (8 * (5 - i / 2)); } } @@ -193,7 +193,7 @@ bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, FuriString* key) { bool key_found = false; stream_rewind(dict->stream); - while(!key_found) { + while(!key_found) { //-V654 if(!stream_read_line(dict->stream, next_line)) break; if(furi_string_get_char(next_line, 0) == '#') continue; if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue; @@ -294,7 +294,7 @@ bool mf_classic_dict_find_index_str(MfClassicDict* dict, FuriString* key, uint32 bool key_found = false; uint32_t index = 0; stream_rewind(dict->stream); - while(!key_found) { + while(!key_found) { //-V654 if(!stream_read_line(dict->stream, next_line)) break; if(furi_string_get_char(next_line, 0) == '#') continue; if(furi_string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue; diff --git a/lib/nfc/helpers/reader_analyzer.c b/lib/nfc/helpers/reader_analyzer.c index 73b4b125..af4869ca 100644 --- a/lib/nfc/helpers/reader_analyzer.c +++ b/lib/nfc/helpers/reader_analyzer.c @@ -221,11 +221,11 @@ static void reader_analyzer_write( data_sent = furi_stream_buffer_send( instance->stream, &header, sizeof(ReaderAnalyzerHeader), FuriWaitForever); if(data_sent != sizeof(ReaderAnalyzerHeader)) { - FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, sizeof(ReaderAnalyzerHeader)); + FURI_LOG_W(TAG, "Sent %zu out of %zu bytes", data_sent, sizeof(ReaderAnalyzerHeader)); } data_sent = furi_stream_buffer_send(instance->stream, data, len, FuriWaitForever); if(data_sent != len) { - FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, len); + FURI_LOG_W(TAG, "Sent %zu out of %u bytes", data_sent, len); } } diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 49eebc37..52bff24e 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -576,7 +576,7 @@ static bool nfc_device_save_mifare_df_data(FlipperFormat* file, NfcDevice* dev) tmp = malloc(n_apps * 3); int i = 0; for(MifareDesfireApplication* app = data->app_head; app; app = app->next) { - memcpy(tmp + i, app->id, 3); + memcpy(tmp + i, app->id, 3); //-V769 i += 3; } if(!flipper_format_write_hex(file, "Application IDs", tmp, n_apps * 3)) break; @@ -1085,7 +1085,7 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { saved = true; } while(0); - if(!saved) { + if(!saved) { //-V547 dialog_message_show_storage_error(dev->dialogs, "Can not save\nkey file"); } furi_string_free(temp_str); diff --git a/lib/nfc/nfc_worker.c b/lib/nfc/nfc_worker.c index 450428a1..0ffe1d07 100644 --- a/lib/nfc/nfc_worker.c +++ b/lib/nfc/nfc_worker.c @@ -453,11 +453,11 @@ void nfc_worker_read_type(NfcWorker* nfc_worker) { event = NfcWorkerEventReadUidNfcA; break; } - } else { - if(!card_not_detected_notified) { - nfc_worker->callback(NfcWorkerEventNoCardDetected, nfc_worker->context); - card_not_detected_notified = true; - } + } + } else { + if(!card_not_detected_notified) { + nfc_worker->callback(NfcWorkerEventNoCardDetected, nfc_worker->context); + card_not_detected_notified = true; } } furi_hal_nfc_sleep(); @@ -509,7 +509,7 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { reader_analyzer_start(nfc_worker->reader_analyzer, ReaderAnalyzerModeDebugLog); } - while(nfc_worker->state == NfcWorkerStateEmulateApdu) { + while(nfc_worker->state == NfcWorkerStateEmulateApdu) { //-V1044 if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) { FURI_LOG_D(TAG, "POS terminal detected"); if(emv_card_emulation(&tx_rx)) { @@ -657,7 +657,7 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { } FURI_LOG_D( - TAG, "Start Dictionary attack, Key Count %ld", mf_classic_dict_get_total_keys(dict)); + TAG, "Start Dictionary attack, Key Count %lu", mf_classic_dict_get_total_keys(dict)); for(size_t i = 0; i < total_sectors; i++) { FURI_LOG_I(TAG, "Sector %d", i); nfc_worker->callback(NfcWorkerEventNewSector, nfc_worker->context); @@ -742,7 +742,7 @@ void nfc_worker_emulate_mf_classic(NfcWorker* nfc_worker) { rfal_platform_spi_acquire(); furi_hal_nfc_listen_start(nfc_data); - while(nfc_worker->state == NfcWorkerStateMfClassicEmulate) { + while(nfc_worker->state == NfcWorkerStateMfClassicEmulate) { //-V1044 if(furi_hal_nfc_listen_rx(&tx_rx, 300)) { mf_classic_emulator(&emulator, &tx_rx); } @@ -776,7 +776,8 @@ void nfc_worker_write_mf_classic(NfcWorker* nfc_worker) { furi_hal_nfc_sleep(); FURI_LOG_I(TAG, "Check low level nfc data"); - if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData))) { + if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData)) != + 0) { FURI_LOG_E(TAG, "Wrong card"); nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context); break; @@ -848,7 +849,8 @@ void nfc_worker_update_mf_classic(NfcWorker* nfc_worker) { furi_hal_nfc_sleep(); FURI_LOG_I(TAG, "Check low level nfc data"); - if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData))) { + if(memcmp(&nfc_data, &nfc_worker->dev_data->nfc_data, sizeof(FuriHalNfcDevData)) != + 0) { FURI_LOG_E(TAG, "Low level nfc data mismatch"); nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context); break; diff --git a/lib/nfc/parsers/all_in_one.c b/lib/nfc/parsers/all_in_one.c index 05cfe576..c02710a2 100644 --- a/lib/nfc/parsers/all_in_one.c +++ b/lib/nfc/parsers/all_in_one.c @@ -73,24 +73,14 @@ bool all_in_one_parser_parse(NfcDeviceData* dev_data) { return false; } - // If the layout is a then the ride count is stored in the first byte of page 8 uint8_t ride_count = 0; uint32_t serial = 0; if(all_in_one_get_layout(dev_data) == ALL_IN_ONE_LAYOUT_A) { + // If the layout is A then the ride count is stored in the first byte of page 8 ride_count = dev_data->mf_ul_data.data[4 * 8]; } else if(all_in_one_get_layout(dev_data) == ALL_IN_ONE_LAYOUT_D) { // If the layout is D, the ride count is stored in the second byte of page 9 ride_count = dev_data->mf_ul_data.data[4 * 9 + 1]; - // I hate this with a burning passion. - - // The number starts at the second half of the third byte on page 4, and is 32 bits long - // So we get the second half of the third byte, then bytes 4-6, and then the first half of the 7th byte - // B8 17 A2 A4 BD becomes 81 7A 2A 4B - serial = (dev_data->mf_ul_data.data[4 * 4 + 2] & 0x0F) << 28 | - dev_data->mf_ul_data.data[4 * 4 + 3] << 20 | - dev_data->mf_ul_data.data[4 * 4 + 4] << 12 | - dev_data->mf_ul_data.data[4 * 4 + 5] << 4 | - (dev_data->mf_ul_data.data[4 * 4 + 6] >> 4); } else { FURI_LOG_I("all_in_one", "Unknown layout: %d", all_in_one_get_layout(dev_data)); ride_count = 137; @@ -110,4 +100,4 @@ bool all_in_one_parser_parse(NfcDeviceData* dev_data) { furi_string_printf( dev_data->parsed_data, "\e#All-In-One\nNumber: %lu\nRides left: %u", serial, ride_count); return true; -} \ No newline at end of file +} diff --git a/lib/nfc/parsers/plantain_4k_parser.c b/lib/nfc/parsers/plantain_4k_parser.c index 348b5a64..9a51cdea 100644 --- a/lib/nfc/parsers/plantain_4k_parser.c +++ b/lib/nfc/parsers/plantain_4k_parser.c @@ -116,26 +116,9 @@ bool plantain_4k_parser_parse(NfcDeviceData* dev_data) { for(size_t i = 0; i < 7; i++) { card_number = (card_number << 8) | card_number_arr[i]; } - // Convert card number to string - FuriString* card_number_str; - card_number_str = furi_string_alloc(); - // Should look like "361301047292848684" - furi_string_printf(card_number_str, "%llu", card_number); - // Add suffix with luhn checksum (1 digit) to the card number string - FuriString* card_number_suffix; - card_number_suffix = furi_string_alloc(); - - furi_string_cat_printf(card_number_suffix, "-"); - furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); - // Free all not needed strings - furi_string_free(card_number_suffix); furi_string_printf( - dev_data->parsed_data, - "\e#Plantain\nN:%s\nBalance:%ld\n", - furi_string_get_cstr(card_number_str), - balance); - furi_string_free(card_number_str); + dev_data->parsed_data, "\e#Plantain\nN:%llu-\nBalance:%ld\n", card_number, balance); return true; } diff --git a/lib/nfc/parsers/plantain_parser.c b/lib/nfc/parsers/plantain_parser.c index 5328b5c4..79926217 100644 --- a/lib/nfc/parsers/plantain_parser.c +++ b/lib/nfc/parsers/plantain_parser.c @@ -89,26 +89,9 @@ bool plantain_parser_parse(NfcDeviceData* dev_data) { for(size_t i = 0; i < 7; i++) { card_number = (card_number << 8) | card_number_arr[i]; } - // Convert card number to string - FuriString* card_number_str; - card_number_str = furi_string_alloc(); - // Should look like "361301047292848684" - furi_string_printf(card_number_str, "%llu", card_number); - // Add suffix with luhn checksum (1 digit) to the card number string - FuriString* card_number_suffix; - card_number_suffix = furi_string_alloc(); - - furi_string_cat_printf(card_number_suffix, "-"); - furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); - // Free all not needed strings - furi_string_free(card_number_suffix); furi_string_printf( - dev_data->parsed_data, - "\e#Plantain\nN:%s\nBalance:%ld\n", - furi_string_get_cstr(card_number_str), - balance); - furi_string_free(card_number_str); + dev_data->parsed_data, "\e#Plantain\nN:%llu-\nBalance:%ld\n", card_number, balance); return true; } diff --git a/lib/nfc/parsers/two_cities.c b/lib/nfc/parsers/two_cities.c index 2c6184a7..2f4b7dd0 100644 --- a/lib/nfc/parsers/two_cities.c +++ b/lib/nfc/parsers/two_cities.c @@ -117,19 +117,6 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) { for(size_t i = 0; i < 7; i++) { card_number = (card_number << 8) | card_number_arr[i]; } - // Convert card number to string - FuriString* card_number_str; - card_number_str = furi_string_alloc(); - // Should look like "361301047292848684" - furi_string_printf(card_number_str, "%llu", card_number); - // Add suffix with luhn checksum (1 digit) to the card number string - FuriString* card_number_suffix; - card_number_suffix = furi_string_alloc(); - - furi_string_cat_printf(card_number_suffix, "-"); - furi_string_cat_printf(card_number_str, furi_string_get_cstr(card_number_suffix)); - // Free all not needed strings - furi_string_free(card_number_suffix); // ===== // --PLANTAIN-- @@ -149,12 +136,11 @@ bool two_cities_parser_parse(NfcDeviceData* dev_data) { furi_string_printf( dev_data->parsed_data, - "\e#Troika+Plantain\nPN: %s\nPB: %ld rur.\nTN: %ld\nTB: %d rur.\n", - furi_string_get_cstr(card_number_str), + "\e#Troika+Plantain\nPN: %llu-\nPB: %ld rur.\nTN: %ld\nTB: %d rur.\n", + card_number, balance, troika_number, troika_balance); - furi_string_free(card_number_str); return true; } diff --git a/lib/nfc/protocols/crypto1.c b/lib/nfc/protocols/crypto1.c index 2ac0ff08..f59651cf 100644 --- a/lib/nfc/protocols/crypto1.c +++ b/lib/nfc/protocols/crypto1.c @@ -4,7 +4,8 @@ // Algorithm from https://github.com/RfidResearchGroup/proxmark3.git -#define SWAPENDIAN(x) (x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16) +#define SWAPENDIAN(x) \ + ((x) = ((x) >> 8 & 0xff00ff) | ((x)&0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16) #define LF_POLY_ODD (0x29CE5C) #define LF_POLY_EVEN (0x870804) diff --git a/lib/nfc/protocols/mifare_classic.c b/lib/nfc/protocols/mifare_classic.c index f4c7353a..e26dfd7f 100644 --- a/lib/nfc/protocols/mifare_classic.c +++ b/lib/nfc/protocols/mifare_classic.c @@ -245,7 +245,8 @@ bool mf_classic_is_allowed_access_sector_trailer( case MfClassicActionKeyARead: { return false; } - case MfClassicActionKeyAWrite: { + case MfClassicActionKeyAWrite: + case MfClassicActionKeyBWrite: { return ( (key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) || (key == MfClassicKeyB && (AC == 0x04 || AC == 0x03))); @@ -253,11 +254,6 @@ bool mf_classic_is_allowed_access_sector_trailer( case MfClassicActionKeyBRead: { return (key == MfClassicKeyA && (AC == 0x00 || AC == 0x02 || AC == 0x01)); } - case MfClassicActionKeyBWrite: { - return ( - (key == MfClassicKeyA && (AC == 0x00 || AC == 0x01)) || - (key == MfClassicKeyB && (AC == 0x04 || AC == 0x03))); - } case MfClassicActionACRead: { return ( (key == MfClassicKeyA) || @@ -734,7 +730,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_ MfClassicKey access_key = MfClassicKeyA; // Read command - while(!command_processed) { + while(!command_processed) { //-V654 if(!is_encrypted) { crypto1_reset(&emulator->crypto); memcpy(plain_data, tx_rx->rx_data, tx_rx->rx_bits / 8); @@ -850,7 +846,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_ if(mf_classic_is_sector_trailer(block)) { if(!mf_classic_is_allowed_access( emulator, block, access_key, MfClassicActionKeyARead)) { - memset(block_data, 0, 6); + memset(block_data, 0, 6); //-V1086 } if(!mf_classic_is_allowed_access( emulator, block, access_key, MfClassicActionKeyBRead)) { @@ -860,22 +856,16 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_ emulator, block, access_key, MfClassicActionACRead)) { memset(&block_data[6], 0, 4); } - } else { - if(!mf_classic_is_allowed_access( - emulator, block, access_key, MfClassicActionDataRead)) { - // Send NACK - uint8_t nack = 0x04; - if(is_encrypted) { - crypto1_encrypt( - &emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity); - } else { - tx_rx->tx_data[0] = nack; - } - tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent; - tx_rx->tx_bits = 4; - furi_hal_nfc_tx_rx(tx_rx, 300); - break; - } + } else if(!mf_classic_is_allowed_access( + emulator, block, access_key, MfClassicActionDataRead)) { + // Send NACK + uint8_t nack = 0x04; + crypto1_encrypt( + &emulator->crypto, NULL, &nack, 4, tx_rx->tx_data, tx_rx->tx_parity); + tx_rx->tx_rx_type = FuriHalNfcTxRxTransparent; + tx_rx->tx_bits = 4; + furi_hal_nfc_tx_rx(tx_rx, 300); + break; } nfca_append_crc16(block_data, 16); @@ -908,7 +898,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_ if(mf_classic_is_sector_trailer(block)) { if(mf_classic_is_allowed_access( emulator, block, access_key, MfClassicActionKeyAWrite)) { - memcpy(block_data, plain_data, 6); + memcpy(block_data, plain_data, 6); //-V1086 } if(mf_classic_is_allowed_access( emulator, block, access_key, MfClassicActionKeyBWrite)) { @@ -924,7 +914,7 @@ bool mf_classic_emulator(MfClassicEmulator* emulator, FuriHalNfcTxRxContext* tx_ memcpy(block_data, plain_data, MF_CLASSIC_BLOCK_SIZE); } } - if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE)) { + if(memcmp(block_data, emulator->data.block[block].value, MF_CLASSIC_BLOCK_SIZE) != 0) { memcpy(emulator->data.block[block].value, block_data, MF_CLASSIC_BLOCK_SIZE); emulator->data_changed = true; } @@ -1060,7 +1050,8 @@ bool mf_classic_write_sector( bool write_success = true; for(size_t i = first_block; i < first_block + total_blocks; i++) { // Compare blocks - if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE)) { + if(memcmp(dest_data->block[i].value, src_data->block[i].value, MF_CLASSIC_BLOCK_SIZE) != + 0) { bool key_a_write_allowed = mf_classic_is_allowed_access_data_block( dest_data, i, MfClassicKeyA, MfClassicActionDataWrite); bool key_b_write_allowed = mf_classic_is_allowed_access_data_block( diff --git a/lib/nfc/protocols/mifare_desfire.c b/lib/nfc/protocols/mifare_desfire.c index b2247bf2..23308ae9 100644 --- a/lib/nfc/protocols/mifare_desfire.c +++ b/lib/nfc/protocols/mifare_desfire.c @@ -108,7 +108,7 @@ void mf_df_cat_version(MifareDesfireVersion* version, FuriString* out) { } void mf_df_cat_free_mem(MifareDesfireFreeMemory* free_mem, FuriString* out) { - furi_string_cat_printf(out, "freeMem %ld\n", free_mem->bytes); + furi_string_cat_printf(out, "freeMem %lu\n", free_mem->bytes); } void mf_df_cat_key_settings(MifareDesfireKeySettings* ks, FuriString* out) { @@ -191,10 +191,10 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) { case MifareDesfireFileTypeValue: size = 4; furi_string_cat_printf( - out, "lo %ld hi %ld\n", file->settings.value.lo_limit, file->settings.value.hi_limit); + out, "lo %lu hi %lu\n", file->settings.value.lo_limit, file->settings.value.hi_limit); furi_string_cat_printf( out, - "limit %ld enabled %d\n", + "limit %lu enabled %d\n", file->settings.value.limited_credit_value, file->settings.value.limited_credit_enabled); break; @@ -203,7 +203,7 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) { size = file->settings.record.size; num = file->settings.record.cur; furi_string_cat_printf(out, "size %d\n", size); - furi_string_cat_printf(out, "num %d max %ld\n", num, file->settings.record.max); + furi_string_cat_printf(out, "num %d max %lu\n", num, file->settings.record.max); break; } uint8_t* data = file->contents; @@ -220,8 +220,9 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) { } } for(int i = 0; i < 4 && ch + i < size; i++) { - if(isprint(data[rec * size + ch + i])) { - furi_string_cat_printf(out, "%c", data[rec * size + ch + i]); + const size_t data_index = rec * size + ch + i; + if(isprint(data[data_index])) { + furi_string_cat_printf(out, "%c", data[data_index]); } else { furi_string_cat_printf(out, "."); } @@ -547,7 +548,8 @@ bool mf_df_read_card(FuriHalNfcTxRxContext* tx_rx, MifareDesfireData* data) { for(MifareDesfireApplication* app = data->app_head; app; app = app->next) { tx_rx->tx_bits = 8 * mf_df_prepare_select_application(tx_rx->tx_data, app->id); if(!furi_hal_nfc_tx_rx_full(tx_rx) || - !mf_df_parse_select_application_response(tx_rx->rx_data, tx_rx->rx_bits / 8)) { + !mf_df_parse_select_application_response( + tx_rx->rx_data, tx_rx->rx_bits / 8)) { //-V1051 FURI_LOG_W(TAG, "Bad exchange selecting application"); continue; } diff --git a/lib/nfc/protocols/mifare_ultralight.c b/lib/nfc/protocols/mifare_ultralight.c index 85e234bd..d642e290 100644 --- a/lib/nfc/protocols/mifare_ultralight.c +++ b/lib/nfc/protocols/mifare_ultralight.c @@ -170,6 +170,7 @@ bool mf_ultralight_read_version( } bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint16_t* pack) { + furi_assert(pack); bool authenticated = false; do { @@ -189,9 +190,7 @@ bool mf_ultralight_authenticate(FuriHalNfcTxRxContext* tx_rx, uint32_t key, uint break; } - if(pack != NULL) { - *pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0]; - } + *pack = (tx_rx->rx_data[1] << 8) | tx_rx->rx_data[0]; FURI_LOG_I(TAG, "Auth success. Password: %08lX. PACK: %04X", key, *pack); authenticated = true; @@ -492,7 +491,7 @@ MfUltralightConfigPages* mf_ultralight_get_config_pages(MfUltralightData* data) } else if( data->type >= MfUltralightTypeNTAGI2CPlus1K && data->type <= MfUltralightTypeNTAGI2CPlus2K) { - return (MfUltralightConfigPages*)&data->data[0xe3 * 4]; + return (MfUltralightConfigPages*)&data->data[0xe3 * 4]; //-V641 } else { return NULL; } @@ -561,7 +560,7 @@ bool mf_ultralight_read_pages_direct( FURI_LOG_D(TAG, "Failed to read pages %d - %d", start_index, start_index + 3); return false; } - memcpy(data, tx_rx->rx_data, 16); + memcpy(data, tx_rx->rx_data, 16); //-V1086 return true; } @@ -584,7 +583,8 @@ bool mf_ultralight_read_pages( curr_sector_index = tag_sector; } - FURI_LOG_D(TAG, "Reading pages %d - %d", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1); + FURI_LOG_D( + TAG, "Reading pages %zu - %zu", i, i + (valid_pages > 4 ? 4 : valid_pages) - 1U); tx_rx->tx_data[0] = MF_UL_READ_CMD; tx_rx->tx_data[1] = tag_page; tx_rx->tx_bits = 16; @@ -593,9 +593,9 @@ bool mf_ultralight_read_pages( if(!furi_hal_nfc_tx_rx(tx_rx, 50) || tx_rx->rx_bits < 16 * 8) { FURI_LOG_D( TAG, - "Failed to read pages %d - %d", + "Failed to read pages %zu - %zu", i, - i + (valid_pages > 4 ? 4 : valid_pages) - 1); + i + (valid_pages > 4 ? 4 : valid_pages) - 1U); break; } @@ -857,7 +857,7 @@ static void mf_ul_ntag_i2c_fill_cross_area_read( } if(apply) { - while(tx_page_offset < 0 && page_length > 0) { + while(tx_page_offset < 0 && page_length > 0) { //-V614 ++tx_page_offset; ++data_page_offset; --page_length; @@ -987,9 +987,9 @@ static bool mf_ul_check_lock(MfUltralightEmulator* emulator, int16_t write_page) switch(emulator->data.type) { // low byte LSB range, MSB range case MfUltralightTypeNTAG203: - if(write_page >= 16 && write_page <= 27) + if(write_page >= 16 && write_page <= 27) //-V560 shift = (write_page - 16) / 4 + 1; - else if(write_page >= 28 && write_page <= 39) + else if(write_page >= 28 && write_page <= 39) //-V560 shift = (write_page - 28) / 4 + 5; else if(write_page == 41) shift = 12; @@ -1216,7 +1216,7 @@ static void mf_ul_emulate_write( page_buff[0] = new_locks & 0xff; page_buff[1] = new_locks >> 8; page_buff[2] = new_block_locks; - if(emulator->data.type >= MfUltralightTypeUL21 && + if(emulator->data.type >= MfUltralightTypeUL21 && //-V1016 emulator->data.type <= MfUltralightTypeNTAG216) page_buff[3] = MF_UL_TEARING_FLAG_DEFAULT; else diff --git a/lib/one_wire/ibutton/ibutton_key.c b/lib/one_wire/ibutton/ibutton_key.c index 2c0f7fa2..7b7571a2 100644 --- a/lib/one_wire/ibutton/ibutton_key.c +++ b/lib/one_wire/ibutton/ibutton_key.c @@ -62,8 +62,6 @@ const char* ibutton_key_get_string_by_type(iButtonKeyType key_type) { break; default: furi_crash("Invalid iButton type"); - return ""; - break; } } diff --git a/lib/one_wire/ibutton/ibutton_worker_modes.c b/lib/one_wire/ibutton/ibutton_worker_modes.c index b1e5904c..b284940e 100644 --- a/lib/one_wire/ibutton/ibutton_worker_modes.c +++ b/lib/one_wire/ibutton/ibutton_worker_modes.c @@ -130,7 +130,6 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) { ibutton_key_set_data(worker->key_p, worker->key_data, ibutton_key_get_max_size()); result = true; break; - break; default: break; } diff --git a/lib/one_wire/ibutton/ibutton_writer.c b/lib/one_wire/ibutton/ibutton_writer.c index 203c4fc0..84d12249 100644 --- a/lib/one_wire/ibutton/ibutton_writer.c +++ b/lib/one_wire/ibutton/ibutton_writer.c @@ -72,7 +72,7 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) { writer_write_one_bit(writer, 1, 50000); // read written key byte - answer = onewire_host_read(writer->host); + answer = onewire_host_read(writer->host); //-V519 // check that written and read are same if(ibutton_key_get_data_p(key)[i] != answer) { diff --git a/lib/one_wire/ibutton/protocols/protocol_cyfral.c b/lib/one_wire/ibutton/protocols/protocol_cyfral.c index 51c42824..0c44c2b4 100644 --- a/lib/one_wire/ibutton/protocols/protocol_cyfral.c +++ b/lib/one_wire/ibutton/protocols/protocol_cyfral.c @@ -270,10 +270,10 @@ static LevelDuration protocol_cyfral_encoder_yield(ProtocolCyfral* proto) { // start word (0b0001) switch(proto->encoder.index) { case 0: - result = level_duration_make(false, CYFRAL_0_LOW); + result = level_duration_make(false, CYFRAL_0_LOW); //-V1037 break; case 1: - result = level_duration_make(true, CYFRAL_0_HI); + result = level_duration_make(true, CYFRAL_0_HI); //-V1037 break; case 2: result = level_duration_make(false, CYFRAL_0_LOW); @@ -341,4 +341,4 @@ const ProtocolBase protocol_cyfral = { .start = (ProtocolEncoderStart)protocol_cyfral_encoder_start, .yield = (ProtocolEncoderYield)protocol_cyfral_encoder_yield, }, -}; \ No newline at end of file +}; diff --git a/lib/one_wire/ibutton/protocols/protocol_metakom.c b/lib/one_wire/ibutton/protocols/protocol_metakom.c index 00f16e45..ff65c667 100644 --- a/lib/one_wire/ibutton/protocols/protocol_metakom.c +++ b/lib/one_wire/ibutton/protocols/protocol_metakom.c @@ -248,14 +248,14 @@ static LevelDuration protocol_metakom_encoder_yield(ProtocolMetakom* proto) { if(proto->encoder.index == 0) { // sync bit result = level_duration_make(false, METAKOM_PERIOD); - } else if(proto->encoder.index >= 1 && proto->encoder.index <= 6) { + } else if(proto->encoder.index <= 6) { // start word (0b010) switch(proto->encoder.index) { case 1: - result = level_duration_make(true, METAKOM_0_LOW); + result = level_duration_make(true, METAKOM_0_LOW); //-V1037 break; case 2: - result = level_duration_make(false, METAKOM_0_HI); + result = level_duration_make(false, METAKOM_0_HI); //-V1037 break; case 3: result = level_duration_make(true, METAKOM_1_LOW); @@ -317,4 +317,4 @@ const ProtocolBase protocol_metakom = { .start = (ProtocolEncoderStart)protocol_metakom_encoder_start, .yield = (ProtocolEncoderYield)protocol_metakom_encoder_yield, }, -}; \ No newline at end of file +}; diff --git a/lib/one_wire/one_wire_slave.c b/lib/one_wire/one_wire_slave.c index af04cfda..ad9c34b1 100644 --- a/lib/one_wire/one_wire_slave.c +++ b/lib/one_wire/one_wire_slave.c @@ -41,7 +41,7 @@ uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, cons uint32_t time_ticks = time * furi_hal_cortex_instructions_per_microsecond(); uint32_t time_captured; - do { + do { //-V1044 time_captured = DWT->CYCCNT; if(furi_hal_ibutton_pin_get_level() != pin_value) { uint32_t remaining_time = time_ticks - (time_captured - start); @@ -155,8 +155,10 @@ bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) { uint8_t cmd; onewire_slave_receive(bus, &cmd, 1); - if(bus->error == RESET_IN_PROGRESS) return true; - if(bus->error != NO_ERROR) return false; + if(bus->error == RESET_IN_PROGRESS) + return true; + else if(bus->error != NO_ERROR) + return false; switch(cmd) { case 0xF0: @@ -172,10 +174,8 @@ bool onewire_slave_receive_and_process_cmd(OneWireSlave* bus) { default: // Unknown command bus->error = INCORRECT_ONEWIRE_CMD; + return false; } - - if(bus->error == RESET_IN_PROGRESS) return true; - return (bus->error == NO_ERROR); } bool onewire_slave_bus_start(OneWireSlave* bus) { diff --git a/lib/print/printf_tiny.c b/lib/print/printf_tiny.c index 6e47f652..54f192a6 100644 --- a/lib/print/printf_tiny.c +++ b/lib/print/printf_tiny.c @@ -541,7 +541,7 @@ static size_t _etoa( exp2 = (int)(expval * 3.321928094887362 + 0.5); const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453; const double z2 = z * z; - conv.U = ((uint64_t)exp2 + 1023) << 52U; + conv.U = ((uint64_t)exp2 + 1023) << 52U; //-V519 // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); // correct for rounding errors diff --git a/lib/subghz/blocks/generic.c b/lib/subghz/blocks/generic.c index 1bad5f0a..94114676 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -71,7 +71,7 @@ bool subghz_block_generic_serialize( uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->data >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->data >> (i * 8)) & 0xFF; } if(!flipper_format_write_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) { diff --git a/lib/subghz/blocks/math.h b/lib/subghz/blocks/math.h index a4f04271..87c209f7 100644 --- a/lib/subghz/blocks/math.h +++ b/lib/subghz/blocks/math.h @@ -8,8 +8,7 @@ #define bit_set(value, bit) ((value) |= (1UL << (bit))) #define bit_clear(value, bit) ((value) &= ~(1UL << (bit))) #define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit)) -#define DURATION_DIFF(x, y) ((x < y) ? (y - x) : (x - y)) -#define abs(x) ((x) > 0 ? (x) : -(x)) +#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) #ifdef __cplusplus extern "C" { diff --git a/lib/subghz/protocols/bett.c b/lib/subghz/protocols/bett.c index 2dd39af9..644d80fd 100644 --- a/lib/subghz/protocols/bett.c +++ b/lib/subghz/protocols/bett.c @@ -242,7 +242,6 @@ void subghz_protocol_decoder_bett_feed(void* context, bool level, uint32_t durat if(!level) { if(DURATION_DIFF(duration, subghz_protocol_bett_const.te_short * 44) < (subghz_protocol_bett_const.te_delta * 15)) { - instance->decoder.parser_step = BETTDecoderStepSaveDuration; if(instance->decoder.decode_count_bit == subghz_protocol_bett_const.min_count_bit_for_found) { instance->generic.data = instance->decoder.decode_data; diff --git a/lib/subghz/protocols/holtek.c b/lib/subghz/protocols/holtek.c index 39e27bbf..8aaad3b7 100644 --- a/lib/subghz/protocols/holtek.c +++ b/lib/subghz/protocols/holtek.c @@ -240,7 +240,6 @@ void subghz_protocol_decoder_holtek_feed(void* context, bool level, uint32_t dur if(!level) { if(duration >= ((uint32_t)subghz_protocol_holtek_const.te_short * 10 + subghz_protocol_holtek_const.te_delta)) { - instance->decoder.parser_step = HoltekDecoderStepSaveDuration; if(instance->decoder.decode_count_bit == subghz_protocol_holtek_const.min_count_bit_for_found) { if((instance->decoder.decode_data & HOLTEK_HEADER_MASK) == HOLTEK_HEADER) { diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index eef1d093..6a9c3468 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -119,8 +119,8 @@ void subghz_protocol_encoder_keeloq_free(void* context) { */ static bool subghz_protocol_keeloq_gen_data(SubGhzProtocolEncoderKeeloq* instance, uint8_t btn) { instance->generic.cnt++; - uint32_t fix = btn << 28 | instance->generic.serial; - uint32_t decrypt = btn << 28 | + uint32_t fix = (uint32_t)btn << 28 | instance->generic.serial; + uint32_t decrypt = (uint32_t)btn << 28 | (instance->generic.serial & 0x3FF) << 16 | //ToDo in some protocols the discriminator is 0 instance->generic.cnt; @@ -271,7 +271,8 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl subghz_protocol_keeloq_check_remote_controller( &instance->generic, instance->keystore, &instance->manufacture_name); - if(strcmp(instance->manufacture_name, "DoorHan")) { + if(strcmp(instance->manufacture_name, "DoorHan") != 0) { + FURI_LOG_E(TAG, "Wrong manufacturer name"); break; } @@ -287,7 +288,7 @@ bool subghz_protocol_encoder_keeloq_deserialize(void* context, FlipperFormat* fl } uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF; } if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) { FURI_LOG_E(TAG, "Unable to add Key"); diff --git a/lib/subghz/protocols/kia.c b/lib/subghz/protocols/kia.c index 997f8e1d..a5d9e37e 100644 --- a/lib/subghz/protocols/kia.c +++ b/lib/subghz/protocols/kia.c @@ -142,7 +142,7 @@ void subghz_protocol_decoder_kia_feed(void* context, bool level, uint32_t durati case KIADecoderStepSaveDuration: if(level) { if(duration >= - (uint32_t)(subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2)) { + (subghz_protocol_kia_const.te_long + subghz_protocol_kia_const.te_delta * 2UL)) { //Found stop bit instance->decoder.parser_step = KIADecoderStepReset; if(instance->decoder.decode_count_bit == diff --git a/lib/subghz/protocols/megacode.c b/lib/subghz/protocols/megacode.c index 1b871a0c..05b5b689 100644 --- a/lib/subghz/protocols/megacode.c +++ b/lib/subghz/protocols/megacode.c @@ -417,7 +417,7 @@ void subghz_protocol_decoder_megacode_get_string(void* context, FuriString* outp output, "%s %dbit\r\n" "Key:0x%06lX\r\n" - "Sn:0x%04lX - %ld\r\n" + "Sn:0x%04lX - %lu\r\n" "Facility:%lX Btn:%X\r\n", instance->generic.protocol_name, instance->generic.data_count_bit, diff --git a/lib/subghz/protocols/nero_radio.c b/lib/subghz/protocols/nero_radio.c index 5fffaa19..c8126b1e 100644 --- a/lib/subghz/protocols/nero_radio.c +++ b/lib/subghz/protocols/nero_radio.c @@ -308,7 +308,7 @@ void subghz_protocol_decoder_nero_radio_feed(void* context, bool level, uint32_t } instance->decoder.decode_data = 0; instance->decoder.decode_count_bit = 0; - instance->decoder.parser_step = NeroRadioDecoderStepReset; + instance->decoder.parser_step = NeroRadioDecoderStepReset; //-V1048 break; } else if( (DURATION_DIFF( diff --git a/lib/subghz/protocols/princeton.c b/lib/subghz/protocols/princeton.c index ab1c5876..7fc8f652 100644 --- a/lib/subghz/protocols/princeton.c +++ b/lib/subghz/protocols/princeton.c @@ -363,7 +363,7 @@ void subghz_protocol_decoder_princeton_get_string(void* context, FuriString* out "Key:0x%08lX\r\n" "Yek:0x%08lX\r\n" "Sn:0x%05lX Btn:%01X\r\n" - "Te:%ldus\r\n", + "Te:%luus\r\n", instance->generic.protocol_name, instance->generic.data_count_bit, (uint32_t)(instance->generic.data & 0xFFFFFF), diff --git a/lib/subghz/protocols/princeton_for_testing.c b/lib/subghz/protocols/princeton_for_testing.c index 0987e0ad..fa561602 100644 --- a/lib/subghz/protocols/princeton_for_testing.c +++ b/lib/subghz/protocols/princeton_for_testing.c @@ -94,12 +94,12 @@ void subghz_encoder_princeton_for_testing_print_log(void* context) { ((float)instance->time_high / (instance->time_high + instance->time_low)) * 100; FURI_LOG_I( TAG "Encoder", - "Radio tx_time=%ldus ON=%ldus, OFF=%ldus, DutyCycle=%ld,%ld%%", + "Radio tx_time=%luus ON=%luus, OFF=%luus, DutyCycle=%lu,%lu%%", instance->time_high + instance->time_low, instance->time_high, instance->time_low, (uint32_t)duty_cycle, - (uint32_t)((duty_cycle - (uint32_t)duty_cycle) * 100)); + (uint32_t)((duty_cycle - (uint32_t)duty_cycle) * 100UL)); } LevelDuration subghz_encoder_princeton_for_testing_yield(void* context) { diff --git a/lib/subghz/protocols/scher_khan.c b/lib/subghz/protocols/scher_khan.c index a9a3078e..955104bc 100644 --- a/lib/subghz/protocols/scher_khan.c +++ b/lib/subghz/protocols/scher_khan.c @@ -151,8 +151,8 @@ void subghz_protocol_decoder_scher_khan_feed(void* context, bool level, uint32_t break; case ScherKhanDecoderStepSaveDuration: if(level) { - if(duration >= (uint32_t)(subghz_protocol_scher_khan_const.te_long + - subghz_protocol_scher_khan_const.te_delta * 2)) { + if(duration >= (subghz_protocol_scher_khan_const.te_delta * 2UL + + subghz_protocol_scher_khan_const.te_long)) { //Found stop bit instance->decoder.parser_step = ScherKhanDecoderStepReset; if(instance->decoder.decode_count_bit >= diff --git a/lib/subghz/protocols/secplus_v1.c b/lib/subghz/protocols/secplus_v1.c index 7bd0b5b7..75a44a26 100644 --- a/lib/subghz/protocols/secplus_v1.c +++ b/lib/subghz/protocols/secplus_v1.c @@ -291,7 +291,7 @@ bool subghz_protocol_encoder_secplus_v1_deserialize(void* context, FlipperFormat uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF; } if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) { FURI_LOG_E(TAG, "Unable to add Key"); @@ -550,7 +550,7 @@ bool subghz_protocol_secplus_v1_check_fixed(uint32_t fixed) { do { if(id1 == 0) return false; - if(!(btn == 0 || btn == 1 || btn == 2)) return false; + if(!(btn == 0 || btn == 1 || btn == 2)) return false; //-V560 } while(false); return true; } @@ -588,7 +588,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou if(pin <= 9999) { furi_string_cat_printf(output, " pin:%d", pin); - } else if(10000 <= pin && pin <= 11029) { + } else if(pin <= 11029) { furi_string_cat_printf(output, " pin:enter"); } @@ -618,7 +618,7 @@ void subghz_protocol_decoder_secplus_v1_get_string(void* context, FuriString* ou furi_string_cat_printf(output, " Btn:left\r\n"); } else if(instance->generic.btn == 0) { furi_string_cat_printf(output, " Btn:middle\r\n"); - } else if(instance->generic.btn == 2) { + } else if(instance->generic.btn == 2) { //-V547 furi_string_cat_printf(output, " Btn:right\r\n"); } diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index 90cc805a..7b79892b 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -151,7 +151,7 @@ static bool subghz_protocol_secplus_v2_mix_order_decode(uint8_t order, uint16_t case 0x06: // 0b0110 2, 1, 0], case 0x09: // 0b1001 2, 1, 0], p[2] = a; - p[1] = b; + // p[1]: no change p[0] = c; break; case 0x08: // 0b1000 1, 2, 0], @@ -166,20 +166,18 @@ static bool subghz_protocol_secplus_v2_mix_order_decode(uint8_t order, uint16_t p[1] = c; break; case 0x00: // 0b0000 0, 2, 1], - p[0] = a; + // p[0]: no change p[2] = b; p[1] = c; break; case 0x05: // 0b0101 1, 0, 2], p[1] = a; p[0] = b; - p[2] = c; + // p[2]: no change break; case 0x02: // 0b0010 0, 1, 2], case 0x0A: // 0b1010 0, 1, 2], - p[0] = a; - p[1] = b; - p[2] = c; + // no reordering break; default: FURI_LOG_E(TAG, "Order FAIL"); @@ -539,7 +537,7 @@ bool subghz_protocol_encoder_secplus_v2_deserialize(void* context, FlipperFormat //update data for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->generic.data >> (i * 8)) & 0xFF; } if(!flipper_format_update_hex(flipper_format, "Key", key_data, sizeof(uint64_t))) { FURI_LOG_E(TAG, "Unable to add Key"); @@ -547,7 +545,7 @@ bool subghz_protocol_encoder_secplus_v2_deserialize(void* context, FlipperFormat } for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF; } if(!flipper_format_update_hex( flipper_format, "Secplus_packet_1", key_data, sizeof(uint64_t))) { @@ -605,7 +603,7 @@ bool subghz_protocol_secplus_v2_create_data( uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF; } if(res && @@ -691,7 +689,7 @@ void subghz_protocol_decoder_secplus_v2_feed(void* context, bool level, uint32_t subghz_protocol_secplus_v2_const.te_delta) { event = ManchesterEventLongLow; } else if( - duration >= (uint32_t)(subghz_protocol_secplus_v2_const.te_long * 2 + + duration >= (subghz_protocol_secplus_v2_const.te_long * 2UL + subghz_protocol_secplus_v2_const.te_delta)) { if(instance->decoder.decode_count_bit == subghz_protocol_secplus_v2_const.min_count_bit_for_found) { @@ -766,7 +764,7 @@ bool subghz_protocol_decoder_secplus_v2_serialize( uint8_t key_data[sizeof(uint64_t)] = {0}; for(size_t i = 0; i < sizeof(uint64_t); i++) { - key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> i * 8) & 0xFF; + key_data[sizeof(uint64_t) - i - 1] = (instance->secplus_packet_1 >> (i * 8)) & 0xFF; } if(res && diff --git a/lib/subghz/protocols/smc5326.c b/lib/subghz/protocols/smc5326.c index 889e39f0..9c9b5d4f 100644 --- a/lib/subghz/protocols/smc5326.c +++ b/lib/subghz/protocols/smc5326.c @@ -372,8 +372,8 @@ void subghz_protocol_decoder_smc5326_get_string(void* context, FuriString* outpu furi_string_cat_printf( output, - "%s %dbit\r\n" - "Key:%07lX Te:%ldus\r\n" + "%s %ubit\r\n" + "Key:%07lX Te:%luus\r\n" " +: " DIP_PATTERN "\r\n" " o: " DIP_PATTERN " ", instance->generic.protocol_name, diff --git a/lib/subghz/subghz_file_encoder_worker.c b/lib/subghz/subghz_file_encoder_worker.c index abc33188..5c4d36f7 100644 --- a/lib/subghz/subghz_file_encoder_worker.c +++ b/lib/subghz/subghz_file_encoder_worker.c @@ -90,7 +90,7 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) { level_duration = level_duration_make(false, -duration); } else if(duration > 0) { level_duration = level_duration_make(true, duration); - } else if(duration == 0) { + } else if(duration == 0) { //-V547 level_duration = level_duration_reset(); FURI_LOG_I(TAG, "Stop transmission"); instance->worker_stoping = true; diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index e06bd979..e0b1cf6c 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -189,7 +189,7 @@ bool subghz_keystore_load(SubGhzKeystore* instance, const char* file_name) { bool result = false; uint8_t iv[16]; uint32_t version; - SubGhzKeystoreEncryption encryption; + uint32_t encryption; FuriString* filetype; filetype = furi_string_alloc(); @@ -324,9 +324,9 @@ bool subghz_keystore_save(SubGhzKeystore* instance, const char* file_name, uint8 size_t total_keys = SubGhzKeyArray_size(instance->data); result = encrypted_line_count == total_keys; if(result) { - FURI_LOG_I(TAG, "Success. Encrypted: %d of %d", encrypted_line_count, total_keys); + FURI_LOG_I(TAG, "Success. Encrypted: %zu of %zu", encrypted_line_count, total_keys); } else { - FURI_LOG_E(TAG, "Failure. Encrypted: %d of %d", encrypted_line_count, total_keys); + FURI_LOG_E(TAG, "Failure. Encrypted: %zu of %zu", encrypted_line_count, total_keys); } } while(0); flipper_format_free(flipper_format); @@ -349,9 +349,9 @@ bool subghz_keystore_raw_encrypted_save( uint8_t* iv) { bool encrypted = false; uint32_t version; + uint32_t encryption; FuriString* filetype; filetype = furi_string_alloc(); - SubGhzKeystoreEncryption encryption; Storage* storage = furi_record_open(RECORD_STORAGE); @@ -464,7 +464,7 @@ bool subghz_keystore_raw_encrypted_save( } stream_write_cstring(output_stream, encrypted_line); - } while(result); + } while(true); flipper_format_free(output_flipper_format); @@ -488,7 +488,7 @@ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* bool result = false; uint8_t iv[16]; uint32_t version; - SubGhzKeystoreEncryption encryption; + uint32_t encryption; FuriString* str_temp; str_temp = furi_string_alloc(); diff --git a/lib/subghz/subghz_setting.c b/lib/subghz/subghz_setting.c index c5ec5db7..57e23c38 100644 --- a/lib/subghz/subghz_setting.c +++ b/lib/subghz/subghz_setting.c @@ -532,9 +532,8 @@ uint8_t* subghz_setting_get_preset_data_by_name(SubGhzSetting* instance, const c uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) { furi_assert(instance); - uint32_t* ret = FrequencyList_get(instance->frequencies, idx); - if(ret) { - return (*ret) & FREQUENCY_MASK; + if(idx < FrequencyList_size(instance->frequencies)) { + return (*FrequencyList_get(instance->frequencies, idx)) & FREQUENCY_MASK; } else { return 0; } @@ -542,9 +541,8 @@ uint32_t subghz_setting_get_frequency(SubGhzSetting* instance, size_t idx) { uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx) { furi_assert(instance); - uint32_t* ret = FrequencyList_get(instance->hopper_frequencies, idx); - if(ret) { - return *ret; + if(idx < FrequencyList_size(instance->frequencies)) { + return *FrequencyList_get(instance->hopper_frequencies, idx); } else { return 0; } diff --git a/lib/toolbox/dir_walk.c b/lib/toolbox/dir_walk.c index b5e2cb52..e5a3cf32 100644 --- a/lib/toolbox/dir_walk.c +++ b/lib/toolbox/dir_walk.c @@ -69,8 +69,11 @@ static DirWalkResult if(dir_walk_filter(dir_walk, name, &info)) { if(return_path != NULL) { - furi_string_printf( - return_path, "%s/%s", furi_string_get_cstr(dir_walk->path), name); + furi_string_printf( //-V576 + return_path, + "%s/%s", + furi_string_get_cstr(dir_walk->path), + name); } if(fileinfo != NULL) { diff --git a/lib/toolbox/float_tools.c b/lib/toolbox/float_tools.c new file mode 100644 index 00000000..9c0fe871 --- /dev/null +++ b/lib/toolbox/float_tools.c @@ -0,0 +1,8 @@ +#include "float_tools.h" + +#include +#include + +bool float_is_equal(float a, float b) { + return fabsf(a - b) <= FLT_EPSILON * fmaxf(fabsf(a), fabsf(b)); +} diff --git a/lib/toolbox/float_tools.h b/lib/toolbox/float_tools.h new file mode 100644 index 00000000..0b758e9f --- /dev/null +++ b/lib/toolbox/float_tools.h @@ -0,0 +1,19 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** Compare two floating point numbers + * @param a First number to compare + * @param b Second number to compare + * + * @return bool true if a equals b, false otherwise + */ +bool float_is_equal(float a, float b); + +#ifdef __cplusplus +} +#endif diff --git a/lib/toolbox/hex.c b/lib/toolbox/hex.c index 7b2719b7..25dcb095 100644 --- a/lib/toolbox/hex.c +++ b/lib/toolbox/hex.c @@ -1,14 +1,14 @@ #include "hex.h" bool hex_char_to_hex_nibble(char c, uint8_t* nibble) { - if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) { - if((c >= '0' && c <= '9')) { - *nibble = c - '0'; - } else if((c >= 'A' && c <= 'F')) { - *nibble = c - 'A' + 10; - } else { - *nibble = c - 'a' + 10; - } + if((c >= '0' && c <= '9')) { + *nibble = c - '0'; + return true; + } else if((c >= 'A' && c <= 'F')) { + *nibble = c - 'A' + 10; + return true; + } else if(c >= 'a' && c <= 'f') { + *nibble = c - 'a' + 10; return true; } else { return false; diff --git a/lib/toolbox/md5.c b/lib/toolbox/md5.c index 3cf7cf05..a907d52e 100644 --- a/lib/toolbox/md5.c +++ b/lib/toolbox/md5.c @@ -115,7 +115,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) { GET_UINT32_LE(X[14], data, 56); GET_UINT32_LE(X[15], data, 60); -#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) +#define S(x, n) (((x) << (n)) | (((x)&0xFFFFFFFF) >> (32 - (n)))) #define P(a, b, c, d, k, s, t) \ { \ @@ -128,7 +128,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) { C = ctx->state[2]; D = ctx->state[3]; -#define F(x, y, z) (z ^ (x & (y ^ z))) +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) P(A, B, C, D, 0, 7, 0xD76AA478); P(D, A, B, C, 1, 12, 0xE8C7B756); @@ -149,7 +149,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) { #undef F -#define F(x, y, z) (y ^ (z & (x ^ y))) +#define F(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) P(A, B, C, D, 1, 5, 0xF61E2562); P(D, A, B, C, 6, 9, 0xC040B340); @@ -170,7 +170,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) { #undef F -#define F(x, y, z) (x ^ y ^ z) +#define F(x, y, z) ((x) ^ (y) ^ (z)) P(A, B, C, D, 5, 4, 0xFFFA3942); P(D, A, B, C, 8, 11, 0x8771F681); @@ -191,7 +191,7 @@ void md5_process(md5_context* ctx, const unsigned char data[64]) { #undef F -#define F(x, y, z) (y ^ (x | ~z)) +#define F(x, y, z) ((y) ^ ((x) | ~(z))) P(A, B, C, D, 0, 6, 0xF4292244); P(D, A, B, C, 7, 10, 0x432AFF97); @@ -295,5 +295,5 @@ void md5(const unsigned char* input, size_t ilen, unsigned char output[16]) { md5_update(&ctx, input, ilen); md5_finish(&ctx, output); - memset(&ctx, 0, sizeof(md5_context)); + memset(&ctx, 0, sizeof(md5_context)); //-V597 } diff --git a/lib/toolbox/sha256.c b/lib/toolbox/sha256.c index ece77955..ff498443 100644 --- a/lib/toolbox/sha256.c +++ b/lib/toolbox/sha256.c @@ -62,15 +62,15 @@ static void memcpy_output_bswap32(unsigned char* dst, const uint32_t* p) { } } -#define rotr32(x, n) (((x) >> n) | ((x) << (32 - n))) +#define rotr32(x, n) (((x) >> n) | ((x) << (32 - (n)))) #define ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define maj(x, y, z) (((x) & (y)) | ((z) & ((x) ^ (y)))) /* round transforms for SHA256 compression functions */ -#define vf(n, i) v[(n - i) & 7] +#define vf(n, i) v[((n) - (i)) & 7] -#define hf(i) (p[i & 15] += g_1(p[(i + 14) & 15]) + p[(i + 9) & 15] + g_0(p[(i + 1) & 15])) +#define hf(i) (p[(i)&15] += g_1(p[((i) + 14) & 15]) + p[((i) + 9) & 15] + g_0(p[((i) + 1) & 15])) #define v_cycle0(i) \ p[i] = __builtin_bswap32(p[i]); \ @@ -176,8 +176,8 @@ void sha256_finish(sha256_context* ctx, unsigned char output[32]) { uint32_t last = (ctx->total[0] & SHA256_MASK); ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]); - ctx->wbuf[last >> 2] &= 0xffffff80 << (8 * (~last & 3)); - ctx->wbuf[last >> 2] |= 0x00000080 << (8 * (~last & 3)); + ctx->wbuf[last >> 2] &= 0xffffff80UL << (8 * (~last & 3)); + ctx->wbuf[last >> 2] |= 0x00000080UL << (8 * (~last & 3)); ctx->wbuf[last >> 2] = __builtin_bswap32(ctx->wbuf[last >> 2]); if(last > SHA256_BLOCK_SIZE - 9) { diff --git a/lib/toolbox/stream/stream.c b/lib/toolbox/stream/stream.c index 86d35c95..055bab5b 100644 --- a/lib/toolbox/stream/stream.c +++ b/lib/toolbox/stream/stream.c @@ -315,8 +315,8 @@ void stream_dump_data(Stream* stream) { size_t size = stream_size(stream); size_t tell = stream_tell(stream); printf("stream %p\r\n", stream); - printf("size = %u\r\n", size); - printf("tell = %u\r\n", tell); + printf("size = %zu\r\n", size); + printf("tell = %zu\r\n", tell); printf("DATA START\r\n"); uint8_t* data = malloc(STREAM_CACHE_SIZE); stream_rewind(stream); diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c index e8b44729..fd0d175e 100644 --- a/lib/toolbox/tar/tar_archive.c +++ b/lib/toolbox/tar/tar_archive.c @@ -236,7 +236,7 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header, return 0; } - FURI_LOG_D(TAG, "Extracting %d bytes to '%s'", header->size, header->name); + FURI_LOG_D(TAG, "Extracting %u bytes to '%s'", header->size, header->name); FuriString* converted_fname = furi_string_alloc_set(header->name); if(op_params->converter) { @@ -382,4 +382,4 @@ bool tar_archive_unpack_file( return false; } return archive_extract_current_file(archive, destination); -} \ No newline at end of file +} diff --git a/lib/toolbox/varint.c b/lib/toolbox/varint.c index ee2f5c3a..79777c4b 100644 --- a/lib/toolbox/varint.c +++ b/lib/toolbox/varint.c @@ -15,7 +15,7 @@ size_t varint_uint32_unpack(uint32_t* value, const uint8_t* input, size_t input_ uint32_t parsed = 0; for(i = 0; i < input_size; i++) { - parsed |= (input[i] & 0x7F) << (7 * i); + parsed |= (input[i] & 0x7FUL) << (7 * i); if(!(input[i] & 0x80)) { break; @@ -73,4 +73,4 @@ size_t varint_int32_length(int32_t value) { } return varint_uint32_length(v); -} \ No newline at end of file +} diff --git a/lib/update_util/dfu_file.c b/lib/update_util/dfu_file.c index d6f31b60..62b139e8 100644 --- a/lib/update_util/dfu_file.c +++ b/lib/update_util/dfu_file.c @@ -35,7 +35,7 @@ uint8_t dfu_file_validate_headers(File* dfuf, const DfuValidationParams* referen return 0; } - if(memcmp(dfu_prefix.szSignature, DFU_SIGNATURE, sizeof(dfu_prefix.szSignature))) { + if(memcmp(dfu_prefix.szSignature, DFU_SIGNATURE, sizeof(dfu_prefix.szSignature)) != 0) { return 0; } diff --git a/lib/update_util/resources/manifest.c b/lib/update_util/resources/manifest.c index 8b6a1b33..baa7aceb 100644 --- a/lib/update_util/resources/manifest.c +++ b/lib/update_util/resources/manifest.c @@ -98,7 +98,7 @@ ResourceManifestEntry* resource_manifest_reader_next(ResourceManifestReader* res furi_string_right(resource_manifest->linebuf, offs + 1); furi_string_set(resource_manifest->entry.name, resource_manifest->linebuf); - } else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) { + } else if(resource_manifest->entry.type == ResourceManifestEntryTypeDirectory) { //-V547 /* Parse directory entry D: */ diff --git a/lib/update_util/update_operation.c b/lib/update_util/update_operation.c index 3a44605e..c6a9ccc5 100644 --- a/lib/update_util/update_operation.c +++ b/lib/update_util/update_operation.c @@ -11,7 +11,7 @@ #define UPDATE_ROOT_DIR EXT_PATH("update") /* Need at least 4 free LFS pages before update */ -#define UPDATE_MIN_INT_FREE_SPACE 2 * 4 * 1024 +#define UPDATE_MIN_INT_FREE_SPACE (2 * 4 * 1024) static const char* update_prepare_result_descr[] = { [UpdatePrepareResultOK] = "OK", @@ -110,7 +110,7 @@ bool update_operation_get_current_package_manifest_path(Storage* storage, FuriSt } static bool update_operation_persist_manifest_path(Storage* storage, const char* manifest_path) { - const uint16_t manifest_path_len = strlen(manifest_path); + const size_t manifest_path_len = strlen(manifest_path); furi_check(manifest_path && manifest_path_len); bool success = false; File* file = storage_file_alloc(storage); diff --git a/scripts/fbt_tools/fbt_debugopts.py b/scripts/fbt_tools/fbt_debugopts.py index 9ff05cb7..f4b021c2 100644 --- a/scripts/fbt_tools/fbt_debugopts.py +++ b/scripts/fbt_tools/fbt_debugopts.py @@ -41,12 +41,10 @@ def generate(env, **kw): "|openocd -c 'gdb_port pipe; log_output ${FBT_DEBUG_DIR}/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}" ], GDBOPTS_BASE=[ - "-ex", - "set pagination off", "-ex", "target extended-remote ${GDBREMOTE}", "-ex", - "set confirm off", + "source ${FBT_DEBUG_DIR}/gdbinit", ], GDBOPTS_BLACKMAGIC=[ "-ex",