[devhelp] parser: check dh_parser_read_file() arguments



commit a382ad3e9dd740d4d9198cf1fbc2d34d5dc490d1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu May 11 12:28:46 2017 +0200

    parser: check dh_parser_read_file() arguments

 src/dh-book.c   |   12 +++++++-----
 src/dh-parser.c |    8 ++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/dh-book.c b/src/dh-book.c
index 1bddfe4..12af97d 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -298,7 +298,7 @@ dh_book_new (const gchar *index_file_path)
         DhBookPrivate *priv;
         DhBook     *book;
         GFile      *index_file;
-        gchar      *language;
+        gchar      *language = NULL;
         GError     *error = NULL;
 
         g_return_val_if_fail (index_file_path, NULL);
@@ -316,10 +316,12 @@ dh_book_new (const gchar *index_file_path)
                                   &priv->tree,
                                   &priv->keywords,
                                   &error)) {
-                g_warning ("Failed to read '%s': %s",
-                           index_file_path,
-                           error->message);
-                g_error_free (error);
+                if (error != NULL) {
+                        g_warning ("Failed to read '%s': %s",
+                                   index_file_path,
+                                   error->message);
+                        g_error_free (error);
+                }
 
                 /* Deallocate the book, as we are not going to add it in the
                  * manager.
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 13d70ce..3386c56 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -498,6 +498,14 @@ dh_parser_read_file (GFile   *index_file,
         GInputStream *input_stream = NULL;
         gboolean ok = TRUE;
 
+        g_return_val_if_fail (G_IS_FILE (index_file), FALSE);
+        g_return_val_if_fail (book_title != NULL && *book_title == NULL, FALSE);
+        g_return_val_if_fail (book_name != NULL && *book_name == NULL, FALSE);
+        g_return_val_if_fail (book_language != NULL && *book_language == NULL, FALSE);
+        g_return_val_if_fail (book_tree != NULL && *book_tree == NULL, FALSE);
+        g_return_val_if_fail (keywords != NULL && *keywords == NULL, FALSE);
+        g_return_val_if_fail (error != NULL && *error == NULL, FALSE);
+
         parser = g_new0 (DhParser, 1);
 
         index_file_uri = g_file_get_uri (index_file);


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