[gitg/wip/lantw/fix-non-literal-format-string] build: Fix non-literal format string warnings for clang



commit d43a006ad299777a7c4d0772cdb6842812c6ab94
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sat Nov 3 22:08:14 2018 +0800

    build: Fix non-literal format string warnings for clang
    
    https://gitlab.gnome.org/GNOME/gitg/issues/160
    https://gitlab.gnome.org/GNOME/gitg/issues/161

 gitg/gitg-ref-action-fetch.vala            |  4 ++--
 libgitg/gitg-diff-image-side-by-side.vala  | 16 ++++++----------
 libgitg/gitg-diff-view-lines-renderer.vala |  8 ++++----
 3 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/gitg/gitg-ref-action-fetch.vala b/gitg/gitg-ref-action-fetch.vala
index bf0b5ac5..f0af2363 100644
--- a/gitg/gitg-ref-action-fetch.vala
+++ b/gitg/gitg-ref-action-fetch.vala
@@ -103,12 +103,12 @@ class RefActionFetch : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Obj
                        if (a.is_zero())
                        {
                                /* Translators: new refers to a new remote reference having been fetched, */
-                               updates.add(@"$name (%s)".printf(_("new")));
+                               updates.add(@"%s (%s)".printf(name, _("new")));
                        }
                        else
                        {
                                /* Translators: updated refers to a remote reference having been updated, */
-                               updates.add(@"$name (%s)".printf(_("updated")));
+                               updates.add(@"%s (%s)".printf(name, _("updated")));
                        }
                });
 
diff --git a/libgitg/gitg-diff-image-side-by-side.vala b/libgitg/gitg-diff-image-side-by-side.vala
index cc856b62..854b9bd5 100644
--- a/libgitg/gitg-diff-image-side-by-side.vala
+++ b/libgitg/gitg-diff-image-side-by-side.vala
@@ -30,22 +30,20 @@ class Gitg.DiffImageSideBySide : Gtk.DrawingArea
                {
                        if (d_old_size_layout == null && cache.old_pixbuf != null)
                        {
-                               string message;
+                               string message = @"$(cache.old_pixbuf.get_width()) × 
$(cache.old_pixbuf.get_height())";
 
                                if (cache.new_pixbuf != null)
                                {
                                        // Translators: this label is displayed below the image diff, %s
                                        // is substituted with the size of the image
-                                       message = _("before (%s)");
+                                       d_old_size_layout = create_pango_layout(_("before 
(%s)").printf(message));
                                }
                                else
                                {
                                        // Translators: this label is displayed below the image diff, %s
                                        // is substituted with the size of the image
-                                       message = _("removed (%s)");
+                                       d_old_size_layout = create_pango_layout(_("removed 
(%s)").printf(message));
                                }
-
-                               d_old_size_layout = 
create_pango_layout(message.printf(@"$(cache.old_pixbuf.get_width()) × $(cache.old_pixbuf.get_height())"));
                        }
 
                        return d_old_size_layout;
@@ -58,22 +56,20 @@ class Gitg.DiffImageSideBySide : Gtk.DrawingArea
                {
                        if (d_new_size_layout == null && cache.new_pixbuf != null)
                        {
-                               string message;
+                               string message = @"$(cache.new_pixbuf.get_width()) × 
$(cache.new_pixbuf.get_height())";
 
                                if (cache.old_pixbuf != null)
                                {
                                        // Translators: this label is displayed below the image diff, %s
                                        // is substituted with the size of the image
-                                       message = _("after (%s)");
+                                       d_new_size_layout = create_pango_layout(_("after 
(%s)").printf(message));
                                }
                                else
                                {
                                        // Translators: this label is displayed below the image diff, %s
                                        // is substituted with the size of the image
-                                       message = _("added (%s)");
+                                       d_new_size_layout = create_pango_layout(_("added 
(%s)").printf(message));
                                }
-
-                               d_new_size_layout = 
create_pango_layout(message.printf(@"$(cache.new_pixbuf.get_width()) × $(cache.new_pixbuf.get_height())"));
                        }
 
                        return d_new_size_layout;
diff --git a/libgitg/gitg-diff-view-lines-renderer.vala b/libgitg/gitg-diff-view-lines-renderer.vala
index 25614c0b..51d8444a 100644
--- a/libgitg/gitg-diff-view-lines-renderer.vala
+++ b/libgitg/gitg-diff-view-lines-renderer.vala
@@ -26,7 +26,7 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                SYMBOL
        }
 
-       private string d_num_digits_fmts;
+       private int d_num_digits;
        private string d_num_digits_fill;
 
        private ulong d_view_style_updated_id;
@@ -182,7 +182,7 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                        num_digits = 1;
                }
 
-               d_num_digits_fmts = @"%$(num_digits)d";
+               d_num_digits = num_digits;
                d_num_digits_fill = string.nfill(num_digits, ' ');
        }
 
@@ -207,14 +207,14 @@ class Gitg.DiffViewLinesRenderer : Gtk.SourceGutterRendererText
                        case Style.NEW:
                                if (origin == Ggit.DiffLineType.CONTEXT || origin == 
Ggit.DiffLineType.ADDITION)
                                {
-                                       ltext = d_num_digits_fmts.printf(newn);
+                                       ltext = "%*d".printf(d_num_digits, newn);
                                        newn++;
                                }
                                break;
                        case Style.OLD:
                                if (origin == Ggit.DiffLineType.CONTEXT || origin == 
Ggit.DiffLineType.DELETION)
                                {
-                                       ltext = d_num_digits_fmts.printf(oldn);
+                                       ltext = "%*d".printf(d_num_digits, oldn);
                                        oldn++;
                                }
                                break;


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