From 84c228c9f59edb341f434a577b4e3352def47540 Mon Sep 17 00:00:00 2001 From: Leeroy <135471162+LeeroysHub@users.noreply.github.com> Date: Sat, 26 Sep 2026 15:48:32 +1000 Subject: [PATCH] Get rid of always allocated 64 byte save_flename --- protopirate_app.c | 7 ++++++- protopirate_app_i.h | 2 +- scenes/protopirate_scene_receiver_info.c | 26 +++++++++++++++++++----- scenes/protopirate_scene_sub_decode.c | 23 +++++++++++++++------ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/protopirate_app.c b/protopirate_app.c index 355c46f..e7c1afa 100644 --- a/protopirate_app.c +++ b/protopirate_app.c @@ -185,7 +185,7 @@ ProtoPirateApp* protopirate_app_alloc() { app->save_protocol = NULL; app->save_history_idx = 0; app->emulate_disabled_for_loaded = false; - memset(app->save_filename, 0, sizeof(app->save_filename)); + app->save_filename = NULL; // File Browser path app->file_path = furi_string_alloc(); @@ -410,6 +410,11 @@ void protopirate_app_free(ProtoPirateApp* app) { protopirate_views_free(app); + if(app->save_filename) { + free(app->save_filename); + app->save_filename = NULL; + } + if(app->file_path) { FURI_LOG_D(TAG, "Freeing file_path"); furi_string_free(app->file_path); diff --git a/protopirate_app_i.h b/protopirate_app_i.h index b51668c..b229eaf 100644 --- a/protopirate_app_i.h +++ b/protopirate_app_i.h @@ -101,7 +101,7 @@ struct ProtoPirateApp { uint8_t emulate_feature_enabled : 1; uint32_t start_tx_time; uint8_t tx_power; - char save_filename[64]; + char* save_filename; FuriString* save_protocol; uint16_t save_history_idx; PluginManager* plugin_manager; diff --git a/scenes/protopirate_scene_receiver_info.c b/scenes/protopirate_scene_receiver_info.c index 8626eb5..ef38dee 100644 --- a/scenes/protopirate_scene_receiver_info.c +++ b/scenes/protopirate_scene_receiver_info.c @@ -315,13 +315,16 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e size_t name_len = strlen(name_start); const char* dot = strrchr(name_start, '.'); if(dot) name_len = dot - name_start; - if(name_len >= sizeof(app->save_filename)) - name_len = sizeof(app->save_filename) - 1; + if(name_len >= 64) name_len = 64; + if(app->save_filename) free(app->save_filename); + app->save_filename = malloc(name_len + 1); memcpy(app->save_filename, name_start, name_len); - app->save_filename[name_len] = '\0'; } else { - snprintf(app->save_filename, sizeof(app->save_filename), "capture"); + if(app->save_filename) free(app->save_filename); + uint8_t len = 8; + app->save_filename = malloc(len); + snprintf(app->save_filename, len, "capture"); } furi_string_free(auto_path); @@ -338,7 +341,7 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e protopirate_scene_receiver_info_text_input_callback, app, app->save_filename, - sizeof(app->save_filename), + strlen(app->save_filename), false); // don't clear default text view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewTextInput); @@ -377,6 +380,19 @@ bool protopirate_scene_receiver_info_on_event(void* context, SceneManagerEvent e // Return to the receiver info widget view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewWidget); + + //Kill the text_input view. + if(app->text_input) { + FURI_LOG_D(TAG, "Removing text_input view"); + view_dispatcher_remove_view(app->view_dispatcher, ProtoPirateViewTextInput); + text_input_free(app->text_input); + app->text_input = NULL; + } + + if(app->save_filename) { + free(app->save_filename); + app->save_filename = NULL; + } consumed = true; } diff --git a/scenes/protopirate_scene_sub_decode.c b/scenes/protopirate_scene_sub_decode.c index 07dc86d..1cc0747 100644 --- a/scenes/protopirate_scene_sub_decode.c +++ b/scenes/protopirate_scene_sub_decode.c @@ -677,13 +677,16 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even size_t name_len = strlen(name_start); const char* dot = strrchr(name_start, '.'); if(dot) name_len = dot - name_start; - if(name_len >= sizeof(app->save_filename)) - name_len = sizeof(app->save_filename) - 1; + if(name_len > 64) name_len = 64; + if(app->save_filename) free(app->save_filename); + app->save_filename = malloc(name_len + 1); memcpy(app->save_filename, name_start, name_len); - app->save_filename[name_len] = '\0'; } else { - snprintf(app->save_filename, sizeof(app->save_filename), "capture"); + if(app->save_filename) free(app->save_filename); + uint8_t len = 8; + app->save_filename = malloc(len); + snprintf(app->save_filename, len, "capture"); } furi_string_free(auto_path); @@ -705,7 +708,7 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even protopirate_scene_sub_decode_text_input_callback, app, app->save_filename, - sizeof(app->save_filename), + strlen(app->save_filename), false); // don't clear default text view_dispatcher_switch_to_view(app->view_dispatcher, ProtoPirateViewTextInput); @@ -750,6 +753,11 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even text_input_free(app->text_input); app->text_input = NULL; } + + if(app->save_filename) { + free(app->save_filename); + app->save_filename = NULL; + } consumed = true; } @@ -1393,7 +1401,10 @@ bool protopirate_scene_sub_decode_on_event(void* context, SceneManagerEvent even if(ctx->showing_signal_info) { // In signal info - go back to history ctx->showing_signal_info = false; - //ctx->selected_history_index = 0; + if(app->save_filename) { + free(app->save_filename); + app->save_filename = NULL; + }; ctx->state = DecodeStateShowHistory; view_dispatcher_send_custom_event( app->view_dispatcher, ProtoPirateCustomEventSubDecodeUpdate);