Rupert Swarbrick | 22 Dec 2010 13:06
Picon
Gravatar

[PATCH 00/14] Code cleanups

These patches fix all the warnings from gcc with -Wall and (the
meaningful ones) from cppcheck in the libyelp directory. (Except for
yelp-man-parser, but I've posted a separate patchset which deals with
that).

Frankly, you may not wish to apply fourteen teensy patches. So I've
bundled the lot together into one larger patch which I'm also sending
to the list - use either!

Rupert Swarbrick (14):
  Fix missing return value.
  Unused variable.
  Fix missing return values and typecast.
  Missing return values.
  Add typecasts and a header we use.
  Unused variable.
  Remove unused variables.
  Lots of typecasts and some unused variables.
  Missing return values.
  Unused variables.
  Unused variable.
  Remove unused variables and undefined functions!
  Fix missing return type and incorrect test (= not ==).
  Fix memory leaks found by cppcheck.

 libyelp/yelp-bookmarks.c        |    2 +-
 libyelp/yelp-bz2-decompressor.c |    1 -
 libyelp/yelp-docbook-document.c |    6 +++-
 libyelp/yelp-document.c         |   13 ++++++----
 libyelp/yelp-document.h         |    2 +-
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:18
Picon
Gravatar

[PATCH 01/14] Fix missing return value.

---
 libyelp/yelp-bookmarks.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libyelp/yelp-bookmarks.c b/libyelp/yelp-bookmarks.c
