From 39e9d5c5ba9e1f1f7a8ed9885ae2730e17245549 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 6 Dec 2015 13:28:20 +0100 Subject: [PATCH] Start cutting down on the size of some char local variables - we don't need PATH_MAX_LENGTH for everything --- command_event.c | 21 +++++++++++---------- driver.c | 2 +- dynamic.c | 10 +++++----- gfx/video_driver.c | 2 +- input/drivers_joypad/udev_joypad.c | 4 ++-- menu/drivers/materialui.c | 19 ++++++++----------- menu/drivers/xmb.c | 2 +- movie.c | 2 +- runloop.c | 5 +++-- screenshot.c | 2 +- 10 files changed, 34 insertions(+), 35 deletions(-) diff --git a/command_event.c b/command_event.c index 58c145bd52..c05447ed7c 100644 --- a/command_event.c +++ b/command_event.c @@ -96,7 +96,7 @@ static void event_save_files(void) **/ static void event_disk_control_set_eject(bool new_state, bool print_log) { - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; bool error = false; rarch_system_info_t *info = rarch_system_info_get_ptr(); const struct retro_disk_control_callback *control = @@ -155,11 +155,11 @@ static void event_check_disk_eject( static void event_disk_control_set_index(unsigned idx) { unsigned num_disks; - char msg[PATH_MAX_LENGTH] = {0}; + bool error = false; + char msg[128] = {0}; rarch_system_info_t *info = rarch_system_info_get_ptr(); const struct retro_disk_control_callback *control = info ? (const struct retro_disk_control_callback*)&info->disk_control : NULL; - bool error = false; if (!control || !control->get_num_images) return; @@ -209,7 +209,7 @@ static void event_disk_control_set_index(unsigned idx) void event_disk_control_append_image(const char *path) { unsigned new_idx; - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; struct retro_game_info info = {0}; global_t *global = global_get_ptr(); rarch_system_info_t *sysinfo = rarch_system_info_get_ptr(); @@ -333,7 +333,7 @@ static void event_check_disk_next( **/ static void event_set_volume(float gain) { - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; settings_t *settings = config_get_ptr(); settings->audio.volume += gain; @@ -466,7 +466,7 @@ static bool event_load_save_files(void) static void event_load_auto_state(void) { bool ret; - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; char savestate_name_auto[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); @@ -526,7 +526,7 @@ static void event_set_savestate_auto_index(void) for (i = 0; i < dir_list->size; i++) { unsigned idx; - char elem_base[PATH_MAX_LENGTH] = {0}; + char elem_base[128] = {0}; const char *end = NULL; const char *dir_elem = dir_list->elems[i].data; @@ -670,7 +670,7 @@ static bool event_save_core_config(void) char config_dir[PATH_MAX_LENGTH] = {0}; char config_name[PATH_MAX_LENGTH] = {0}; char config_path[PATH_MAX_LENGTH] = {0}; - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; bool ret = false; bool found_path = false; bool overrides_active = false; @@ -847,7 +847,7 @@ static void event_load_state(const char *path, char *s, size_t len) static void event_main_state(unsigned cmd) { char path[PATH_MAX_LENGTH] = {0}; - char msg[PATH_MAX_LENGTH] = {0}; + char msg[128] = {0}; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); @@ -933,9 +933,10 @@ bool event_command(enum event_command cmd) if (video_driver_get_video_output_size(&width, &height)) { + char msg[128] = {0}; + video_driver_set_video_mode(width, height, true); - char msg[PATH_MAX_LENGTH] = {0}; snprintf(msg, sizeof(msg),"Resolution: %dx%d",width, height); rarch_main_msg_queue_push(msg, 1, 100, true); } diff --git a/driver.c b/driver.c index c524570593..595025d320 100644 --- a/driver.c +++ b/driver.c @@ -139,7 +139,7 @@ static const void *find_driver_nonempty(const char *label, int i, int find_driver_index(const char * label, const char *drv) { unsigned i; - char str[PATH_MAX_LENGTH] = {0}; + char str[256]; const void *obj = NULL; for (i = 0; (obj = (const void*) diff --git a/dynamic.c b/dynamic.c index 6da5927f68..8b9da4a065 100644 --- a/dynamic.c +++ b/dynamic.c @@ -626,9 +626,9 @@ static bool rarch_game_specific_options(char **output) * Try config directory setting first, * fallback to the location of the current configuration file. */ if (settings->menu_config_directory[0] != '\0') - strlcpy(config_directory, settings->menu_config_directory, PATH_MAX_LENGTH); + strlcpy(config_directory, settings->menu_config_directory, sizeof(config_directory)); else if (global->path.config[0] != '\0') - fill_pathname_basedir(config_directory, global->path.config, PATH_MAX_LENGTH); + fill_pathname_basedir(config_directory, global->path.config, sizeof(config_directory)); else { RARCH_WARN("Per-Game Options: no config directory set\n"); @@ -636,9 +636,9 @@ static bool rarch_game_specific_options(char **output) } /* Concatenate strings into full paths for game_path */ - fill_pathname_join(game_path, config_directory, core_name, PATH_MAX_LENGTH); - fill_pathname_join(game_path, game_path, game_name, PATH_MAX_LENGTH); - strlcat(game_path, ".opt", PATH_MAX_LENGTH); + fill_pathname_join(game_path, config_directory, core_name, sizeof(game_path)); + fill_pathname_join(game_path, game_path, game_name, sizeof(game_path)); + strlcat(game_path, ".opt", sizeof(game_path)); option_file = config_file_new(game_path); if (!option_file) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 411ed15c1b..6a2a555a3a 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -927,7 +927,7 @@ void video_driver_set_size(unsigned *width, unsigned *height) **/ void video_monitor_set_refresh_rate(float hz) { - char msg[PATH_MAX_LENGTH]; + char msg[128]; settings_t *settings = config_get_ptr(); snprintf(msg, sizeof(msg), "Setting refresh rate to: %.3f Hz.", hz); diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index 7c2b2c5956..468265e471 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -70,7 +70,7 @@ struct udev_joypad uint16_t strength[2]; uint16_t configured_strength[2]; - char ident[PATH_MAX_LENGTH]; + char ident[256]; char *path; int32_t vid; int32_t pid; @@ -341,7 +341,7 @@ static void udev_check_device(struct udev_device *dev, const char *path, bool ho default: if (hotplugged) { - char msg[PATH_MAX_LENGTH] = {0}; + char msg[256]; snprintf(msg, sizeof(msg), "Device #%u (%s) connected.", pad, path); rarch_main_msg_queue_push(msg, 0, 60, false); diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 0699d0279d..e12314e528 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -484,15 +484,12 @@ static void mui_render_label_value(mui_handle_t *mui, { char label_str[PATH_MAX_LENGTH]; char value_str[PATH_MAX_LENGTH]; - int value_len = strlen(value); - int ticker_limit = 0; - size_t usable_width = 0; + int value_len = strlen(value); + int ticker_limit = 0; + size_t usable_width = 0; uintptr_t texture_switch = 0; - bool do_draw_text = false; - uint32_t hash_value = 0; - - label_str[0] = '\0'; - value_str[0] = '\0'; + bool do_draw_text = false; + uint32_t hash_value = 0; usable_width = width - (mui->margin * 2); @@ -728,9 +725,9 @@ static void mui_frame(void) 0, 0, 0, 0.2, }; unsigned width, height, ticker_limit, i; - char msg[PATH_MAX_LENGTH]; - char title[PATH_MAX_LENGTH]; - char title_buf[PATH_MAX_LENGTH]; + char msg[256]; + char title[256]; + char title_buf[256]; size_t selection; size_t title_margin; uint64_t *frame_count; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index e9b8860d50..09b91302c5 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -180,7 +180,7 @@ typedef struct xmb_handle } label; } margins; - char title_name[PATH_MAX_LENGTH]; + char title_name[256]; struct { diff --git a/movie.c b/movie.c index 2fcecfcb9a..dd726aac25 100644 --- a/movie.c +++ b/movie.c @@ -299,7 +299,7 @@ static void bsv_movie_init_state(void) } else if (bsv_movie_ctl(BSV_MOVIE_CTL_START_RECORDING, NULL)) { - char msg[PATH_MAX_LENGTH] = {0}; + char msg[256]; snprintf(msg, sizeof(msg), "%s \"%s\".", msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), diff --git a/runloop.c b/runloop.c index 06fc7a1838..b4abf8cc93 100644 --- a/runloop.c +++ b/runloop.c @@ -318,7 +318,7 @@ bool shader_dir_init(void) static void check_shader_dir(bool pressed_next, bool pressed_prev) { uint32_t ext_hash; - char msg[PATH_MAX_LENGTH]; + char msg[128]; const char *shader = NULL; const char *ext = NULL; enum rarch_shader_type type = RARCH_SHADER_NONE; @@ -636,7 +636,8 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL)) return false; { - char path[PATH_MAX_LENGTH], msg[PATH_MAX_LENGTH]; + char msg[128]; + char path[PATH_MAX_LENGTH]; settings->rewind_granularity = 1; diff --git a/screenshot.c b/screenshot.c index e22d37aac7..a9114243c7 100644 --- a/screenshot.c +++ b/screenshot.c @@ -57,7 +57,7 @@ static bool screenshot_dump(const char *folder, const void *frame, { bool ret; char filename[PATH_MAX_LENGTH] = {0}; - char shotname[PATH_MAX_LENGTH] = {0}; + char shotname[256] = {0}; struct scaler_ctx scaler = {0}; RFILE *file = NULL; uint8_t *out_buffer = NULL;