From 6e2bea3b38918c9137b52dbfe88478840a6b49cd Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 13 Jun 2015 01:18:13 +0200 Subject: [PATCH] (Audio/gfx) Cleanups --- audio/audio_driver.c | 3 +- audio/audio_dsp_filter.c | 9 ++-- audio/audio_resampler_driver.c | 3 +- gfx/common/x11_common.c | 4 +- gfx/video_filter.c | 9 ++-- gfx/video_shader_parse.c | 91 ++++++++++++++++++++-------------- gfx/video_state_python.c | 9 ++-- 7 files changed, 77 insertions(+), 51 deletions(-) diff --git a/audio/audio_driver.c b/audio/audio_driver.c index 95a5c0214e..5479f84db5 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -230,7 +230,7 @@ const char* config_get_audio_driver_options(void) { union string_list_elem_attr attr; unsigned i; - char *options = NULL; + char *options = NULL; int options_len = 0; struct string_list *options_l = string_list_new(); @@ -242,6 +242,7 @@ const char* config_get_audio_driver_options(void) for (i = 0; audio_driver_find_handle(i); i++) { const char *opt = audio_driver_find_ident(i); + options_len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } diff --git a/audio/audio_dsp_filter.c b/audio/audio_dsp_filter.c index 68b5d1ae25..9854501c36 100644 --- a/audio/audio_dsp_filter.c +++ b/audio/audio_dsp_filter.c @@ -95,8 +95,9 @@ static bool create_filter_graph(rarch_dsp_filter_t *dsp, float sample_rate) for (i = 0; i < filters; i++) { - char key[64], name[64]; struct config_file_userdata userdata; + char key[64] = {0}; + char name[64] = {0}; struct dspfilter_info info = { sample_rate }; snprintf(key, sizeof(key), "filter%u", i); @@ -222,9 +223,9 @@ static bool append_plugs(rarch_dsp_filter_t *dsp, struct string_list *list) rarch_dsp_filter_t *rarch_dsp_filter_new( const char *filter_config, float sample_rate) { - char basedir[PATH_MAX_LENGTH]; - struct string_list *plugs = NULL; - rarch_dsp_filter_t *dsp = NULL; + char basedir[PATH_MAX_LENGTH] = {0}; + struct string_list *plugs = NULL; + rarch_dsp_filter_t *dsp = NULL; (void)basedir; diff --git a/audio/audio_resampler_driver.c b/audio/audio_resampler_driver.c index 9a70be6ffe..c483104f85 100644 --- a/audio/audio_resampler_driver.c +++ b/audio/audio_resampler_driver.c @@ -101,7 +101,7 @@ const char* config_get_audio_resampler_driver_options(void) { union string_list_elem_attr attr; unsigned i; - char *options = NULL; + char *options = NULL; int options_len = 0; struct string_list *options_l = string_list_new(); @@ -113,6 +113,7 @@ const char* config_get_audio_resampler_driver_options(void) for (i = 0; resampler_drivers[i]; i++) { const char *opt = resampler_drivers[i]->ident; + options_len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index f4dd8c09f7..3b3bf1c2c8 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -26,11 +26,11 @@ static void x11_hide_mouse(Display *dpy, Window win) { static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0}; - Cursor no_ptr; Pixmap bm_no; XColor black, dummy; Colormap colormap = DefaultColormap(dpy, DefaultScreen(dpy)); + if (!XAllocNamedColor(dpy, colormap, "black", &black, &dummy)) return; @@ -124,7 +124,7 @@ void x11_set_window_attr(Display *dpy, Window win) void x11_suspend_screensaver(Window wnd) { int ret; - char cmd[64]; + char cmd[64] = {0}; RARCH_LOG("Suspending screensaver (X11).\n"); diff --git a/gfx/video_filter.c b/gfx/video_filter.c index c17cb062ea..5df658891f 100644 --- a/gfx/video_filter.c +++ b/gfx/video_filter.c @@ -125,8 +125,9 @@ static bool create_softfilter_graph(rarch_softfilter_t *filt, unsigned threads) { unsigned input_fmts, input_fmt, output_fmts, i; - char key[64], name[64]; struct config_file_userdata userdata; + char key[64] = {0}; + char name[64] = {0}; snprintf(key, sizeof(key), "filter"); @@ -374,10 +375,10 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_config, enum retro_pixel_format in_pixel_format, unsigned max_width, unsigned max_height) { - char basedir[PATH_MAX_LENGTH]; softfilter_simd_mask_t cpu_features = rarch_get_cpu_features(); - struct string_list *plugs = NULL; - rarch_softfilter_t *filt = NULL; + char basedir[PATH_MAX_LENGTH] = {0}; + struct string_list *plugs = NULL; + rarch_softfilter_t *filt = NULL; (void)basedir; diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index d6295454e3..70ef7214d6 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -84,17 +84,25 @@ static enum gfx_wrap_type wrap_str_to_mode(const char *wrap_mode) **/ static bool video_shader_parse_pass(config_file_t *conf, struct video_shader_pass *pass, unsigned i) { - char shader_name[64], filter_name_buf[64], wrap_name_buf[64], wrap_mode[64]; - char frame_count_mod_buf[64], srgb_output_buf[64], fp_fbo_buf[64]; - char mipmap_buf[64], alias_buf[64], scale_name_buf[64], attr_name_buf[64]; - char scale_type[64] = {0}; - char scale_type_x[64] = {0}; - char scale_type_y[64] = {0}; - char frame_count_mod[64] = {0}; - struct gfx_fbo_scale *scale = NULL; - bool smooth = false; - float fattr = 0.0f; - int iattr = 0; + char shader_name[64] = {0}; + char filter_name_buf[64] = {0}; + char wrap_name_buf[64] = {0}; + char wrap_mode[64] = {0}; + char frame_count_mod_buf[64] = {0}; + char srgb_output_buf[64] = {0}; + char fp_fbo_buf[64] = {0}; + char mipmap_buf[64] = {0}; + char alias_buf[64] = {0}; + char scale_name_buf[64] = {0}; + char attr_name_buf[64] = {0}; + char scale_type[64] = {0}; + char scale_type_x[64] = {0}; + char scale_type_y[64] = {0}; + char frame_count_mod[64] = {0}; + struct gfx_fbo_scale *scale = NULL; + bool smooth = false; + float fattr = 0.0f; + int iattr = 0; /* Source */ snprintf(shader_name, sizeof(shader_name), "shader%u", i); @@ -255,9 +263,9 @@ static bool video_shader_parse_pass(config_file_t *conf, struct video_shader_pas static bool video_shader_parse_textures(config_file_t *conf, struct video_shader *shader) { - const char *id; - char *save; - char textures[1024]; + const char *id = NULL; + char *save = NULL; + char textures[1024] = {0}; if (!config_get_array(conf, "textures", textures, sizeof(textures))) return true; @@ -266,10 +274,12 @@ static bool video_shader_parse_textures(config_file_t *conf, id && shader->luts < GFX_MAX_TEXTURES; shader->luts++, id = strtok_r(NULL, ";", &save)) { - char id_filter[64], id_wrap[64], wrap_mode[64]; - char id_mipmap[64]; - bool mipmap = false; - bool smooth = false; + char id_filter[64] = {0}; + char id_wrap[64] = {0}; + char wrap_mode[64] = {0}; + char id_mipmap[64] = {0}; + bool mipmap = false; + bool smooth = false; if (!config_get_array(conf, id, shader->lut[shader->luts].path, sizeof(shader->lut[shader->luts].path))) @@ -349,7 +359,7 @@ bool video_shader_resolve_parameters(config_file_t *conf, for (i = 0; i < shader->passes; i++) { - char line[4096]; + char line[4096] = {0}; FILE *file = fopen(shader->pass[i].source.path, "r"); if (!file) @@ -387,9 +397,9 @@ bool video_shader_resolve_parameters(config_file_t *conf, if (conf) { /* Read in parameters which override the defaults. */ - char parameters[4096]; - const char *id; - char *save = NULL; + char parameters[4096] = {0}; + const char *id = NULL; + char *save = NULL; if (!config_get_array(conf, "parameters", parameters, sizeof(parameters))) @@ -427,9 +437,9 @@ bool video_shader_resolve_parameters(config_file_t *conf, static bool video_shader_parse_imports(config_file_t *conf, struct video_shader *shader) { - char imports[1024]; - const char *id; - char *save = NULL; + const char *id = NULL; + char *save = NULL; + char imports[1024] = {0}; if (!config_get_array(conf, "imports", imports, sizeof(imports))) return true; @@ -438,9 +448,15 @@ static bool video_shader_parse_imports(config_file_t *conf, id && shader->variables < GFX_MAX_VARIABLES; shader->variables++, id = strtok_r(NULL, ";", &save)) { - char semantic_buf[64], wram_buf[64], input_slot_buf[64]; - char mask_buf[64], equal_buf[64], semantic[64]; - unsigned addr = 0, mask = 0, equal = 0; + char semantic_buf[64] = {0}; + char wram_buf[64] = {0}; + char input_slot_buf[64] = {0}; + char mask_buf[64] = {0}; + char equal_buf[64] = {0}; + char semantic[64] = {0}; + unsigned addr = 0; + unsigned mask = 0; + unsigned equal = 0; struct state_tracker_uniform_info *var = (struct state_tracker_uniform_info*) &shader->variable[shader->variables]; @@ -589,7 +605,7 @@ static const char *scale_type_to_str(enum gfx_scale_type type) static void shader_write_scale_dim(config_file_t *conf, const char *dim, enum gfx_scale_type type, float scale, unsigned absolute, unsigned i) { - char key[64]; + char key[64] = {0}; snprintf(key, sizeof(key), "scale_type_%s%u", dim, i); config_set_string(conf, key, scale_type_to_str(type)); @@ -604,7 +620,7 @@ static void shader_write_scale_dim(config_file_t *conf, const char *dim, static void shader_write_fbo(config_file_t *conf, const struct gfx_fbo_scale *fbo, unsigned i) { - char key[64]; + char key[64] = {0}; snprintf(key, sizeof(key), "float_framebuffer%u", i); config_set_bool(conf, key, fbo->fp_fbo); @@ -658,9 +674,12 @@ static const char *import_semantic_to_str(enum state_tracker_type type) static void shader_write_variable(config_file_t *conf, const struct state_tracker_uniform_info *info) { - char semantic_buf[64], wram_buf[64], input_slot_buf[64]; - char mask_buf[64], equal_buf[64]; - const char *id = info->id; + char semantic_buf[64] = {0}; + char wram_buf[64] = {0}; + char input_slot_buf[64] = {0}; + char mask_buf[64] = {0}; + char equal_buf[64] = {0}; + const char *id = info->id; snprintf(semantic_buf, sizeof(semantic_buf), "%s_semantic", id); snprintf(wram_buf, sizeof(wram_buf), "%s_wram", id); @@ -709,7 +728,7 @@ void video_shader_write_conf_cgp(config_file_t *conf, for (i = 0; i < shader->passes; i++) { - char key[64]; + char key[64] = {0}; const struct video_shader_pass *pass = &shader->pass[i]; snprintf(key, sizeof(key), "shader%u", i); @@ -775,7 +794,7 @@ void video_shader_write_conf_cgp(config_file_t *conf, for (i = 0; i < shader->luts; i++) { - char key[64]; + char key[64] = {0}; config_set_string(conf, shader->lut[i].id, shader->lut[i].path); @@ -859,7 +878,7 @@ void video_shader_resolve_relative(struct video_shader *shader, const char *ref_path) { unsigned i; - char tmp_path[4096]; + char tmp_path[4096] = {0}; for (i = 0; i < shader->passes; i++) { diff --git a/gfx/video_state_python.c b/gfx/video_state_python.c index 95b491f150..4fffcaf128 100644 --- a/gfx/video_state_python.c +++ b/gfx/video_state_python.c @@ -235,6 +235,7 @@ static char *dupe_newline(const char *str) { unsigned size; char *ret = NULL; + if (!str) return NULL; @@ -253,9 +254,11 @@ static char *dupe_newline(const char *str) static char *align_program(const char *program) { size_t prog_size; - char *new_prog = NULL, *save = NULL, *line; + char *new_prog = NULL; + char *save = NULL; + char *line = NULL; unsigned skip_chars = 0; - char *prog = strdup(program); + char *prog = strdup(program); if (!prog) return NULL; @@ -391,7 +394,7 @@ float py_state_get(py_state_t *handle, const char *id, { unsigned i; float retval; - PyObject *ret = NULL; + PyObject *ret = NULL; settings_t *settings = config_get_ptr(); for (i = 0; i < MAX_USERS; i++)