(General) Cleanup

This commit is contained in:
twinaphex 2015-06-12 17:00:37 +02:00
parent e514c30d0f
commit c36e21ed13
12 changed files with 148 additions and 133 deletions

View File

@ -835,10 +835,11 @@ static void config_set_defaults(void)
**/
static config_file_t *open_default_config_file(void)
{
char conf_path[PATH_MAX_LENGTH], app_path[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
bool saved = false;
global_t *global = global_get_ptr();
char conf_path[PATH_MAX_LENGTH] = {0};
char app_path[PATH_MAX_LENGTH] = {0};
config_file_t *conf = NULL;
bool saved = false;
global_t *global = global_get_ptr();
(void)conf_path;
(void)app_path;
@ -961,9 +962,9 @@ static config_file_t *open_default_config_file(void)
{
if (home || xdg)
{
/* Try to create a new config file. */
char basedir[PATH_MAX_LENGTH] = {0};
char basedir[PATH_MAX_LENGTH];
/* Try to create a new config file. */
/* XDG_CONFIG_HOME falls back to $HOME/.config. */
if (xdg)
@ -982,7 +983,8 @@ static config_file_t *open_default_config_file(void)
if (path_mkdir(basedir))
{
char skeleton_conf[PATH_MAX_LENGTH];
char skeleton_conf[PATH_MAX_LENGTH] = {0};
fill_pathname_join(skeleton_conf, GLOBAL_CONFIG_DIR,
"retroarch.cfg", sizeof(skeleton_conf));
conf = config_file_new(skeleton_conf);
@ -1138,15 +1140,17 @@ static void config_file_dump_all(config_file_t *conf)
static bool config_load_file(const char *path, bool set_defaults)
{
unsigned i;
char *save, tmp_str[PATH_MAX_LENGTH];
char tmp_append_path[PATH_MAX_LENGTH]; /* Don't destroy append_config_path. */
const char *extra_path;
char *save = NULL;
const char *extra_path = NULL;
char tmp_str[PATH_MAX_LENGTH] = {0};
char tmp_append_path[PATH_MAX_LENGTH] = {0}; /* Don't destroy append_config_path. */
int vp_width = 0, vp_height = 0, vp_x = 0, vp_y = 0;
unsigned msg_color = 0;
config_file_t *conf = NULL;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
video_viewport_t *custom_vp = (video_viewport_t*)video_viewport_get_custom();
unsigned msg_color = 0;
config_file_t *conf = NULL;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
video_viewport_t *custom_vp = (video_viewport_t*)
video_viewport_get_custom();
if (path)
{
@ -1346,7 +1350,7 @@ static bool config_load_file(const char *path, bool set_defaults)
for (i = 0; i < MAX_USERS; i++)
{
char buf[64];
char buf[64] = {0};
snprintf(buf, sizeof(buf), "input_player%u_joypad_index", i + 1);
CONFIG_GET_INT_BASE(conf, settings, input.joypad_map[i], buf);
@ -1686,12 +1690,12 @@ static void config_load_core_specific(void)
if (settings->core_specific_config)
{
char tmp[PATH_MAX_LENGTH] = {0};
/* Toggle has_save_path to false so it resets */
global->has_set_save_path = false;
global->has_set_state_path = false;
/* Toggle has_save_path to false so it resets */
global->has_set_save_path = false;
global->has_set_state_path = false;
char tmp[PATH_MAX_LENGTH];
strlcpy(tmp, settings->libretro, sizeof(tmp));
RARCH_LOG("Loading core-specific config from: %s.\n",
global->core_specific_config_path);
@ -1706,9 +1710,9 @@ static void config_load_core_specific(void)
/* This must be true for core specific configs. */
settings->core_specific_config = true;
/* Reset save paths */
global->has_set_save_path = true;
global->has_set_state_path = true;
/* Reset save paths */
global->has_set_save_path = true;
global->has_set_state_path = true;
}
}
@ -1730,14 +1734,15 @@ static void config_load_core_specific(void)
*/
bool config_load_override(void)
{
char config_directory[PATH_MAX_LENGTH], /* path to the directory containing retroarch.cfg (prefix) */
core_path[PATH_MAX_LENGTH], /* final path for core-specific configuration (prefix+suffix) */
game_path[PATH_MAX_LENGTH]; /* final path for game-specific configuration (prefix+suffix) */
config_file_t *new_conf;
const char *core_name, *game_name; /* suffix */
bool should_append = false;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
char config_directory[PATH_MAX_LENGTH] = {0}; /* path to the directory containing retroarch.cfg (prefix) */
char core_path[PATH_MAX_LENGTH] = {0}; /* final path for core-specific configuration (prefix+suffix) */
char game_path[PATH_MAX_LENGTH] = {0}; /* final path for game-specific configuration (prefix+suffix) */
config_file_t *new_conf = NULL;
const char *core_name = NULL;
const char *game_name = NULL;
bool should_append = false;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
/* Early return in case a library isn't loaded */
if (!global->system.info.library_name || !strcmp(global->system.info.library_name,"No Core"))
@ -1822,7 +1827,7 @@ bool config_load_override(void)
/* Re-load the configuration with any overrides that might have been found */
if (should_append)
{
char buf[PATH_MAX_LENGTH];
char buf[PATH_MAX_LENGTH] = {0};
if (settings->core_specific_config)
{
@ -1912,13 +1917,14 @@ bool config_load_override(void)
*/
bool config_load_remap(void)
{
config_file_t *new_conf;
char remap_directory[PATH_MAX_LENGTH], /* path to the directory containing retroarch.cfg (prefix) */
core_path[PATH_MAX_LENGTH], /* final path for core-specific configuration (prefix+suffix) */
game_path[PATH_MAX_LENGTH]; /* final path for game-specific configuration (prefix+suffix) */
const char *core_name, *game_name; /* suffix */
global_t *global = global_get_ptr(); /* global pointer */
settings_t *settings = config_get_ptr(); /* config pointer */
config_file_t *new_conf = NULL;
const char *core_name = NULL;
const char *game_name = NULL;
char remap_directory[PATH_MAX_LENGTH] = {0}; /* path to the directory containing retroarch.cfg (prefix) */
char core_path[PATH_MAX_LENGTH] = {0}; /* final path for core-specific configuration (prefix+suffix) */
char game_path[PATH_MAX_LENGTH] = {0}; /* final path for game-specific configuration (prefix+suffix) */
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
/* Early return in case a library isn't loaded or remapping is disabled */
if (!global->system.info.library_name || !strcmp(global->system.info.library_name,"No Core"))
@ -2040,7 +2046,8 @@ static bool config_read_keybinds(const char *path)
static void save_keybind_key(config_file_t *conf, const char *prefix,
const char *base, const struct retro_keybind *bind)
{
char key[64], btn[64];
char key[64] = {0};
char btn[64] = {0};
snprintf(key, sizeof(key), "%s_%s", prefix, base);
input_keymaps_translate_rk_to_str(bind->key, btn, sizeof(btn));
@ -2050,9 +2057,9 @@ static void save_keybind_key(config_file_t *conf, const char *prefix,
static void save_keybind_hat(config_file_t *conf, const char *key,
const struct retro_keybind *bind)
{
char config[16];
unsigned hat = GET_HAT(bind->joykey);
const char *dir = NULL;
char config[16] = {0};
unsigned hat = GET_HAT(bind->joykey);
const char *dir = NULL;
switch (GET_HAT_DIR(bind->joykey))
{
@ -2083,7 +2090,8 @@ static void save_keybind_hat(config_file_t *conf, const char *key,
static void save_keybind_joykey(config_file_t *conf, const char *prefix,
const char *base, const struct retro_keybind *bind)
{
char key[64];
char key[64] = {0};
snprintf(key, sizeof(key), "%s_%s_btn", prefix, base);
if (bind->joykey == NO_BTN)
@ -2097,9 +2105,10 @@ static void save_keybind_joykey(config_file_t *conf, const char *prefix,
static void save_keybind_axis(config_file_t *conf, const char *prefix,
const char *base, const struct retro_keybind *bind)
{
char key[64], config[16];
unsigned axis = 0;
char dir = '\0';
char key[64] = {0};
char config[16] = {0};
unsigned axis = 0;
char dir = '\0';
snprintf(key, sizeof(key), "%s_%s_axis", prefix, base);
@ -2207,8 +2216,8 @@ void config_load(void)
**/
bool config_save_keybinds_file(const char *path)
{
unsigned i = 0;
bool ret = false;
unsigned i = 0;
bool ret = false;
config_file_t *conf = config_file_new(path);
if (!conf)
@ -2237,8 +2246,8 @@ bool config_save_keybinds_file(const char *path)
**/
bool config_save_file(const char *path)
{
unsigned i = 0;
bool ret = false;
unsigned i = 0;
bool ret = false;
config_file_t *conf = config_file_new(path);
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
@ -2544,7 +2553,7 @@ bool config_save_file(const char *path)
settings->input.keyboard_layout);
for (i = 0; i < MAX_USERS; i++)
{
char cfg[64];
char cfg[64] = {0};
snprintf(cfg, sizeof(cfg), "input_device_p%u", i + 1);
config_set_int(conf, cfg, settings->input.device[i]);

View File

@ -94,8 +94,9 @@ static bool read_content_file(unsigned i, const char *path, void **buf,
static void dump_to_file_desperate(const void *data,
size_t size, unsigned type)
{
char path[PATH_MAX_LENGTH], timebuf[PATH_MAX_LENGTH];
time_t time_;
char path[PATH_MAX_LENGTH] = {0};
char timebuf[PATH_MAX_LENGTH] = {0};
#if defined(_WIN32) && !defined(_XBOX)
const char *base = getenv("APPDATA");
#elif defined(__CELLOS_LV2__) || defined(_XBOX)
@ -142,8 +143,8 @@ struct sram_block
**/
bool save_state(const char *path)
{
bool ret = false;
void *data = NULL;
bool ret = false;
void *data = NULL;
size_t size = pretro_serialize_size();
RARCH_LOG("Saving state: \"%s\".\n", path);
@ -356,12 +357,13 @@ static bool load_content_need_fullpath(
bool need_fullpath, const char *path)
{
#ifdef HAVE_COMPRESSION
char new_path[PATH_MAX_LENGTH], new_basedir[PATH_MAX_LENGTH];
ssize_t len;
union string_list_elem_attr attributes;
bool ret = false;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
char new_path[PATH_MAX_LENGTH] = {0};
char new_basedir[PATH_MAX_LENGTH] = {0};
bool ret = false;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (global->system.info.block_extract)
return true;
@ -601,7 +603,7 @@ bool init_content_file(void)
if (ext && !strcasecmp(ext, "zip"))
{
char temporary_content[PATH_MAX_LENGTH];
char temporary_content[PATH_MAX_LENGTH] = {0};
strlcpy(temporary_content, content->elems[i].data,
sizeof(temporary_content));

View File

@ -390,7 +390,7 @@ static void load_symbols(bool is_dummy)
void libretro_get_current_core_pathname(char *name, size_t size)
{
size_t i;
const char *id = NULL;
const char *id = NULL;
struct retro_system_info info = {0};
if (size == 0)
@ -596,18 +596,19 @@ bool rarch_environment_cb(unsigned cmd, void *data)
core_option_free(global->system.core_options);
}
const struct retro_variable *vars =
(const struct retro_variable*)data;
const char *options_path = settings->core_options_path;
char buf[PATH_MAX_LENGTH];
if (!*options_path && *global->config_path)
{
fill_pathname_resolve_relative(buf, global->config_path,
"retroarch-core-options.cfg", sizeof(buf));
options_path = buf;
const struct retro_variable *vars = (const struct retro_variable*)data;
char buf[PATH_MAX_LENGTH] = {0};
const char *options_path = settings->core_options_path;
if (!*options_path && *global->config_path)
{
fill_pathname_resolve_relative(buf, global->config_path,
"retroarch-core-options.cfg", sizeof(buf));
options_path = buf;
}
global->system.core_options = core_option_new(options_path, vars);
}
global->system.core_options = core_option_new(options_path, vars);
break;
}

View File

@ -153,13 +153,13 @@ error:
int read_compressed_file(const char * path, void **buf,
const char* optional_filename, ssize_t *length)
{
const char* file_ext;
char archive_path[PATH_MAX_LENGTH], *archive_found = NULL;
const char* file_ext = NULL;
char *archive_found = NULL;
char archive_path[PATH_MAX_LENGTH] = {0};
if (optional_filename)
{
/* Safety check.
* If optional_filename and optional_filename
/* Safety check. * If optional_filename and optional_filename
* exists, we simply return 0,
* hoping that optional_filename is the
* same as requested.

View File

@ -96,7 +96,7 @@ void fill_pathname_expand_special(char *out_path,
)
{
size_t src_size;
char application_dir[PATH_MAX_LENGTH];
char application_dir[PATH_MAX_LENGTH] = {0};
fill_pathname_application_path(application_dir, sizeof(application_dir));
path_basedir(application_dir);
@ -119,8 +119,8 @@ void fill_pathname_abbreviate_special(char *out_path,
{
#if !defined(RARCH_CONSOLE)
unsigned i;
char application_dir[PATH_MAX_LENGTH];
const char *home = getenv("HOME");
char application_dir[PATH_MAX_LENGTH] = {0};
const char *home = getenv("HOME");
fill_pathname_application_path(application_dir, sizeof(application_dir));
path_basedir(application_dir);
@ -199,7 +199,7 @@ void fill_pathname_application_path(char *buf, size_t size)
#else
*buf = '\0';
pid_t pid = getpid();
char link_path[PATH_MAX_LENGTH];
char link_path[PATH_MAX_LENGTH] = {0};
/* Linux, BSD and Solaris paths. Not standardized. */
static const char *exts[] = { "exe", "file", "path/a.out" };
for (i = 0; i < ARRAY_SIZE(exts); i++)

View File

@ -575,8 +575,8 @@ static void log_connection(const struct sockaddr_storage *their_addr,
const struct sockaddr_in *v4;
const struct sockaddr_in6 *v6;
} u;
const char *str = NULL;
char buf_v4[INET_ADDRSTRLEN] = {0};
const char *str = NULL;
char buf_v4[INET_ADDRSTRLEN] = {0};
char buf_v6[INET6_ADDRSTRLEN] = {0};
u.storage = their_addr;
@ -610,7 +610,7 @@ static void log_connection(const struct sockaddr_storage *their_addr,
if (str)
{
char msg[512];
char msg[512] = {0};
snprintf(msg, sizeof(msg), "Got connection from: \"%s (%s)\" (#%u)",
nick, str, slot);
rarch_main_msg_queue_push(msg, 1, 180, false);
@ -679,10 +679,10 @@ end:
static bool init_tcp_socket(netplay_t *netplay, const char *server,
uint16_t port, bool spectate)
{
char port_buf[16];
bool ret = false;
char port_buf[16] = {0};
bool ret = false;
const struct addrinfo *tmp_info = NULL;
struct addrinfo hints, *res = NULL;
struct addrinfo hints, *res = NULL;
memset(&hints, 0, sizeof(hints));
@ -734,8 +734,8 @@ static bool init_tcp_socket(netplay_t *netplay, const char *server,
static bool init_udp_socket(netplay_t *netplay, const char *server,
uint16_t port)
{
char port_buf[16];
struct addrinfo hints;
char port_buf[16] = {0};
struct addrinfo hints = {0};
memset(&hints, 0, sizeof(hints));
#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY)

View File

@ -410,8 +410,9 @@ uint64_t rarch_get_cpu_features(void)
const unsigned MAX_FEATURES = \
sizeof(" MMX MMXEXT SSE SSE2 SSE3 SSSE3 SS4 SSE4.2 AES AVX AVX2 NEON VMX VMX128 VFPU PS");
char buf[MAX_FEATURES];
memset(buf, 0, MAX_FEATURES);
memset(buf, 0, MAX_FEATURES);
(void)flags;
#if defined(CPU_X86)

View File

@ -321,11 +321,11 @@ size_t content_playlist_size(content_playlist_t *playlist)
static bool content_playlist_read_file(
content_playlist_t *playlist, const char *path)
{
char buf[PLAYLIST_ENTRIES][1024];
unsigned i;
content_playlist_entry_t *entry = NULL;
char *last = NULL;
FILE *file = fopen(path, "r");
char buf[PLAYLIST_ENTRIES][1024] = {0};
content_playlist_entry_t *entry = NULL;
char *last = NULL;
FILE *file = fopen(path, "r");
/* If playlist file does not exist,
* create an empty playlist instead.

View File

@ -117,7 +117,7 @@ static void print_features(void)
**/
static void print_help(void)
{
char str[PATH_MAX_LENGTH];
char str[PATH_MAX_LENGTH] = {0};
puts("===================================================================");
#ifdef HAVE_GIT_VERSION
@ -840,8 +840,8 @@ static void rarch_init_savefile_paths(void)
}
else
{
char savefile_name_rtc[PATH_MAX_LENGTH];
union string_list_elem_attr attr;
char savefile_name_rtc[PATH_MAX_LENGTH] = {0};
attr.i = RETRO_MEMORY_SAVE_RAM;
string_list_append(global->savefiles, global->savefile_name, attr);
@ -1333,11 +1333,11 @@ void rarch_main_deinit(void)
**/
void rarch_playlist_load_content(void *data, unsigned idx)
{
const char *path = NULL;
const char *core_path = NULL;
const char *path = NULL;
const char *core_path = NULL;
content_playlist_t *playlist = (content_playlist_t*)data;
menu_handle_t *menu = menu_driver_get_ptr();
settings_t *settings = config_get_ptr();
menu_handle_t *menu = menu_driver_get_ptr();
settings_t *settings = config_get_ptr();
if (!playlist)
return;
@ -1375,11 +1375,11 @@ int rarch_defer_core(core_info_list_t *core_info, const char *dir,
const char *path, const char *menu_label,
char *s, size_t len)
{
char new_core_path[PATH_MAX_LENGTH];
const core_info_t *info = NULL;
size_t supported = 0;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
char new_core_path[PATH_MAX_LENGTH] = {0};
const core_info_t *info = NULL;
size_t supported = 0;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
fill_pathname_join(s, dir, path, len);

View File

@ -123,8 +123,8 @@ static void check_fast_forward_button(bool fastforward_pressed,
**/
static void check_stateslots(bool pressed_increase, bool pressed_decrease)
{
char msg[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
char msg[PATH_MAX_LENGTH] = {0};
settings_t *settings = config_get_ptr();
/* Save state slots */
if (pressed_increase)
@ -243,7 +243,8 @@ static void check_slowmotion(bool slowmotion_pressed)
static bool check_movie_init(void)
{
char path[PATH_MAX_LENGTH], msg[PATH_MAX_LENGTH];
char path[PATH_MAX_LENGTH] = {0};
char msg[PATH_MAX_LENGTH] = {0};
bool ret = true;
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
@ -353,8 +354,9 @@ static bool check_movie(void)
**/
static void check_shader_dir(bool pressed_next, bool pressed_prev)
{
char msg[PATH_MAX_LENGTH];
const char *shader = NULL, *ext = NULL;
char msg[PATH_MAX_LENGTH] = {0};
const char *shader = NULL;
const char *ext = NULL;
enum rarch_shader_type type = RARCH_SHADER_NONE;
global_t *global = global_get_ptr();

View File

@ -326,9 +326,9 @@ void rarch_main_data_msg_queue_push(unsigned type,
const char *msg, const char *msg2,
unsigned prio, unsigned duration, bool flush)
{
char new_msg[PATH_MAX_LENGTH];
msg_queue_t *queue = NULL;
data_runloop_t *runloop = rarch_main_data_get_ptr();
char new_msg[PATH_MAX_LENGTH] = {0};
msg_queue_t *queue = NULL;
data_runloop_t *runloop = rarch_main_data_get_ptr();
switch(type)
{

View File

@ -177,13 +177,13 @@ end:
static bool take_screenshot_viewport(void)
{
char screenshot_path[PATH_MAX_LENGTH];
const char *screenshot_dir = NULL;
uint8_t *buffer = NULL;
bool retval = false;
struct video_viewport vp = {0};
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
char screenshot_path[PATH_MAX_LENGTH] = {0};
const char *screenshot_dir = NULL;
uint8_t *buffer = NULL;
bool retval = false;
struct video_viewport vp = {0};
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
video_driver_viewport_info(&vp);
@ -222,11 +222,11 @@ static bool take_screenshot_raw(void)
{
unsigned width, height;
size_t pitch;
char screenshot_path[PATH_MAX_LENGTH];
global_t *global = global_get_ptr();
const void *data = NULL;
settings_t *settings = config_get_ptr();
const char *screenshot_dir = NULL;
char screenshot_path[PATH_MAX_LENGTH] = {0};
const void *data = NULL;
const char *screenshot_dir = NULL;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
video_driver_cached_frame_get(data, &width, &height, &pitch);
@ -254,9 +254,9 @@ static bool take_screenshot_raw(void)
**/
bool take_screenshot(void)
{
bool viewport_read = false;
bool ret = true;
const char *msg = NULL;
bool viewport_read = false;
bool ret = true;
const char *msg = NULL;
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
@ -343,13 +343,13 @@ bool take_screenshot(void)
bool screenshot_dump(const char *folder, const void *frame,
unsigned width, unsigned height, int pitch, bool bgr24)
{
char filename[PATH_MAX_LENGTH];
char shotname[PATH_MAX_LENGTH];
struct scaler_ctx scaler = {0};
FILE *file = NULL;
uint8_t *out_buffer = NULL;
bool ret = false;
driver_t *driver = driver_get_ptr();
char filename[PATH_MAX_LENGTH] = {0};
char shotname[PATH_MAX_LENGTH] = {0};
struct scaler_ctx scaler = {0};
FILE *file = NULL;
uint8_t *out_buffer = NULL;
bool ret = false;
driver_t *driver = driver_get_ptr();
(void)file;
(void)out_buffer;