From 9868844f7f4d7c4fca164be610ef8f010a1255ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 24 May 2018 11:21:59 +0200 Subject: Fix cppcheck warnings --- c_src/sdl_keyboard.c | 3 +-- c_src/sdl_rect.c | 2 +- c_src/sdl_video.c | 1 + c_src/sdl_window.c | 24 +++++++++++++----------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/c_src/sdl_keyboard.c b/c_src/sdl_keyboard.c index d4b4233..c46cc75 100644 --- a/c_src/sdl_keyboard.c +++ b/c_src/sdl_keyboard.c @@ -282,9 +282,8 @@ NIF_CAST_HANDLER(thread_set_text_input_rect) NIF_FUNCTION(set_text_input_rect) { - SDL_Rect* rect = NULL; + SDL_Rect* rect = (SDL_Rect*)enif_alloc(sizeof(SDL_Rect)); - rect = (SDL_Rect*)enif_alloc(sizeof(SDL_Rect)); if (!map_to_rect(env, argv[0], rect)) { enif_free(rect); return enif_make_badarg(env); diff --git a/c_src/sdl_rect.c b/c_src/sdl_rect.c index ed42fdd..2bed2f4 100644 --- a/c_src/sdl_rect.c +++ b/c_src/sdl_rect.c @@ -92,7 +92,7 @@ ERL_NIF_TERM rect_to_map(ErlNifEnv* env, const SDL_Rect* rect) NIF_FUNCTION(enclose_points) { - SDL_Point* points = NULL; + SDL_Point* points; SDL_Rect clip, result; SDL_bool b; ERL_NIF_TERM list, head; diff --git a/c_src/sdl_video.c b/c_src/sdl_video.c index f14304b..4648ed1 100644 --- a/c_src/sdl_video.c +++ b/c_src/sdl_video.c @@ -68,6 +68,7 @@ NIF_CALL_HANDLER(thread_get_closest_display_mode) mode.w = (long)args[2]; mode.h = (long)args[3]; mode.refresh_rate = (long)args[4]; + mode.driverdata = NULL; if (!SDL_GetClosestDisplayMode((long)args[0], &mode, &closest)) return atom_undefined; diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c index d6c8a47..1c4f5a7 100644 --- a/c_src/sdl_window.c +++ b/c_src/sdl_window.c @@ -735,6 +735,7 @@ NIF_CALL_HANDLER(thread_set_window_display_mode) mode.w = (long)args[2]; mode.h = (long)args[3]; mode.refresh_rate = (long)args[4]; + mode.driverdata = NULL; if (SDL_SetWindowDisplayMode(args[0], &mode)) return sdl_error_tuple(env); @@ -963,28 +964,29 @@ NIF_FUNCTION(set_window_hit_test) { void* window_res; unsigned int module_len, function_len; - char *module = NULL, *function = NULL; + char *module, *function; BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res)); BADARG_IF(!enif_get_atom_length(env, argv[1], &module_len, ERL_NIF_LATIN1)); BADARG_IF(!enif_get_atom_length(env, argv[2], &function_len, ERL_NIF_LATIN1)); module = (char*)enif_alloc(module_len + 1); - if (!enif_get_atom(env, argv[1], module, module_len + 1, ERL_NIF_LATIN1)) - goto set_window_hit_test_badarg; + if (!enif_get_atom(env, argv[1], module, module_len + 1, ERL_NIF_LATIN1)) { + enif_free(module); + + return enif_make_badarg(env); + } function = (char*)enif_alloc(function_len + 1); - if (!enif_get_atom(env, argv[2], function, function_len + 1, ERL_NIF_LATIN1)) - goto set_window_hit_test_badarg; + if (!enif_get_atom(env, argv[2], function, function_len + 1, ERL_NIF_LATIN1)) { + enif_free(module); + enif_free(function); + + return enif_make_badarg(env); + } return nif_thread_call(env, thread_set_window_hit_test, 3, NIF_RES_GET(Window, window_res), module, function); - -set_window_hit_test_badarg: - enif_free(module); - enif_free(function); - - return enif_make_badarg(env); } // set_window_hit_test_remove -- cgit v1.2.3