[sound-juicer] Fix -Wformat-nonliteral warnings



commit ab70bfd877e359fdc6fc7f62038036bada880a31
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Mon Jun 13 11:07:18 2016 +0100

    Fix -Wformat-nonliteral warnings
    
    GNOME_COMPILE_WARNINGS now sets -Werror-format=2 which gives fatal
    errors when compiling. Rather than turning off the warnings in the
    affected code rework it to use literal format strings so that we get
    the compile-time checks.

 libjuicer/sj-metadata-musicbrainz5.c |   90 +++++++++++++---------------------
 src/egg-play-preview.c               |    6 +-
 src/sj-extracting.c                  |   11 ++--
 3 files changed, 43 insertions(+), 64 deletions(-)
---
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index edb1cda..9c3f80b 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -473,51 +473,11 @@ build_composer_text (GSList  *composers,
 {
   gsize i = 0;
   gsize j = 0;
-  gsize index = 0; /* Which format string to use */
+  guint flags = 0; /* Which components do we have? */
   GSList *sort = NULL;
   gchar  *comp = NULL;
   gchar  *arr  = NULL;
   gchar  *arr_v[4];
-  gchar  *formats[16] = {
-    NULL,
-    NULL,
-    /* Tranlators: This string is used to build the composer tag when
-       a track has a mixture of arrangers, orchestrators and
-       transcribers but no composers */
-    N_("arr. %s"),
-    /* Tranlators: This string is used to build the composer tag when a
-       track has composers and arrangers, or a composer and a mixture
-       of arrangers, orchestrators and transcribers */
-    N_("%s arr. %s"),
-    /* Tranlators: This string is used to build the composer tag
-       when a track has orchestrators but no composer */
-    N_("orch. %s"),
-    /* Tranlators: This string is used to build the composer tag
-       when a track has composers and orchestrators */
-    N_("%s orch. %s"),
-    /* arrangers and orchestrators but no composers */
-    "arr. %s",
-    /* composers, arrangers and orchestrators */
-    "%s arr. %s",
-    /* Tranlators: This string is used to build the composer tag
-       when a track has a transcribers but no composer */
-    N_("trans. %s"),
-    /* Tranlators: This string is used to build the composer tag
-       when a track has composers and transcribers */
-    N_("%s trans. %s"),
-    /* arrangers and transcribers but no composers */
-    "arr. %s",
-    /* composers, arrangers and transcribers */
-    "%s arr. %s",
-    /* orchestrators and transcribers but no composer */
-    "arr. %s",
-    /* composers, orchestrators and transcribers */
-    "%s arr. %s",
-    /* arrangers, orchestrators and transcribers but no composers */
-    "arr. %s",
-    /* composers, arrangers, orchestrators and transcribers */
-    "%s arr. %s"
-  };
 
   enum {
     HAVE_COMPOSERS     = 1 << 0,
@@ -532,22 +492,22 @@ build_composer_text (GSList  *composers,
   *name = NULL;
 
   if (composers != NULL) {
-    index |= HAVE_COMPOSERS;
+    flags |= HAVE_COMPOSERS;
     comp = concatenate_composers (composers);
     sort = composers;
   }
   if (arrangers != NULL) {
-    index |= HAVE_ARRANGERS;
+    flags |= HAVE_ARRANGERS;
     arr_v[i++] = concatenate_composers (arrangers);
     sort = arrangers;
   }
   if (orchestrators != NULL) {
-    index |= HAVE_ORCHESTRATORS;
+    flags |= HAVE_ORCHESTRATORS;
     arr_v[i++] = concatenate_composers (orchestrators);
     sort = orchestrators;
   }
   if (transcribers != NULL) {
-    index |= HAVE_TRANSCRIBERS;
+    flags |= HAVE_TRANSCRIBERS;
     arr_v[i++] = concatenate_composers (transcribers);
     sort = transcribers;
   }
@@ -556,25 +516,43 @@ build_composer_text (GSList  *composers,
   if (i > 0)
     arr = g_strjoinv (", ", arr_v);
 
-  if (index & HAVE_COMPOSERS) {
-    if (index & ~HAVE_COMPOSERS) {
-      *name = g_strdup_printf (gettext (formats[index]), comp, arr);
+  if (flags & HAVE_COMPOSERS) {
+    if (flags & HAVE_ARRANGERS) {
+      /* Tranlators: This string is used to build the composer tag when a
+         track has composers and arrangers, or a composer and a mixture
+         of arrangers, orchestrators and transcribers */
+      *name = g_strdup_printf (_("%s arr. %s"), comp, arr);
+    } else if (flags & HAVE_ORCHESTRATORS) {
+      /* Tranlators: This string is used to build the composer tag
+         when a track has composers and orchestrators */
+      *name = g_strdup_printf (_("%s orch. %s"), comp, arr);
+    } else if (flags & HAVE_TRANSCRIBERS) {
+      /* Tranlators: This string is used to build the composer tag
+         when a track has composers and transcribers */
+      *name = g_strdup_printf (_("%s trans. %s"), comp, arr);
     } else {
+      /* Only composers */
       *name = g_strdup (comp);
     }
   } else {
-    if (index & ~HAVE_COMPOSERS) {
-      *name = g_strdup_printf (gettext (formats[index]), arr);
+    if (flags & HAVE_ARRANGERS) {
+      /* Tranlators: This string is used to build the composer tag when
+         a track has a mixture of arrangers, orchestrators and
+         transcribers but no composers */
+      *name = g_strdup_printf (_("arr. %s"), arr);
+    } else if (flags & HAVE_ORCHESTRATORS) {
+      /* Tranlators: This string is used to build the composer tag
+         when a track has orchestrators but no composer */
+      *name = g_strdup_printf (_("orch. %s"), arr);
+    } else if (flags & HAVE_TRANSCRIBERS) {
+      /* Tranlators: This string is used to build the composer tag
+         when a track has a transcribers but no composer */
+      *name = g_strdup_printf (_("trans. %s"), arr);
     }
   }
 
-  switch (index) {
-  case HAVE_COMPOSERS:
-  case HAVE_ARRANGERS:
-  case HAVE_ORCHESTRATORS:
-  case HAVE_TRANSCRIBERS:
+  if (flags)
     *sortname = get_sortname (sort);
-  }
 
   while (j < i)
     g_free (arr_v[j++]);
diff --git a/src/egg-play-preview.c b/src/egg-play-preview.c
index c683e48..046c62c 100644
--- a/src/egg-play-preview.c
+++ b/src/egg-play-preview.c
@@ -469,7 +469,7 @@ get_widest_time (int *widths, int duration)
        int minutes;
        int seconds;
        int m, s1, s2;
-       const char *format = "%d:%d%d/%d:%02d";
+       int width = 1;
 
        minutes = duration / 60;
        seconds = duration % 60;
@@ -482,12 +482,12 @@ get_widest_time (int *widths, int duration)
        if (minutes > 9) {
                m = get_widest_digit (widths, 9);
                m += get_widest_digit (widths, minutes % 10) * 10;
-               format = "%02d:%d%d/%d:%02d";
+               width = 2;
        } else {
                m = get_widest_digit (widths, minutes);
        }
 
-       return g_strdup_printf (format, m, s2, s1, minutes, seconds);
+       return g_strdup_printf ("%0*d:%d%d/%d:%02d", width, m, s2, s1, minutes, seconds);
 }
 
 static void
diff --git a/src/sj-extracting.c b/src/sj-extracting.c
index a1be98f..2fe992c 100644
--- a/src/sj-extracting.c
+++ b/src/sj-extracting.c
@@ -1168,14 +1168,15 @@ filepath_parse_pattern (const char* pattern, const TrackDetails *track)
       case 'N':
         /* Disc and track number, zero padded */
         if (track->album->disc_number > 0) {
-          const gchar *format;
+          int width;
+
           if (track->album->disc_count < 10)
-            format = "d%dt%02d";
+            width = 1;
           else if (track->album->disc_count < 100)
-            format = "d%02dt%02d";
+            width = 2;
           else
-            format = "d%03dt%02d";
-          string = g_strdup_printf (format, track->album->disc_number, track->number);
+            width = 3;
+          string = g_strdup_printf ("d%0*dt%02d", width, track->album->disc_number, track->number);
         } else {
           string = g_strdup_printf ("%02d", track->number);
         }


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