From 9878226e4dec1ee7bb1434249214d6d8161b439f Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 20 Oct 2021 16:05:21 -0400 Subject: filetree.c move static and stack allocated buffers around it makes more sense to make the main buffer static and make the second (infrequently needed) buffer as stack allocated Change-Id: Ide7c1a7a312124e47a23ed0ab75a90d7b8be982e --- apps/filetree.c | 21 ++++++++++++--------- apps/filetypes.c | 9 ++++----- apps/filetypes.h | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) (limited to 'apps') diff --git a/apps/filetree.c b/apps/filetree.c index 5c6443cc34..66e4a68398 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -435,7 +435,8 @@ static void ft_load_font(char *file) int ft_enter(struct tree_context* c) { int rc = GO_TO_PREVIOUS; - char buf[MAX_PATH]; + static char buf[MAX_PATH]; + struct entry* file = tree_get_entry_at(c, c->selected_item); if (!file) { @@ -634,17 +635,18 @@ int ft_enter(struct tree_context* c) case FILE_ATTR_LUA: case FILE_ATTR_OPX: { - char *plugin = buf, *argument = NULL, lua_path[MAX_PATH]; + char *plugin = buf, *argument = NULL; + char plugin_path[MAX_PATH]; int ret; if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_LUA) { - snprintf(lua_path, sizeof(lua_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ - plugin = lua_path; + snprintf(plugin_path, sizeof(plugin_path)-1, "%s/lua.rock", VIEWERS_DIR); /* Use a #define here ? */ + plugin = plugin_path; argument = buf; } else if ((file_attr & FILE_ATTR_MASK) == FILE_ATTR_OPX) { - snprintf(lua_path, sizeof(lua_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */ - plugin = lua_path; + snprintf(plugin_path, sizeof(plugin_path)-1, "%s/open_plugins.rock", VIEWERS_DIR); /* Use a #define here ? */ + plugin = plugin_path; argument = buf; } @@ -685,7 +687,8 @@ int ft_enter(struct tree_context* c) default: { const char* plugin; - + char plugin_path[MAX_PATH]; + const char *argument = buf; if (global_settings.party_mode && audio_status()) { splash(HZ, ID2P(LANG_PARTY_MODE)); break; @@ -698,10 +701,10 @@ int ft_enter(struct tree_context* c) return rc; } - plugin = filetype_get_plugin(file); + plugin = filetype_get_plugin(file, plugin_path, sizeof(plugin_path)); if (plugin) { - switch (plugin_load(plugin,buf)) + switch (plugin_load(plugin, argument)) { case PLUGIN_USB_CONNECTED: rc = GO_TO_FILEBROWSER; diff --git a/apps/filetypes.c b/apps/filetypes.c index 530ab18683..3724f57a9b 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -531,17 +531,16 @@ int filetype_get_icon(int attr) return filetypes[index].icon; } -char* filetype_get_plugin(const struct entry* file) +char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len) { - static char plugin_name[MAX_PATH]; int index = find_attr(file->attr); - if (index < 0) + if (index < 0 || !buffer) return NULL; if (filetypes[index].plugin == NULL) return NULL; - snprintf(plugin_name, MAX_PATH, "%s/%s.%s", + snprintf(buffer, buffer_len, "%s/%s.%s", PLUGIN_DIR, filetypes[index].plugin, ROCK_EXTENSION); - return plugin_name; + return buffer; } bool filetype_supported(int attr) diff --git a/apps/filetypes.h b/apps/filetypes.h index 23f259b3ca..efe9f3f5df 100644 --- a/apps/filetypes.h +++ b/apps/filetypes.h @@ -73,7 +73,7 @@ int filetype_get_color(const char* name, int attr); #endif int filetype_get_icon(int attr); /* return the plugin filename associated with the file */ -char* filetype_get_plugin(const struct entry* file); +char* filetype_get_plugin(const struct entry* file, char *buffer, size_t buffer_len); /* returns true if the attr is supported */ bool filetype_supported(int attr); -- cgit v1.2.3