[easytag] Use g_return_val_if_fail() for more invariants



commit 0d970246720420bc4281f5dc908043a3babd8af9
Author: David King <amigadave amigadave com>
Date:   Sat May 18 10:39:26 2013 +0100

    Use g_return_val_if_fail() for more invariants
    
    Found while looking through locations of "return NULL;".

 src/browser.c    |    3 +--
 src/charset.c    |    9 +++------
 src/id3_tag.c    |    4 ++--
 src/id3v24_tag.c |    3 +--
 src/misc.c       |    9 +++------
 src/scan.c       |    7 ++-----
 6 files changed, 12 insertions(+), 23 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 361c4b8..1cbd8ab 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -1627,8 +1627,7 @@ GtkTreePath *Browser_List_Select_File_By_Etfile2 (ET_File *searchETFile, gboolea
     ET_File *currentETFile;
     gboolean valid;
 
-     if (searchETFile == NULL)
-         return NULL;
+     g_return_val_if_fail (searchETFile != NULL, NULL);
 
     // If the path is used, we try the next item (to increase speed), as it is correct in many cases...
     if (startPath)
diff --git a/src/charset.c b/src/charset.c
index 8687f65..6d1bb15 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -252,8 +252,7 @@ get_encoding_from_locale (const char *locale)
     char lang[3];
     const char *encoding;
 
-    if (locale == NULL)
-        return NULL;
+    g_return_val_if_fail (locale != NULL, NULL);
 
     /* if locale includes encoding, use it *//*
     encoding = strchr (locale, '.');
@@ -443,8 +442,7 @@ gchar *convert_to_utf8 (const gchar *string)
     gchar *output;
     GError *error = NULL;
 
-    if (!string)
-        return NULL;
+    g_return_val_if_fail (string != NULL, NULL);
 
     output = g_locale_to_utf8(string, -1, NULL, NULL, &error);
 
@@ -643,8 +641,7 @@ gchar *Try_To_Validate_Utf8_String (const gchar *string)
     gchar *ret = NULL;
     GError *error = NULL;
 
-    if (!string)
-        return NULL;
+    g_return_val_if_fail (string != NULL, NULL);
 
     if (g_utf8_validate(string, -1, NULL))
     {
diff --git a/src/id3_tag.c b/src/id3_tag.c
index 349543a..eeaf2be 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -1179,8 +1179,8 @@ gchar *Id3tag_Rules_For_ISO_Fields (const gchar *string, const gchar *from_codes
 {
     gchar *string_converted = NULL;
 
-    if (!string || !from_codeset || !to_codeset)
-        return NULL;
+    g_return_val_if_fail (string != NULL && from_codeset != NULL
+                          && to_codeset != NULL, NULL);
 
     if (FILE_WRITING_ID3V1_ICONV_OPTIONS_NO)
     {
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index bef171d..4b7d6bf 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -1096,8 +1096,7 @@ Id3tag_find_and_create_frame (struct id3_tag *tag, const gchar *name)
 {
     struct id3_frame *frame;
 
-    if (!tag || !name || !*name)
-        return NULL;
+    g_return_val_if_fail (tag != NULL && name != NULL && *name != 0, NULL);
 
     frame = id3_tag_findframe(tag, name, 0);
     if (!frame)
diff --git a/src/misc.c b/src/misc.c
index d48593b..a7fc5e3 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -358,8 +358,7 @@ gchar *Get_Active_Combo_Box_Item (GtkComboBox *combo)
     GtkTreeIter iter;
     GtkTreeModel *model;
 
-    if (!combo)
-        return NULL;
+    g_return_val_if_fail (combo != NULL, NULL);
 
     model = gtk_combo_box_get_model(combo);
     if (!gtk_combo_box_get_active_iter(combo, &iter))
@@ -640,8 +639,7 @@ GtkWidget *Create_Xpm_Image (const char **xpm_name)
     GdkPixbuf *pixbuf;
     GtkWidget *image;
 
-    if (!*xpm_name)
-        return NULL;
+    g_return_val_if_fail (*xpm_name != NULL, NULL);
 
     pixbuf = gdk_pixbuf_new_from_xpm_data(xpm_name);
     image = gtk_image_new_from_pixbuf(GDK_PIXBUF(pixbuf));
@@ -999,8 +997,7 @@ gchar *Check_If_Executable_Exists (const gchar *program)
     gchar *program_tmp;
     gchar *tmp;
 
-    if (!program)
-        return NULL;
+    g_return_val_if_fail (program != NULL, NULL);
 
     program_tmp = g_strdup(program);
     g_strstrip(program_tmp);
diff --git a/src/scan.c b/src/scan.c
index f6ebb83..e2ae07f 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -1939,11 +1939,8 @@ int2roman_r (int num, char * str, size_t len)
    unsigned u;
    unsigned dividend;
 
-   // checks arguments
-   if (!str)
-   {
-      return NULL;
-   };
+   g_return_val_if_fail (str != NULL, NULL);
+
    // verify that number is withing boundaries
    if ((num > 5000) || (num < 0))
    {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]