[easytag/wip/application-window: 43/72] Fix some const string warnings



commit 2f4049684b9d40478ad11cbc164e0b1c6b1ebe14
Author: David King <amigadave amigadave com>
Date:   Wed Jul 9 16:52:18 2014 +0100

    Fix some const string warnings
    
    Found with -Wwrite-strings and -Wcast-qual.

 nautilus-extension/nautilus-easytag.c |    2 +-
 src/cddb_dialog.c                     |    2 +-
 src/charset.c                         |    7 +++++--
 src/easytag.c                         |    2 +-
 src/et_core.c                         |   22 +++++++++++-----------
 src/et_core.h                         |    2 +-
 src/flac_tag.c                        |    2 ++
 src/genres.h                          |    2 +-
 src/id3_tag.c                         |    3 ++-
 src/id3_tag.h                         |    2 +-
 src/id3v24_tag.c                      |    8 +++++---
 src/picture.c                         |    4 +++-
 src/scan_dialog.c                     |    2 +-
 src/search_dialog.c                   |   32 ++++++++++++++++----------------
 src/vcedit.c                          |    2 +-
 15 files changed, 52 insertions(+), 42 deletions(-)
---
diff --git a/nautilus-extension/nautilus-easytag.c b/nautilus-extension/nautilus-easytag.c
index b80a369..51d5966 100644
--- a/nautilus-extension/nautilus-easytag.c
+++ b/nautilus-extension/nautilus-easytag.c
@@ -53,7 +53,7 @@ typedef struct
 
 static struct
 {
-    gchar *mime_type;
+    const gchar *mime_type;
     gboolean is_directory;
     gboolean is_file;
 } easytag_mime_types[] =
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index e4b01a0..6c022cb 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -170,7 +170,7 @@ enum
 
 
 #define CDDB_GENRE_MAX ( sizeof(cddb_genre_vs_id3_genre)/sizeof(cddb_genre_vs_id3_genre[0]) - 1 )
-static char *cddb_genre_vs_id3_genre [][2] =
+static const gchar *cddb_genre_vs_id3_genre [][2] =
 {
     /* Cddb Genre - ID3 Genre */
     {"Blues",       "Blues"},
diff --git a/src/charset.c b/src/charset.c
index 554faf6..93fa925 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -158,7 +158,7 @@ check_locale (const char *locale)
 
 /* stolen from gnome-desktop-item.c */
 G_GNUC_NULL_TERMINATED static void
-insert_locales (GHashTable *encodings, char *enc, ...)
+insert_locales (GHashTable *encodings, const gchar *enc, ...)
 {
     va_list args;
     char *s;
@@ -169,7 +169,9 @@ insert_locales (GHashTable *encodings, char *enc, ...)
         s = va_arg (args, char *);
         if (s == NULL)
             break;
-        g_hash_table_insert (encodings, s, enc);
+        /* A GDestroyNotify is not passed, so casting away the const is
+         * safe, as the key is never freed. */
+        g_hash_table_insert (encodings, s, (gpointer)enc);
     }
     va_end (args);
 }
@@ -179,6 +181,7 @@ insert_locales (GHashTable *encodings, char *enc, ...)
 void
 Charset_Insert_Locales_Init (void)
 {
+    /* FIXME: Use g_hash_table_new_full. */
     encodings = g_hash_table_new (g_str_hash, g_str_equal);
 
     /* "C" is plain ascii */
diff --git a/src/easytag.c b/src/easytag.c
index 9d974bf..ae65750 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1195,7 +1195,7 @@ Write_File_Tag (ET_File *ETFile, gboolean hide_msgbox)
         return TRUE;
     }
 
