From: Daniel Carl Date: Tue, 3 Jun 2014 15:53:24 +0000 (+0200) Subject: Use g_return_*() function to avoid programming issues. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=b0eb2fcb259752919ae62efbc629d5e26f5ba12b;p=vimb.git Use g_return_*() function to avoid programming issues. --- diff --git a/src/ex.c b/src/ex.c index a4fa0f1..4ec27bc 100644 --- a/src/ex.c +++ b/src/ex.c @@ -329,7 +329,7 @@ VbResult ex_keypress(int key) default: /* if is printable ascii char, than write it at the cursor - * position into input box */ + * position into input box */ if (key >= 0x20 && key <= 0x7e) { gtk_text_buffer_insert_at_cursor(buffer, (char[2]){key, 0}, 1); } else { @@ -821,9 +821,8 @@ static gboolean ex_open(const ExArg *arg) { if (arg->code == EX_TABOPEN) { return vb_load_uri(&((Arg){VB_TARGET_NEW, arg->rhs->str})); - } else { - return vb_load_uri(&((Arg){VB_TARGET_CURRENT, arg->rhs->str})); } + return vb_load_uri(&((Arg){VB_TARGET_CURRENT, arg->rhs->str})); } #ifdef FEATURE_QUEUE @@ -875,7 +874,6 @@ static gboolean ex_save(const ExArg *arg) static gboolean ex_set(const ExArg *arg) { - gboolean success; char *param = NULL; if (!arg->rhs->len) { @@ -885,12 +883,10 @@ static gboolean ex_set(const ExArg *arg) /* split the input string into parameter and value part */ if ((param = strchr(arg->rhs->str, '='))) { *param++ = '\0'; - success = setting_run(arg->rhs->str, param ? param : NULL); - } else { - success = setting_run(arg->rhs->str, NULL); + return setting_run(arg->rhs->str, param ? param : NULL); } - return success; + return setting_run(arg->rhs->str, NULL); } static gboolean ex_shellcmd(const ExArg *arg) diff --git a/src/handlers.c b/src/handlers.c index b89fd49..4b049ba 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -54,9 +54,8 @@ gboolean handler_remove(const char *key) gboolean handle_uri(const char *uri) { - char *handler; + char *handler, *cmd; GError *error = NULL; - char *cmd; gboolean result; if (!(handler = handler_lookup(uri))) { diff --git a/src/hints.c b/src/hints.c index 9616550..eb22475 100644 --- a/src/hints.c +++ b/src/hints.c @@ -263,9 +263,7 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para { char *value = js_object_call_function(hints.ctx, hints.obj, func, count, params); - if (!value) { - return false; - } + g_return_val_if_fail(value != NULL, false); if (!strncmp(value, "ERROR:", 6)) { g_free(value); diff --git a/src/history.c b/src/history.c index e3272ec..149c1c6 100644 --- a/src/history.c +++ b/src/history.c @@ -22,6 +22,7 @@ #include "history.h" #include "util.h" #include "completion.h" +#include "ascii.h" extern VbCore vb; @@ -237,7 +238,7 @@ static History *line_to_history(const char *line) char **parts; int len; - while (g_ascii_isspace(*line)) { + while (VB_IS_SPACE(*line)) { line++; } if (!*line) { diff --git a/src/input.c b/src/input.c index 56f135c..7aa166a 100644 --- a/src/input.c +++ b/src/input.c @@ -83,7 +83,7 @@ VbResult input_open_editor(void) GPid pid; gboolean success; - if (!vb.config.editor_command) { + if (!vb.config.editor_command || !*vb.config.editor_command) { vb_echo(VB_MSG_ERROR, true, "No editor-command configured"); return RESULT_ERROR; } diff --git a/src/js.c b/src/js.c index 3bc3a49..74d025e 100644 --- a/src/js.c +++ b/src/js.c @@ -102,9 +102,7 @@ char* js_object_call_function(JSContextRef ctx, JSObjectRef obj, JSStringRef js_func = NULL; char *value; - if (!obj) { - return NULL; - } + g_return_val_if_fail(obj != NULL, NULL); js_func = JSStringCreateWithUTF8CString(func); if (!JSObjectHasProperty(ctx, obj, js_func)) { @@ -124,7 +122,7 @@ char* js_object_call_function(JSContextRef ctx, JSObjectRef obj, } /** - * Retrune a new allocates string for given valeu reference. + * Retrune a new allocates string for given value reference. * String must be freed if not used anymore. */ char* js_ref_to_string(JSContextRef ctx, JSValueRef ref) @@ -133,9 +131,7 @@ char* js_ref_to_string(JSContextRef ctx, JSValueRef ref) size_t len; JSStringRef str_ref; - if (!ref) { - return NULL; - } + g_return_val_if_fail(ref != NULL, NULL); str_ref = JSValueToStringCopy(ctx, ref, NULL); len = JSStringGetMaximumUTF8CStringSize(str_ref); diff --git a/src/map.c b/src/map.c index f04cceb..e066d7d 100644 --- a/src/map.c +++ b/src/map.c @@ -311,8 +311,7 @@ MapState map_handle_keys(const guchar *keys, int keylen, gboolean use_map) } } - /* should never be reached */ - return MAP_DONE; + g_return_val_if_reached(MAP_DONE); } /** diff --git a/src/mode.c b/src/mode.c index 7d6d074..ed60ff8 100644 --- a/src/mode.c +++ b/src/mode.c @@ -22,6 +22,7 @@ #include "mode.h" #include "normal.h" #include "ascii.h" +#include static GHashTable *modes = NULL; extern VbCore vb; @@ -62,10 +63,8 @@ void mode_add(char id, ModeTransitionFunc enter, ModeTransitionFunc leave, void mode_enter(char id) { Mode *new = g_hash_table_lookup(modes, GINT_TO_POINTER(id)); - if (!new) { - PRINT_DEBUG("!mode %c not found", id); - return; - } + + g_return_if_fail(new != NULL); if (vb.mode) { /* don't do anything if the mode isn't a new one */