Use g_return_*() function to avoid programming issues.
authorDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 15:53:24 +0000 (17:53 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 15:53:24 +0000 (17:53 +0200)
src/ex.c
src/handlers.c
src/hints.c
src/history.c
src/input.c
src/js.c
src/map.c
src/mode.c

index a4fa0f1..4ec27bc 100644 (file)
--- 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)
index b89fd49..4b049ba 100644 (file)
@@ -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))) {
index 9616550..eb22475 100644 (file)
@@ -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);
index e3272ec..149c1c6 100644 (file)
@@ -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) {
index 56f135c..7aa166a 100644 (file)
@@ -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;
     }
index 3bc3a49..74d025e 100644 (file)
--- 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);
index f04cceb..e066d7d 100644 (file)
--- 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);
 }
 
 /**
index 7d6d074..ed60ff8 100644 (file)
@@ -22,6 +22,7 @@
 #include "mode.h"
 #include "normal.h"
 #include "ascii.h"
+#include <glib.h>
 
 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 */