-    switch ( ((ET_File_Description *)ETFile->ETFileDescription)->TagType)
+    switch (ETFile->ETFileDescription->TagType)
     {
 #ifdef ENABLE_OGG
         case OGG_TAG:
diff --git a/src/et_core.c b/src/et_core.c
index 7048158..998975a 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -131,8 +131,8 @@ GdkRGBA RED = {1.0, 0.0, 0.0, 1.0 };
 
 //gboolean ET_File_Is_Supported (gchar *filename);
 static gchar *ET_Get_File_Extension (const gchar *filename);
-static ET_File_Description *ET_Get_File_Description (const gchar *filename);
-static ET_File_Description *ET_Get_File_Description_From_Extension (const gchar *extension);
+static const ET_File_Description *ET_Get_File_Description (const gchar *filename);
+static const ET_File_Description *ET_Get_File_Description_From_Extension (const gchar *extension);
 
 static gboolean ET_Free_File_List                 (void);
 static gboolean ET_Free_File_Name_List            (GList *FileNameList);
@@ -220,20 +220,20 @@ ET_Get_File_Extension (const gchar *filename)
  * Determine description of file using his extension.
  * If extension is NULL or not found into the tab, it returns the last entry for UNKNOWN_FILE.
  */
-static ET_File_Description *
+static const ET_File_Description *
 ET_Get_File_Description_From_Extension (const gchar *extension)
 {
     guint i;
 
     if (!extension) // Unknown file
-        return (ET_File_Description*) &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
+        return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
 
     for (i=0; i<ET_FILE_DESCRIPTION_SIZE; i++)  // Use of '<' instead of '<=' to avoid to test for Unknown 
file
         if ( strcasecmp(extension,ETFileDescription[i].Extension)==0 )
-            return (ET_File_Description*) &ETFileDescription[i];
+            return &ETFileDescription[i];
 
     // If not found in the list
-    return (ET_File_Description*) &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
+    return &ETFileDescription[ET_FILE_DESCRIPTION_SIZE];
 }
 
 
@@ -242,7 +242,7 @@ ET_Get_File_Description_From_Extension (const gchar *extension)
  * Determines first the extension. If extension is NULL or not found into the tab,
  * it returns the last entry for UNKNOWN_FILE.
  */
-static ET_File_Description *
+static const ET_File_Description *
 ET_Get_File_Description (const gchar *filename)
 {
     return ET_Get_File_Description_From_Extension(ET_Get_File_Extension(filename));
@@ -485,7 +485,7 @@ ET_Undo_Key_New (void)
  */
 GList *ET_Add_File_To_File_List (gchar *filename)
 {
-    ET_File_Description *ETFileDescription;
+    const ET_File_Description *ETFileDescription;
     ET_File      *ETFile;
     File_Name    *FileName;
     File_Tag     *FileTag;
@@ -2733,7 +2733,7 @@ gboolean ET_Set_Field_File_Tag_Picture (Picture **FileTagField, Picture *pic)
  */
 void ET_Display_File_Data_To_UI (ET_File *ETFile)
 {
-    ET_File_Description *ETFileDescription;
+    const ET_File_Description *ETFileDescription;
     gchar *cur_filename;
     gchar *cur_filename_utf8;
     gchar *msg;
@@ -3325,7 +3325,7 @@ ET_Display_File_Info_To_UI(ET_File_Info *ETFileInfo)
  */
 void ET_Save_File_Data_From_UI (ET_File *ETFile)
 {
-    ET_File_Description *ETFileDescription;
+    const ET_File_Description *ETFileDescription;
     File_Name *FileName;
     File_Tag  *FileTag;
     guint      undo_key;
@@ -4024,7 +4024,7 @@ ET_Save_File_Tag_Internal (ET_File *ETFile, File_Tag *FileTag)
  */
 gboolean ET_Save_File_Tag_To_HD (ET_File *ETFile)
 {
-    ET_File_Description *ETFileDescription;
+    const ET_File_Description *ETFileDescription;
     gchar *cur_filename;
     gchar *cur_filename_utf8;
     gboolean state;
diff --git a/src/et_core.h b/src/et_core.h
index 1e72fcd..cfe8503 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -184,7 +184,7 @@ struct _ET_File
 
     time_t FileModificationTime;            /* Save modification time of the file */
 
-    ET_File_Description *ETFileDescription;
+    const ET_File_Description *ETFileDescription;
     gchar               *ETFileExtension;   /* Real extension of the file (keeping the case) (should be 
placed in ETFileDescription?) */
     ET_File_Info        *ETFileInfo;        /* Header infos: bitrate, duration, ... */
 
diff --git a/src/flac_tag.c b/src/flac_tag.c
index e6c0b57..ebae5c0 100644
--- a/src/flac_tag.c
+++ b/src/flac_tag.c
@@ -1056,6 +1056,8 @@ gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile)
                 
                 // Mime type
                 format = Picture_Format_From_Data(pic);
+                /* Safe to pass a const string, according to the FLAC API
+                 * reference. */
                 FLAC__metadata_object_picture_set_mime_type(picture_block, (gchar 
*)Picture_Mime_Type_String(format), TRUE);
 
                 // Description
diff --git a/src/genres.h b/src/genres.h
index 4b6d5c5..63c93a9 100644
--- a/src/genres.h
+++ b/src/genres.h
@@ -35,7 +35,7 @@
  * Last Update: 2014-05-05
  * https://en.wikipedia.org/wiki/ID3#List_of_genres
  */
-static char *id3_genres[] =
+static const char *id3_genres[] =
 {
     "Blues", /* 0: Core ID3 support */
     "Classic Rock",
diff --git a/src/id3_tag.c b/src/id3_tag.c
index a7b2c29..d2dfccd 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -1566,7 +1566,8 @@ guchar Id3tag_String_To_Genre (gchar *genre)
  *    - undefined/unknown (GENRE_MAX+1 to ID3_INVALID_GENRE-1)
  *    - invalid (>ID3_INVALID_GENRE)
  */
-gchar *Id3tag_Genre_To_String (unsigned char genre_code)
+const gchar *
+Id3tag_Genre_To_String (unsigned char genre_code)
 {
     if (genre_code>=ID3_INVALID_GENRE)    /* empty */
         return "";
diff --git a/src/id3_tag.h b/src/id3_tag.h
index 9424506..ecaf717 100644
--- a/src/id3_tag.h
+++ b/src/id3_tag.h
@@ -40,7 +40,7 @@ gboolean Id3tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag);
 gboolean Id3tag_Write_File_v24Tag (ET_File *ETFile);
 gboolean Id3tag_Write_File_Tag    (ET_File *ETFile);
 
-gchar   *Id3tag_Genre_To_String (unsigned char genre_code);
+const gchar * Id3tag_Genre_To_String (unsigned char genre_code);
 guchar   Id3tag_String_To_Genre (gchar *genre);
 
 gchar *et_id3tag_get_tpos_from_file_tag (File_Tag *file_tag);
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 042a834..946d776 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -573,7 +573,9 @@ etag_guess_byteorder(const id3_ucs4_t *ustr, gchar **ret) /* XXX */
     }
 
     if (!charset)
-        charset = "ISO-8859-1";
+    {
+        charset = g_strdup ("ISO-8859-1");
+    }
 
     tmp = (gchar *)id3_ucs4_utf8duplicate(ustr);
     str = g_convert(tmp, -1, charset, "UTF-8", NULL, NULL, NULL);
@@ -745,8 +747,8 @@ libid3tag_Get_Frame_Str (const struct id3_frame *frame,
                         continue;
                 }
 
-                latinstr = g_strdup (field_type == ID3_FIELD_TYPE_LATIN1 ? (gchar *)id3_field_getlatin1 
(field)
-                                                                         : (gchar *)id3_field_getfulllatin1 
(field));
+                latinstr = g_strdup (field_type == ID3_FIELD_TYPE_LATIN1 ? (const gchar 
*)id3_field_getlatin1 (field)
+                                                                         : (const gchar 
*)id3_field_getfulllatin1 (field));
 
                 if (g_settings_get_boolean (MainSettings,
                                             "id3-override-read-encoding"))
diff --git a/src/picture.c b/src/picture.c
index 105876f..1abfbf7 100644
--- a/src/picture.c
+++ b/src/picture.c
@@ -86,7 +86,9 @@ void Tag_Area_Picture_Drag_Data (GtkWidget *widget, GdkDragContext *dc,
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
     gtk_tree_selection_unselect_all(selection);
 
-    uri = uri_list = g_strsplit((gchar *)gtk_selection_data_get_data(selection_data), "\r\n", 0);
+    uri = uri_list = g_strsplit ((const gchar *)gtk_selection_data_get_data (selection_data),
+                                 "\r\n", 0);
+
     while (*uri && strlen(*uri))
     {
         GFile *file = g_file_new_for_uri (*uri);
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 4e4f2dd..3583863 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -292,7 +292,7 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
         GError *error = NULL;
         guint32 crc32_value;
         gchar *buffer;
-        ET_File_Description *ETFileDescription;
+        const ET_File_Description *ETFileDescription;
 
         ETFileDescription = ETFile->ETFileDescription;
         switch (ETFileDescription->TagType)
diff --git a/src/search_dialog.c b/src/search_dialog.c
index 1877516..491c5e2 100644
--- a/src/search_dialog.c
+++ b/src/search_dialog.c
@@ -590,22 +590,22 @@ create_search_dialog (EtSearchDialog *self)
     GtkWidget *ScrollWindow;
     GtkTreeViewColumn* column;
     GtkCellRenderer* renderer;
-    gchar *SearchResultList_Titles[] = { N_("Filename"),
-                                         N_("Title"),
-                                         N_("Artist"),
-                                         N_("Album Artist"),
-                                         N_("Album"),
-                                         N_("CD"),
-                                         N_("Year"),
-                                         N_("Track"),
-                                         N_("Genre"),
-                                         N_("Comment"),
-                                         N_("Composer"),
-                                         N_("Original Artist"),
-                                         N_("Copyright"),
-                                         N_("URL"),
-                                         N_("Encoded By")
-                                       };
+    const gchar *SearchResultList_Titles[] = { N_("Filename"),
+                                               N_("Title"),
+                                               N_("Artist"),
+                                               N_("Album Artist"),
+                                               N_("Album"),
+                                               N_("CD"),
+                                               N_("Year"),
+                                               N_("Track"),
+                                               N_("Genre"),
+                                               N_("Comment"),
+                                               N_("Composer"),
+                                               N_("Original Artist"),
+                                               N_("Copyright"),
+                                               N_("URL"),
+                                               N_("Encoded By")
+                                             };
 
     priv = et_search_dialog_get_instance_private (self);
 
diff --git a/src/vcedit.c b/src/vcedit.c
index 06e7caa..eb0a062 100644
--- a/src/vcedit.c
+++ b/src/vcedit.c
@@ -89,7 +89,7 @@ void vcedit_clear(vcedit_state *state)
 /* Next two functions pulled straight from libvorbis, apart from one change
  * - we don't want to overwrite the vendor string.
  */
-static void _v_writestring(oggpack_buffer *o,char *s, int len)
+static void _v_writestring(oggpack_buffer *o, const char *s, int len)
 {
     while(len--)
     {


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