index 670650d..a8aeab1 100644
--- a/libyelp/yelp-bookmarks.c
+++ b/libyelp/yelp-bookmarks.c
 <at>  <at>  -83,7 +83,7  <at>  <at>  yelp_bookmarks_is_bookmarked (YelpBookmarks *bookmarks,
 {
     YelpBookmarksInterface *iface;

-    g_return_if_fail (YELP_IS_BOOKMARKS (bookmarks));
+    g_return_val_if_fail (YELP_IS_BOOKMARKS (bookmarks), FALSE);

     iface = YELP_BOOKMARKS_GET_INTERFACE (bookmarks);

--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:19
Picon
Gravatar

[PATCH 02/14] Unused variable.

---
 libyelp/yelp-bz2-decompressor.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/libyelp/yelp-bz2-decompressor.c b/libyelp/yelp-bz2-decompressor.c
index 98802ce..89dbe35 100644
--- a/libyelp/yelp-bz2-decompressor.c
+++ b/libyelp/yelp-bz2-decompressor.c
 <at>  <at>  -128,7 +128,6  <at>  <at>  yelp_bz2_decompressor_convert (GConverter *converter,
                                GError    **error)
 {
     YelpBz2Decompressor *decompressor;
-    gsize header_size;
     int res;

     decompressor = YELP_BZ2_DECOMPRESSOR (converter);
--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:22
Picon
Gravatar

[PATCH 03/14] Fix missing return values and typecast.

---
 libyelp/yelp-docbook-document.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libyelp/yelp-docbook-document.c b/libyelp/yelp-docbook-document.c
index b6a1d90..9863574 100644
--- a/libyelp/yelp-docbook-document.c
+++ b/libyelp/yelp-docbook-document.c
 <at>  <at>  -242,7 +242,7  <at>  <at>  docbook_request_page (YelpDocument         *document,
                                                                                 callback,
                                                                                 user_data);
     if (handled) {
-        return;
+        return TRUE;
     }

     g_mutex_lock (priv->mutex);
 <at>  <at>  -272,6 +272,8  <at>  <at>  docbook_request_page (YelpDocument         *document,
     }

     g_mutex_unlock (priv->mutex);
+
+    return FALSE;
 }

 /******************************************************************************/
 <at>  <at>  -356,7 +358,7  <at>  <at>  docbook_process (YelpDocbookDocument *docbook)
         id = xmlGetNsProp (priv->xmlcur, XML_XML_NAMESPACE, BAD_CAST "id");

     if (id) {
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:26
Picon
Gravatar

[PATCH 04/14] Missing return values.

Note this changes the return type of yelp_document_set_page_icon:
no-one was using a return and it wasn't returning anything helpful...
---
 libyelp/yelp-document.c |   13 ++++++++-----
 libyelp/yelp-document.h |    2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index 215586e..0ca6b24 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
 <at>  <at>  -205,6 +205,7  <at>  <at>  yelp_document_get_for_uri (YelpUri *uri)
     case YELP_URI_DOCUMENT_TYPE_NOT_FOUND:
     case YELP_URI_DOCUMENT_TYPE_EXTERNAL:
     case YELP_URI_DOCUMENT_TYPE_ERROR:
+    case YELP_URI_DOCUMENT_TYPE_UNRESOLVED:
         break;
     }

 <at>  <at>  -625,7 +626,7  <at>  <at>  yelp_document_get_page_icon (YelpDocument *document,
     return ret;
 }

-gchar *
+void
 yelp_document_set_page_icon (YelpDocument *document,
                              const gchar  *page_id,
                              const gchar  *icon)
 <at>  <at>  -646,8 +647,9  <at>  <at>  yelp_document_request_page (YelpDocument         *document,
 			    YelpDocumentCallback  callback,
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:32
Picon
Gravatar

[PATCH 05/14] Add typecasts and a header we use.

---
 libyelp/yelp-help-list.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libyelp/yelp-help-list.c b/libyelp/yelp-help-list.c
index 7b17798..f5b76ab 100644
--- a/libyelp/yelp-help-list.c
+++ b/libyelp/yelp-help-list.c
 <at>  <at>  -31,6 +31,7  <at>  <at> 
 #include <libxml/parser.h>
 #include <libxml/xinclude.h>
 #include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>

 #include "yelp-help-list.h"
 #include "yelp-settings.h"
 <at>  <at>  -131,15 +132,22  <at>  <at>  yelp_help_list_init (YelpHelpList *list)
                                            g_free,
                                            (GDestroyNotify) help_list_entry_free);

-    priv->get_docbook_title = xmlXPathCompile ("normalize-space("
+    priv->get_docbook_title = xmlXPathCompile (BAD_CAST
+                                               "normalize-space("
                                                "( /*/title | /*/db:title"
                                                "| /*/articleinfo/title"
                                                "| /*/bookinfo/title"
                                                "| /*/db:info/db:title"
                                                ")[1])");
-    priv->get_mallard_title = xmlXPathCompile
("normalize-space((/mal:page/mal:info/mal:title[ <at> type='text'] |"
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:36
Picon
Gravatar

[PATCH 06/14] Unused variable.

---
 libyelp/yelp-info-parser.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libyelp/yelp-info-parser.c b/libyelp/yelp-info-parser.c
index edd3812..3cc0443 100644
--- a/libyelp/yelp-info-parser.c
+++ b/libyelp/yelp-info-parser.c
 <at>  <at>  -1349,7 +1349,7  <at>  <at>  info_process_text_notes (xmlNodePtr *node, gchar *content, GtkTreeStore *tree)
   notes = g_regex_split_simple ("\\*[Nn]ote(?!_)", content, 0, 0);

   for (current = notes; *current != NULL; current++) {
-    gchar *url, **urls, **ulink;
+    gchar *url, **urls;
     gchar *append;
     gchar *alt_append, *alt_append1;
     gchar *link_text;
--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:38
Picon
Gravatar

[PATCH 07/14] Remove unused variables.

---
 libyelp/yelp-location-entry.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c
index defe05b..06e1995 100644
--- a/libyelp/yelp-location-entry.c
+++ b/libyelp/yelp-location-entry.c
 <at>  <at>  -879,7 +879,6  <at>  <at>  combo_box_row_separator_func (GtkTreeModel  *model,
                               GtkTreeIter   *iter,
                               gpointer       user_data)
 {
-    YelpLocationEntryPrivate *priv = GET_PRIV (user_data);
     gint flags;
     gtk_tree_model_get (model, iter,
                         HISTORY_COL_FLAGS, &flags,
 <at>  <at>  -905,7 +904,6  <at>  <at>  entry_focus_in_cb (GtkWidget     *widget,
                    GdkEventFocus *event,
                    gpointer       user_data)
 {
-    GtkEntry *text_entry = GTK_ENTRY (widget);
     YelpLocationEntryPrivate *priv = GET_PRIV (user_data);

     if (priv->enable_search && !priv->search_mode)
 <at>  <at>  -953,8 +951,6  <at>  <at>  entry_icon_press_cb (GtkEntry            *gtkentry,
                      GdkEvent            *event,
                      YelpLocationEntry   *entry)
 {
-    YelpLocationEntryPrivate *priv = GET_PRIV (entry);
-
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:48
Picon
Gravatar

[PATCH 10/14] Unused variables.

---
 libyelp/yelp-settings.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/libyelp/yelp-settings.c b/libyelp/yelp-settings.c
index b1f2f90..20a8faa 100644
--- a/libyelp/yelp-settings.c
+++ b/libyelp/yelp-settings.c
 <at>  <at>  -237,8 +237,6  <at>  <at>  yelp_settings_init (YelpSettings *settings)
 static void
 yelp_settings_dispose (GObject *object)
 {
-    YelpSettings *settings = YELP_SETTINGS (object);
-
     G_OBJECT_CLASS (yelp_settings_parent_class)->dispose (object);
 }

 <at>  <at>  -759,7 +757,6  <at>  <at>  gtk_theme_changed (GtkSettings  *gtk_settings,
     GdkColor   blue = { 0, 0x1E1E, 0x3E3E, 0xE7E7 };
     gdouble    base_h, base_s, base_v;
     gdouble    text_h, text_s, text_v;
-    gint i;

     g_mutex_lock (settings->priv->mutex);

--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:45
Picon
Gravatar

[PATCH 08/14] Lots of typecasts and some unused variables.

---
 libyelp/yelp-mallard-document.c |   47 ++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/libyelp/yelp-mallard-document.c b/libyelp/yelp-mallard-document.c
index 1bab124..f67bb97 100644
--- a/libyelp/yelp-mallard-document.c
+++ b/libyelp/yelp-mallard-document.c
 <at>  <at>  -162,7 +162,7  <at>  <at>  yelp_mallard_document_init (YelpMallardDocument *mallard)
     priv->pages_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
                                               NULL,
                                               (GDestroyNotify) mallard_page_data_free);
-    priv->normalize = xmlXPathCompile ("normalize-space(.)");
+    priv->normalize = xmlXPathCompile (BAD_CAST "normalize-space(.)");
 }

 static void
 <at>  <at>  -278,7 +278,6  <at>  <at>  mallard_think (YelpMallardDocument *mallard)
 {
     YelpMallardDocumentPrivate *priv = GET_PRIV (mallard);
     GError *error = NULL;
-    YelpDocument *document;
     gchar **search_path;
     gboolean editor_mode;

 <at>  <at>  -300,7 +299,7  <at>  <at>  mallard_think (YelpMallardDocument *mallard)
         error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND,
                              _("The directory ‘%s’ does not exist."),
                              search_path[0]);
-	yelp_document_error_pending ((YelpDocument *) document, error);
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:49
Picon
Gravatar

[PATCH 12/14] Remove unused variables and undefined functions!

---
 libyelp/yelp-transform.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)

diff --git a/libyelp/yelp-transform.c b/libyelp/yelp-transform.c
index eecfe6a..b9853b4 100644
--- a/libyelp/yelp-transform.c
+++ b/libyelp/yelp-transform.c
 <at>  <at>  -60,9 +60,6  <at>  <at>  static void      yelp_transform_set_property (GObject                 *object,
                                               GParamSpec              *pspec);

 static void      transform_run              (YelpTransform           *transform);
-static gboolean  transform_free             (YelpTransform           *transform);
-static void      transform_set_error        (YelpTransform           *transform,
-                                             YelpError               *error);

 static gboolean  transform_chunk            (YelpTransform           *transform);
 static gboolean  transform_error            (YelpTransform           *transform);
 <at>  <at>  -224,7 +221,6  <at>  <at>  static void
 yelp_transform_finalize (GObject *object)
 {
     YelpTransformPrivate *priv = GET_PRIV (object);
-    xsltDocumentPtr xsltdoc;
     GHashTableIter iter;
     gpointer chunk;

--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:48
Picon
Gravatar

[PATCH 11/14] Unused variable.

---
 libyelp/yelp-simple-document.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/libyelp/yelp-simple-document.c b/libyelp/yelp-simple-document.c
index de62a9b..aa466d5 100644
--- a/libyelp/yelp-simple-document.c
+++ b/libyelp/yelp-simple-document.c
 <at>  <at>  -390,8 +390,6  <at>  <at>  stream_close_cb (GInputStream       *stream,
 		 GAsyncResult       *result,
 		 YelpSimpleDocument *document)
 {
-    GSList *cur;
-
     document->priv->finished = TRUE;
     document_signal_all (document);
 }
--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:46
Picon
Gravatar

[PATCH 09/14] Missing return values.

---
 libyelp/yelp-man-document.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/libyelp/yelp-man-document.c b/libyelp/yelp-man-document.c
index 4fac05a..f401044 100644
--- a/libyelp/yelp-man-document.c
+++ b/libyelp/yelp-man-document.c
 <at>  <at>  -244,7 +244,7  <at>  <at>  man_request_page (YelpDocument         *document,
                                                                             callback,
                                                                             user_data);
     if (handled) {
-        return;
+        return TRUE;
     }

     g_mutex_lock (priv->mutex);
 <at>  <at>  -277,6 +277,8  <at>  <at>  man_request_page (YelpDocument         *document,
     }

     g_mutex_unlock (priv->mutex);
+
+    return FALSE;
 }

 
--

-- 
1.7.2.3
Rupert Swarbrick | 22 Dec 2010 12:52
Picon
Gravatar

[PATCH 13/14] Fix missing return type and incorrect test (= not ==).

---
 libyelp/yelp-view.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index c2b80eb..b8732db 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
 <at>  <at>  -175,6 +175,7  <at>  <at>  struct _YelpActionEntry {
     YelpViewActionValidFunc  func;
     gpointer                 data;
 };
+static void
 action_entry_free (YelpActionEntry *entry)
 {
     if (entry == NULL)
 <at>  <at>  -695,7 +696,7  <at>  <at>  view_scrolled (GtkAdjustment *adjustment,
         return;
     if (adjustment == priv->vadjustment)
         ((YelpBackEntry *) priv->back_cur->data)->vadj = gtk_adjustment_get_value (adjustment);
-    else if (adjustment = priv->hadjustment)
+    else if (adjustment == priv->hadjustment)
         ((YelpBackEntry *) priv->back_cur->data)->hadj = gtk_adjustment_get_value (adjustment);
 }

 <at>  <at>  -1233,7 +1234,6  <at>  <at>  view_resource_request (WebKitWebView         *view,
 {
     YelpViewPrivate *priv = GET_PRIV (view);
     const gchar *requri = webkit_network_request_get_uri (request);
-    gchar last;
(Continue reading)

Rupert Swarbrick | 22 Dec 2010 12:58
Picon
Gravatar

[PATCH 14/14] Fix memory leaks found by cppcheck.

---
 libyelp/yelp-location-entry.c |   10 +++++++---
 libyelp/yelp-settings.c       |    4 ++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c
index 06e1995..897e8e2 100644
--- a/libyelp/yelp-location-entry.c
+++ b/libyelp/yelp-location-entry.c
 <at>  <at>  -932,13 +932,17  <at>  <at>  entry_activate_cb (GtkEntry  *text_entry,
                    gpointer   user_data)
 {
     YelpLocationEntryPrivate *priv = GET_PRIV (user_data);
-    gchar *text = g_strdup (gtk_entry_get_text (text_entry));
+    gchar *text;

     if (!priv->enable_search)
         return;

-    if (!priv->search_mode || text == NULL || strlen(text) == 0)
+    text = g_strdup (gtk_entry_get_text (text_entry));
+
+    if (!priv->search_mode || text == NULL || strlen(text) == 0) {
+        g_free (text);
         return;
+    }

     g_signal_emit (user_data, location_entry_signals[SEARCH_ACTIVATED], 0, text);

 <at>  <at>  -1430,7 +1434,7  <at>  <at>  bookmarks_changed (YelpBookmarks      *bookmarks,
(Continue reading)


Gmane