Blame SOURCES/covscan.patch

a1f32f
diff --git a/src/dh-book-tree.c b/src/dh-book-tree.c
a1f32f
index e97fe283..7d8f2395 100644
a1f32f
--- a/src/dh-book-tree.c
a1f32f
+++ b/src/dh-book-tree.c
a1f32f
@@ -177,7 +177,7 @@ book_tree_find_language_group (DhBookTree  *tree,
a1f32f
                         g_return_if_reached ();
a1f32f
                 }
a1f32f
 
a1f32f
-                if (exact_iter != NULL &&
a1f32f
+                if (exact_iter != NULL && exact_found &&
a1f32f
                     g_ascii_strcasecmp (title, language) == 0) {
a1f32f
                         /* Exact match found! */
a1f32f
                         *exact_iter = loop_iter;
a1f32f
@@ -187,7 +187,7 @@ book_tree_find_language_group (DhBookTree  *tree,
a1f32f
                                 g_free (title);
a1f32f
                                 return;
a1f32f
                         }
a1f32f
-                } else if (next_iter != NULL &&
a1f32f
+                } else if (next_iter != NULL && next_found &&
a1f32f
                            g_ascii_strcasecmp (title, language) > 0) {
a1f32f
                         *next_iter = loop_iter;
a1f32f
                         *next_found = TRUE;
a1f32f
@@ -252,7 +252,7 @@ book_tree_find_book (DhBookTree        *tree,
a1f32f
 
a1f32f
                 /* We can compare pointers directly as we're playing with references
a1f32f
                  * of the same object */
a1f32f
-                if (exact_iter != NULL &&
a1f32f
+                if (exact_iter != NULL && exact_found &&
a1f32f
                     in_tree_book == book) {
a1f32f
                         *exact_iter = loop_iter;
a1f32f
                         *exact_found = TRUE;
a1f32f
diff --git a/src/dh-keyword-model.c b/src/dh-keyword-model.c
a1f32f
index a0b716f4..6a7fc50d 100644
a1f32f
--- a/src/dh-keyword-model.c
a1f32f
+++ b/src/dh-keyword-model.c
a1f32f
@@ -442,6 +442,14 @@ search_single_book (DhBook          *book,
a1f32f
         return ret;
a1f32f
 }
a1f32f
 
a1f32f
+static gint
a1f32f
+compare_links (gconstpointer a,
a1f32f
+               gconstpointer b,
a1f32f
+               gpointer user_data)
a1f32f
+{
a1f32f
+        return dh_link_compare (a, b);
a1f32f
+}
a1f32f
+
a1f32f
 static GQueue *
a1f32f
 search_books (SearchSettings  *settings,
a1f32f
               guint            max_hits,
a1f32f
@@ -486,7 +494,7 @@ search_books (SearchSettings  *settings,
a1f32f
                 dh_util_queue_concat (ret, book_result);
a1f32f
         }
a1f32f
 
a1f32f
-        g_queue_sort (ret, (GCompareDataFunc) dh_link_compare, NULL);
a1f32f
+        g_queue_sort (ret, (GCompareDataFunc) compare_links, NULL);
a1f32f
         return ret;
a1f32f
 }
a1f32f
 
a1f32f
diff --git a/src/dh-preferences.c b/src/dh-preferences.c
a1f32f
index 0568c505..ffae33b3 100644
a1f32f
--- a/src/dh-preferences.c
a1f32f
+++ b/src/dh-preferences.c
a1f32f
@@ -143,7 +143,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
a1f32f
                                     -1);
a1f32f
 
a1f32f
                 /* We may have reached the start of the next language group here */
a1f32f
-                if (first && !in_list_book) {
a1f32f
+                if (exact_found && first && !in_list_book) {
a1f32f
                         *next_iter = loop_iter;
a1f32f
                         *next_found = TRUE;
a1f32f
                         return;
a1f32f
@@ -151,7 +151,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
a1f32f
 
a1f32f
                 /* We can compare pointers directly as we're playing with references
a1f32f
                  * of the same object */
a1f32f
-                if (exact_iter &&
a1f32f
+                if (exact_iter && exact_found &&
a1f32f
                     in_list_book == book) {
a1f32f
                         *exact_iter = loop_iter;
a1f32f
                         *exact_found = TRUE;
a1f32f
@@ -160,7 +160,7 @@ preferences_bookshelf_find_book (DhPreferences     *prefs,
a1f32f
                                 g_object_unref (in_list_book);
a1f32f
                                 return;
a1f32f
                         }
a1f32f
-                } else if (next_iter &&
a1f32f
+                } else if (next_iter && next_found &&
a1f32f
                            dh_book_cmp_by_title (in_list_book, book) > 0) {
a1f32f
                         *next_iter = loop_iter;
a1f32f
                         *next_found = TRUE;
a1f32f
@@ -223,7 +223,7 @@ preferences_bookshelf_find_language_group (DhPreferences *prefs,
a1f32f
                         continue;
a1f32f
                 }
a1f32f
 
a1f32f
-                if (exact_iter &&
a1f32f
+                if (exact_iter && exact_found &&
a1f32f
                     g_ascii_strcasecmp (title, language) == 0) {
a1f32f
                         /* Exact match found! */
a1f32f
                         *exact_iter = loop_iter;
a1f32f
@@ -233,7 +233,7 @@ preferences_bookshelf_find_language_group (DhPreferences *prefs,
a1f32f
                                 g_free (title);
a1f32f
                                 return;
a1f32f
                         }
a1f32f
-                } else if (next_iter &&
a1f32f
+                } else if (next_iter && next_found &&
a1f32f
                            g_ascii_strcasecmp (title, language) > 0) {
a1f32f
                         *next_iter = loop_iter;
a1f32f
                         *next_found = TRUE;