From 02a5d738fe41b70ae3afa96907918202385bf93e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 28 Sep 2015 23:00:22 +0200 Subject: [PATCH] Static code analysis cleanups --- audio/librsound.c | 10 +++------- file_ops.c | 5 ++++- frontend/drivers/platform_linux.c | 5 +++-- frontend/drivers/platform_ps3.c | 24 +++++++++++------------- gfx/drivers_font_renderer/freetype.c | 2 +- input/drivers_joypad/parport_joypad.c | 4 ++-- input/input_autodetect.c | 3 ++- libretro-common/dynamic/dylib.c | 3 ++- libretro-common/net/net_http.c | 3 +-- libretro-db/testlib.c | 11 +++++++---- menu/cbs/menu_cbs_select.c | 9 ++++++--- menu/cbs/menu_cbs_title.c | 5 ----- menu/drivers/glui.c | 5 ++++- menu/menu_displaylist.c | 11 +++++++---- menu/menu_shader.c | 2 +- record/drivers/record_ffmpeg.c | 3 +-- tasks/task_database.c | 5 ++++- tasks/task_database_cue.c | 3 +-- 18 files changed, 60 insertions(+), 53 deletions(-) diff --git a/audio/librsound.c b/audio/librsound.c index 2f789c2dfd..ae29c279f4 100644 --- a/audio/librsound.c +++ b/audio/librsound.c @@ -465,7 +465,7 @@ static int rsnd_get_backend_info ( rsound_t *rd ) rd->backend_info.chunk_size = MAX_CHUNK_SIZE; /* Assumes a default buffer size should it cause problems of being too small */ - if ( rd->buffer_size <= 0 || rd->buffer_size < rd->backend_info.chunk_size * 2 ) + if ( rd->buffer_size == 0 || rd->buffer_size < rd->backend_info.chunk_size * 2 ) rd->buffer_size = rd->backend_info.chunk_size * 32; if ( rd->fifo_buffer != NULL ) @@ -1324,11 +1324,10 @@ size_t rsd_write( rsound_t *rsound, const void* buf, size_t size) while ( written < size ) { - size_t result; size_t write_size = (size - written) > max_write ? max_write : (size - written); - result = rsnd_fill_buffer(rsound, (const char*)buf + written, write_size); + size_t result = rsnd_fill_buffer(rsound, (const char*)buf + written, write_size); - if ( result <= 0 ) + if (result == 0) { rsd_stop(rsound); return 0; @@ -1347,10 +1346,7 @@ int rsd_start(rsound_t *rsound) assert(rsound->port != NULL); if ( rsnd_create_connection(rsound) < 0 ) - { return -1; - } - return 0; } diff --git a/file_ops.c b/file_ops.c index 4796c4113a..1b427a8786 100644 --- a/file_ops.c +++ b/file_ops.c @@ -658,7 +658,9 @@ int read_compressed_file(const char * path, void **buf, /* We split the string in two, by putting a \0, where the hash was: */ *archive_found = '\0'; archive_found += 1; +#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB) file_ext = path_get_extension(archive_path); +#endif #ifdef HAVE_7ZIP if (strcasecmp(file_ext,"7z") == 0) @@ -708,7 +710,9 @@ struct string_list *compressed_file_list_new(const char *path, const char* ext) { #ifdef HAVE_COMPRESSION +#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB) const char* file_ext = path_get_extension(path); +#endif #ifdef HAVE_7ZIP if (strcasecmp(file_ext,"7z") == 0) return compressed_7zip_file_list_new(path,ext); @@ -717,7 +721,6 @@ struct string_list *compressed_file_list_new(const char *path, if (strcasecmp(file_ext,"zip") == 0) return zlib_get_file_list(path, ext); #endif - #endif return NULL; } diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index db4ec7de82..847e2c7b55 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -1517,7 +1517,6 @@ static void frontend_linux_get_env(int *argc, { #ifdef ANDROID int32_t major, minor, rel; - int perms = 0; char device_model[PROP_VALUE_MAX] = {0}; char device_id[PROP_VALUE_MAX] = {0}; struct rarch_main_wrap *args = NULL; @@ -1525,7 +1524,6 @@ static void frontend_linux_get_env(int *argc, jobject obj = NULL; jstring jstr = NULL; struct android_app *android_app = (struct android_app*)data; - char buf[PATH_MAX_LENGTH] = {0}; if (!android_app) return; @@ -1749,6 +1747,7 @@ static void frontend_linux_get_env(int *argc, if (android_app->getStringExtra && jstr) { + int perms = 0; const char *argv = (*env)->GetStringUTFChars(env, jstr, 0); *app_dir = '\0'; @@ -1779,6 +1778,8 @@ static void frontend_linux_get_env(int *argc, RARCH_LOG("Application location: [%s].\n", app_dir); if (args && *app_dir) { + char buf[PATH_MAX_LENGTH]; + fill_pathname_join(g_defaults.dir.assets, app_dir, "assets", sizeof(g_defaults.dir.assets)); fill_pathname_join(g_defaults.dir.extraction, app_dir, diff --git a/frontend/drivers/platform_ps3.c b/frontend/drivers/platform_ps3.c index 3f933cf328..43b4faa9c9 100644 --- a/frontend/drivers/platform_ps3.c +++ b/frontend/drivers/platform_ps3.c @@ -116,7 +116,6 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], unsigned int get_attributes; CellGameContentSize size; char dirName[CELL_GAME_DIRNAME_SIZE] = {0}; - char contentInfoPath[PATH_MAX_LENGTH] = {0}; #ifdef HAVE_MULTIMAN /* not launched from external launcher, set default path */ @@ -169,6 +168,8 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], } else { + char content_info_path[PATH_MAX_LENGTH] = {0}; + RARCH_LOG("cellGameBootCheck() OK.\n"); RARCH_LOG("Directory name: [%s].\n", dirName); RARCH_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", @@ -188,14 +189,14 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], == CELL_GAME_ATTRIBUTE_APP_HOME) RARCH_LOG("RetroArch was launched from host machine (APP_HOME).\n"); - ret = cellGameContentPermit(contentInfoPath, g_defaults.dir.port); + ret = cellGameContentPermit(content_info_path, g_defaults.dir.port); #ifdef HAVE_MULTIMAN if (multiman_detected) { - fill_pathname_join(contentInfoPath, "/dev_hdd0/game/", - EMULATOR_CONTENT_DIR, sizeof(contentInfoPath)); - fill_pathname_join(g_defaults.dir.port, contentInfoPath, + fill_pathname_join(content_info_path, "/dev_hdd0/game/", + EMULATOR_CONTENT_DIR, sizeof(content_info_path)); + fill_pathname_join(g_defaults.dir.port, content_info_path, "USRDIR", sizeof(g_defaults.dir.port)); } #endif @@ -205,7 +206,7 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], else { RARCH_LOG("cellGameContentPermit() OK.\n"); - RARCH_LOG("contentInfoPath : [%s].\n", contentInfoPath); + RARCH_LOG("content_info_path : [%s].\n", content_info_path); RARCH_LOG("usrDirPath : [%s].\n", g_defaults.dir.port); } @@ -357,11 +358,6 @@ static int frontend_ps3_exec_exitspawn(const char *path, static void frontend_ps3_exec(const char *path, bool should_load_game) { - int ret = 0; - - (void)should_load_game; - (void)ret; - #ifndef IS_SALAMANDER global_t *global = global_get_ptr(); bool original_verbose = global->verbosity; @@ -369,6 +365,8 @@ static void frontend_ps3_exec(const char *path, bool should_load_game) global->verbosity = true; #endif + (void)should_load_game; + RARCH_LOG("Attempt to load executable: [%s].\n", path); #ifndef IS_SALAMANDER @@ -382,13 +380,13 @@ static void frontend_ps3_exec(const char *path, bool should_load_game) NULL }; - ret = frontend_ps3_exec_exitspawn(path, + frontend_ps3_exec_exitspawn(path, (const char** const)spawn_argv, NULL); } else #endif { - ret = frontend_ps3_exec_exitspawn(path, + frontend_ps3_exec_exitspawn(path, NULL, NULL); } diff --git a/gfx/drivers_font_renderer/freetype.c b/gfx/drivers_font_renderer/freetype.c index 190505b0db..9416b17c9e 100644 --- a/gfx/drivers_font_renderer/freetype.c +++ b/gfx/drivers_font_renderer/freetype.c @@ -131,7 +131,6 @@ static bool font_renderer_create_atlas(ft_font_renderer_t *handle) /* Blit our texture atlas. */ for (i = 0; i < FT_ATLAS_SIZE; i++) { - unsigned r, c; uint8_t *dst = NULL; unsigned offset_x = (i % FT_ATLAS_COLS) * max_width; unsigned offset_y = (i / FT_ATLAS_COLS) * max_height; @@ -144,6 +143,7 @@ static bool font_renderer_create_atlas(ft_font_renderer_t *handle) if (buffer[i]) { + unsigned r, c; const uint8_t *src = (const uint8_t*)buffer[i]; for (r = 0; r < handle->glyphs[i].height; diff --git a/input/drivers_joypad/parport_joypad.c b/input/drivers_joypad/parport_joypad.c index bebfb8930d..3806bb409a 100644 --- a/input/drivers_joypad/parport_joypad.c +++ b/input/drivers_joypad/parport_joypad.c @@ -310,14 +310,14 @@ static bool parport_joypad_init(void *data) static void parport_joypad_destroy(void) { unsigned i; - struct parport_joypad *pad = NULL; for (i = 0; i < MAX_USERS; i++) { - pad = (struct parport_joypad*)&parport_pads[i]; + struct parport_joypad *pad = (struct parport_joypad*)&parport_pads[i]; if (pad->fd >= 0) parport_free_pad(pad); } + memset(parport_pads, 0, sizeof(parport_pads)); for (i = 0; i < MAX_USERS; i++) parport_pads[i].fd = -1; diff --git a/input/input_autodetect.c b/input/input_autodetect.c index d5435fd3e3..7b83bdb2ee 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -191,7 +191,6 @@ static bool input_autoconfigure_joypad_from_conf_dir( config_file_t *conf = NULL; struct string_list *list = NULL; char path[PATH_MAX_LENGTH] = {0}; - char msg[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); fill_pathname_join(path,settings->input.autoconfig_dir, @@ -231,6 +230,8 @@ static bool input_autoconfigure_joypad_from_conf_dir( } else { + char msg[PATH_MAX_LENGTH]; + RARCH_LOG("Autodetect: no profiles found for %s (%d/%d)", params->name, params->vid, params->pid); snprintf(msg, sizeof(msg), "%s (%ld/%ld) not configured", params->name, (long)params->vid, (long)params->pid); rarch_main_msg_queue_push(msg, 0, 60, false); diff --git a/libretro-common/dynamic/dylib.c b/libretro-common/dynamic/dylib.c index 5bb6ec9c4c..2362f5a5f1 100644 --- a/libretro-common/dynamic/dylib.c +++ b/libretro-common/dynamic/dylib.c @@ -95,7 +95,6 @@ char *dylib_error(void) function_t dylib_proc(dylib_t lib, const char *proc) { function_t sym; - void *ptr_sym = NULL; #ifdef _WIN32 sym = (function_t)GetProcAddress(lib ? @@ -107,6 +106,8 @@ function_t dylib_proc(dylib_t lib, const char *proc) } last_dyn_error[0] = 0; #else + void *ptr_sym = NULL; + if (lib) ptr_sym = dlsym(lib, proc); else diff --git a/libretro-common/net/net_http.c b/libretro-common/net/net_http.c index ce3482b2ab..4e73a69107 100644 --- a/libretro-common/net/net_http.c +++ b/libretro-common/net/net_http.c @@ -194,8 +194,7 @@ error: if (conn->urlcopy) free(conn->urlcopy); conn->urlcopy = NULL; - if (conn) - free(conn); + free(conn); return NULL; } diff --git a/libretro-db/testlib.c b/libretro-db/testlib.c index 321885269b..30592f3489 100644 --- a/libretro-db/testlib.c +++ b/libretro-db/testlib.c @@ -103,7 +103,7 @@ static int create_db(lua_State *L) lua_error(L); } - rv = libretrodb_create(dst, &value_provider, L); + libretrodb_create(dst, &value_provider, L); retro_fclose(dst); return 0; @@ -168,8 +168,6 @@ static int db_cursor_open(lua_State *L) static int db_query(lua_State *L) { - int rv; - libretrodb_cursor_t *cursor = NULL; libretrodb_t *db = checkdb(L); const char *query = luaL_checkstring(L, -1); const char *error = NULL; @@ -183,7 +181,9 @@ static int db_query(lua_State *L) } else { - cursor = lua_newuserdata(L, sizeof(libretrodb_t)); + int rv; + libretrodb_cursor_t *cursor = lua_newuserdata(L, sizeof(libretrodb_t)); + if ((rv = libretrodb_cursor_open(db, cursor, q)) == 0) { luaL_getmetatable(L, "RarchDB.Cursor"); @@ -229,6 +229,9 @@ static int cursor_read(lua_State *L) static int cursor_iter(lua_State *L) { libretrodb_cursor_t *cursor = checkcursor(L); + + (void)cursor; + luaL_getmetafield(L, -1, "read"); lua_pushvalue(L, -2); return 2; diff --git a/menu/cbs/menu_cbs_select.c b/menu/cbs/menu_cbs_select.c index 714274b296..c347353a2d 100644 --- a/menu/cbs/menu_cbs_select.c +++ b/menu/cbs/menu_cbs_select.c @@ -32,6 +32,9 @@ static int action_select_default(const char *path, const char *label, unsigned t menu_entry_get(&entry, idx, NULL, false); cbs = menu_list_get_actiondata_at_offset(menu_list->selection_buf, idx); + + if (!cbs) + return -1; switch (menu_setting_get_type(cbs->setting)) { @@ -55,13 +58,13 @@ static int action_select_default(const char *path, const char *label, unsigned t if (action == MENU_ACTION_NOOP) { - if (cbs && cbs->action_ok) + if (cbs->action_ok) action = MENU_ACTION_OK; else { - if (cbs && cbs->action_start) + if (cbs->action_start) action = MENU_ACTION_START; - if (cbs && cbs->action_right) + if (cbs->action_right) action = MENU_ACTION_RIGHT; } } diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index 30ede0bfa5..6350fae9a3 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -131,17 +131,12 @@ static int action_get_title_generic(char *s, size_t len, const char *path, const char *text) { char elem0_path[PATH_MAX_LENGTH] = {0}; - char elem1_path[PATH_MAX_LENGTH] = {0}; struct string_list *list_path = string_split(path, "|"); if (list_path) { if (list_path->size > 0) - { strlcpy(elem0_path, list_path->elems[0].data, sizeof(elem0_path)); - if (list_path->size > 1) - strlcpy(elem1_path, list_path->elems[1].data, sizeof(elem1_path)); - } string_list_free(list_path); } diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 9efbd1d48a..b36813dca0 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -128,7 +128,6 @@ static void glui_draw_scrollbar(gl_t *gl, unsigned width, unsigned height, GRflo { unsigned header_height; float content_height, total_height, scrollbar_height, y; - int scrollbar_width = 4; glui_handle_t *glui = NULL; menu_handle_t *menu = menu_driver_get_ptr(); @@ -144,6 +143,9 @@ static void glui_draw_scrollbar(gl_t *gl, unsigned width, unsigned height, GRflo y = total_height * menu->scroll_y / content_height; if (content_height >= total_height) + { + int scrollbar_width = 4; + glui_render_quad(gl, width - scrollbar_width, header_height + y, @@ -151,6 +153,7 @@ static void glui_draw_scrollbar(gl_t *gl, unsigned width, unsigned height, GRflo scrollbar_height, width, height, coord_color); + } } static void glui_get_message(const char *message) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 7e6890f38e..4dc9344945 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -77,13 +77,14 @@ static void print_buf_lines(file_list_t *list, char *buf, int buf_size, type, 0, 0); if (type == MENU_FILE_DOWNLOAD_CORE) { - char core_path[PATH_MAX_LENGTH]; - char display_name[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); if (settings) { + char core_path[PATH_MAX_LENGTH]; + char display_name[PATH_MAX_LENGTH] = {0}; char *last = NULL; + fill_pathname_join(core_path, settings->libretro_info_path, line_start, sizeof(core_path)); @@ -1549,7 +1550,7 @@ static void menu_displaylist_realloc_settings(menu_entries_t *entries, unsigned static int menu_setting_set_flags(rarch_setting_t *setting) { - enum setting_type setting_type = menu_setting_get_type(setting); + enum setting_type setting_type; uint64_t flags = menu_setting_get_flags(setting); if (!setting) return 0; @@ -1557,6 +1558,8 @@ static int menu_setting_set_flags(rarch_setting_t *setting) if (flags & SD_FLAG_IS_DRIVER) return MENU_SETTING_DRIVER; + setting_type = menu_setting_get_type(setting); + switch (setting_type) { case ST_ACTION: @@ -2791,7 +2794,7 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) core_info_list_get_supported_cores(global->core_info.list, menu->deferred_path, &core_info, &list_size); - if (list_size <= 0) + if (list_size == 0) { menu_list_push(info->list, menu_hash_to_str(MENU_LABEL_VALUE_NO_CORES_AVAILABLE), diff --git a/menu/menu_shader.c b/menu/menu_shader.c index 082c923ec1..08031bb3a2 100644 --- a/menu/menu_shader.c +++ b/menu/menu_shader.c @@ -35,7 +35,6 @@ void menu_shader_manager_init(menu_handle_t *menu) { #ifdef HAVE_SHADER_MANAGER uint32_t ext_hash; - char preset_path[PATH_MAX_LENGTH]; const char *ext = NULL; struct video_shader *shader = NULL; config_file_t *conf = NULL; @@ -99,6 +98,7 @@ void menu_shader_manager_init(menu_handle_t *menu) break; default: { + char preset_path[PATH_MAX_LENGTH]; const char *shader_dir = *settings->video.shader_dir ? settings->video.shader_dir : settings->system_directory; diff --git a/record/drivers/record_ffmpeg.c b/record/drivers/record_ffmpeg.c index 06ba016f12..f83df4b5ef 100644 --- a/record/drivers/record_ffmpeg.c +++ b/record/drivers/record_ffmpeg.c @@ -240,13 +240,13 @@ static void ffmpeg_audio_resolve_format(struct ff_audio_info *audio, static void ffmpeg_audio_resolve_sample_rate(ffmpeg_t *handle, const AVCodec *codec) { - unsigned i; struct ff_config_param *params = &handle->config; struct ffemu_params *param = &handle->params; /* We'll have to force resampling to some supported sampling rate. */ if (codec->supported_samplerates && !params->sample_rate) { + unsigned i; int input_rate = (int)param->samplerate; /* Favor closest sampling rate, but always prefer ratio > 1.0. */ @@ -280,7 +280,6 @@ static bool ffmpeg_init_audio(ffmpeg_t *handle) settings_t *settings = config_get_ptr(); struct ff_config_param *params = &handle->config; struct ff_audio_info *audio = &handle->audio; - struct ff_video_info *video = &handle->video; struct ffemu_params *param = &handle->params; AVCodec *codec = avcodec_find_encoder_by_name( *params->acodec ? params->acodec : "flac"); diff --git a/tasks/task_database.c b/tasks/task_database.c index 44aaabab68..8f95d4f4ae 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -601,8 +601,11 @@ do_poll: void rarch_main_data_db_init_msg_queue(void) { db_handle_t *db = (db_handle_t*)db_ptr; + + if (!db) + return; - if (!db || !db->msg_queue) + if (!db->msg_queue) rarch_assert(db->msg_queue = msg_queue_new(8)); } diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index 9ed369d789..baec639ffe 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -50,14 +50,13 @@ static struct magic_entry MAGIC_NUMBERS[] = { static ssize_t get_token(RFILE *fd, char *token, size_t max_len) { - int rv; char *c = token; ssize_t len = 0; int in_string = 0; while (1) { - rv = retro_fread(fd, c, 1); + int rv = retro_fread(fd, c, 1); if (rv == 0) return 0;