[easytag/easytag-2-2] Use a stack-allocated buffer for WavPack tags
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/easytag-2-2] Use a stack-allocated buffer for WavPack tags
- Date: Mon, 22 Dec 2014 09:04:41 +0000 (UTC)
commit 7a850cf39135a075ef09540f4182787fad24941b
Author: David King <amigadave amigadave com>
Date: Thu Dec 18 17:41:21 2014 +0000
Use a stack-allocated buffer for WavPack tags
src/wavpack_tag.c | 44 +++++++++++++++-----------------------------
1 files changed, 15 insertions(+), 29 deletions(-)
---
diff --git a/src/wavpack_tag.c b/src/wavpack_tag.c
index 7919fe8..457a197 100644
--- a/src/wavpack_tag.c
+++ b/src/wavpack_tag.c
@@ -66,7 +66,8 @@
gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
{
WavpackContext *wpc;
- gchar *field, *field2;
+ gchar field[MAXLEN] = { 0, };
+ gchar *field2;
guint length;
int open_flags = OPEN_TAGS;
@@ -82,43 +83,39 @@ gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
/*
* Title
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "title", field, MAXLEN);
if ( length > 0 && FileTag->title == NULL ) {
FileTag->title = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Artist
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "artist", field, MAXLEN);
if ( length > 0 && FileTag->artist == NULL) {
FileTag->artist = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Album
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "album", field, MAXLEN);
if ( length > 0 && FileTag->album == NULL ) {
FileTag->album = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Discnumber + Disctotal.
*/
- field = g_malloc0 (sizeof (char) * MAXLEN);
length = WavpackGetTagItem (wpc, "part", field, MAXLEN);
field2 = g_utf8_strchr (field, -1, '/');
@@ -138,24 +135,22 @@ gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
FileTag->disc_number = et_disc_number_to_string (atoi (Try_To_Validate_Utf8_String (field)));
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Year
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "year", field, MAXLEN);
if ( length > 0 && FileTag->year == NULL ) {
FileTag->year = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Tracknumber + tracktotal
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "track", field, MAXLEN);
field2 = g_utf8_strchr(field, -1, '/');
@@ -174,93 +169,84 @@ gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
FileTag->track = et_track_number_to_string (atoi (Try_To_Validate_Utf8_String (field)));
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Genre
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "genre", field, MAXLEN);
if ( length > 0 && FileTag->genre == NULL ) {
FileTag->genre = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Comment
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "comment", field, MAXLEN);
if ( length > 0 && FileTag->comment == NULL ) {
FileTag->comment = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Composer
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "composer", field, MAXLEN);
if ( length > 0 && FileTag->composer == NULL ) {
FileTag->composer = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Original artist
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "original artist", field, MAXLEN);
if ( length > 0 && FileTag->orig_artist == NULL ) {
FileTag->orig_artist = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Copyright
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "copyright", field, MAXLEN);
if ( length > 0 && FileTag->copyright == NULL ) {
FileTag->copyright = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* URL
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "copyright url", field, MAXLEN);
if ( length > 0 && FileTag->url == NULL ) {
FileTag->url = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
+ memset (field, '\0', MAXLEN);
/*
* Encoded by
*/
- field = g_malloc0(sizeof(char) * MAXLEN);
length = WavpackGetTagItem(wpc, "encoded by", field, MAXLEN);
if ( length > 0 && FileTag->encoded_by == NULL ) {
FileTag->encoded_by = Try_To_Validate_Utf8_String(field);
}
- g_free (field);
-
- WavpackCloseFile(wpc);
+ WavpackCloseFile (wpc);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]