[glib] gio-tool: Fix errors format string



commit 3d7534eae5e5421573e1f7cf76f6339cffeb903d
Author: Víctor Manuel Jáquez Leal <vjaquez igalia com>
Date:   Mon Apr 10 13:00:44 2017 +0200

    gio-tool: Fix errors format string
    
    Compiling with clang 3.8.1-18 (debian, x86_64) I ran across this
    error:
    
    gio-tool.c:40:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
      message = g_strdup_vprintf (format, args);
                                  ^~~~~~
    gio-tool.c:55:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
      message = g_strdup_vprintf (format, args);
                                  ^~~~~~
    2 errors generated.
    
    To fix the first one, related with the function print_error(), this
    patch adds to the function prototype a compiler's attribute.
    
    For the second one, since the usage of that function is to print
    one string and the format is already provided, the patch simplifies
    the function by no receiving variadic arguments.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781125

 gio/gio-tool-rename.c |    2 +-
 gio/gio-tool-save.c   |    6 +++---
 gio/gio-tool-set.c    |    2 +-
 gio/gio-tool.c        |   12 ++----------
 gio/gio-tool.h        |    5 ++---
 5 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/gio/gio-tool-rename.c b/gio/gio-tool-rename.c
index 9c36554..820208f 100644
--- a/gio/gio-tool-rename.c
+++ b/gio/gio-tool-rename.c
@@ -85,7 +85,7 @@ handle_rename (int argc, char *argv[], gboolean do_help)
 
   if (new_file == NULL)
     {
-      print_error (error->message);
+      print_error ("%s", error->message);
       g_error_free (error);
       retval = 1;
     }
diff --git a/gio/gio-tool-save.c b/gio/gio-tool-save.c
index dc22242..3e4497b 100644
--- a/gio/gio-tool-save.c
+++ b/gio/gio-tool-save.c
@@ -105,7 +105,7 @@ save (GFile *file)
              if (written == -1)
                {
                  save_res = FALSE;
-                  print_error (error->message);
+                  print_error ("%s", error->message);
                  g_error_free (error);
                  goto out;
                }
@@ -116,7 +116,7 @@ save (GFile *file)
       else if (res < 0)
        {
          save_res = FALSE;
-          print_error (_("Error reading from standard input"));
+          print_error ("%s", _("Error reading from standard input"));
          break;
        }
       else if (res == 0)
@@ -129,7 +129,7 @@ save (GFile *file)
   if (!close_res)
     {
       save_res = FALSE;
-      print_error (error->message);
+      print_error ("%s", error->message);
       g_error_free (error);
     }
 
diff --git a/gio/gio-tool-set.c b/gio/gio-tool-set.c
index ada62c2..411c132 100644
--- a/gio/gio-tool-set.c
+++ b/gio/gio-tool-set.c
@@ -192,7 +192,7 @@ handle_set (int argc, char *argv[], gboolean do_help)
                                G_FILE_QUERY_INFO_NONE,
                              NULL, &error))
     {
-      print_error (error->message);
+      print_error ("%s", error->message);
       g_error_free (error);
       g_object_unref (file);
       return 1;
diff --git a/gio/gio-tool.c b/gio/gio-tool.c
index 61ca87a..3b79d21 100644
--- a/gio/gio-tool.c
+++ b/gio/gio-tool.c
@@ -31,7 +31,7 @@
 
 
 void
-print_error (const char *format, ...)
+print_error (const gchar *format, ...)
 {
   gchar *message;
   va_list args;
@@ -45,21 +45,13 @@ print_error (const char *format, ...)
 }
 
 void
-print_file_error (GFile *file, const gchar *format, ...)
+print_file_error (GFile *file, const gchar *message)
 {
   gchar *uri;
-  gchar *message;
-  va_list args;
-
-  va_start (args, format);
-  message = g_strdup_vprintf (format, args);
-  va_end (args);
 
   uri = g_file_get_uri (file);
   print_error ("%s: %s", uri, message);
   g_free (uri);
-
-  g_free (message);
 }
 
 void
diff --git a/gio/gio-tool.h b/gio/gio-tool.h
index 154f302..58cc0f4 100644
--- a/gio/gio-tool.h
+++ b/gio/gio-tool.h
@@ -21,10 +21,9 @@
 #define __GIO_TOOL_H__
 
 void print_error      (const gchar    *format,
-                       ...);
+                       ...) G_GNUC_PRINTF (1, 2);
 void print_file_error (GFile          *file,
-                       const gchar    *format,
-                       ...);
+                       const gchar    *message);
 void show_help        (GOptionContext *context,
                        const char     *message);
 


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