From 1d43096f89400f82ef31b5b7804351f470a6c548 Mon Sep 17 00:00:00 2001 From: Buschel Date: Sun, 20 Feb 2011 16:12:05 +0000 Subject: [PATCH] FS#11920: Do not overwrite already existing metadata and take into account string termination. This can save several bytes of the metadata buffer when tags have multiple entries (e.g. multiple gerne tags) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29349 a1c6a512-1295-4272-9138-f99709370657 --- apps/metadata/id3tags.c | 12 ++++++++---- apps/metadata/metadata_common.c | 5 ++++- apps/metadata/mp4.c | 16 +++++++++++----- apps/plugins/SOURCES | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/apps/metadata/id3tags.c b/apps/metadata/id3tags.c index 9ee183a1b3..9143f8ad25 100644 --- a/apps/metadata/id3tags.c +++ b/apps/metadata/id3tags.c @@ -358,8 +358,7 @@ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos ) if ((tag - entry->id3v2buf + desc_len + 2) < bufferpos) { /* At least part of the value was read, so we can safely try to - * parse it - */ + * parse it */ value = tag + desc_len + 1; value_len = bufferpos - (tag - entry->id3v2buf); @@ -368,8 +367,7 @@ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos ) entry->albumartist = tag; #if CONFIG_CODEC == SWCODEC } else { - value_len = parse_replaygain(tag, value, entry, tag, - value_len); + value_len = parse_replaygain(tag, value, entry, tag, value_len); #endif } } @@ -1040,6 +1038,12 @@ void setid3v2title(int fd, struct mp3entry *entry) #endif if( tr->ppFunc ) bufferpos = tr->ppFunc(entry, tag, bufferpos); + + /* Trim. Take into account that multiple string contents will + * only be displayed up to their first null termination. All + * content after this null termination is obsolete and can be + * overwritten. */ + bufferpos -= (bytesread - strlen(tag)); /* Seek to the next frame */ if(framelen < totframelen) diff --git a/apps/metadata/metadata_common.c b/apps/metadata/metadata_common.c index e1ef9a0d62..4f001775f3 100644 --- a/apps/metadata/metadata_common.c +++ b/apps/metadata/metadata_common.c @@ -337,7 +337,10 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3, p = NULL; } - if (p) + /* Do not overwrite already available metadata. Especially when reading + * tags with e.g. multiple genres / artists. This way only the first + * of multiple entries is used, all following are dropped. */ + if (p!=NULL && *p==NULL) { len = strlen(value); len = MIN(len, buf_remaining - 1); diff --git a/apps/metadata/mp4.c b/apps/metadata/mp4.c index 706e621234..14aad2203c 100644 --- a/apps/metadata/mp4.c +++ b/apps/metadata/mp4.c @@ -117,11 +117,17 @@ static unsigned int read_mp4_tag_string(int fd, int size_left, char** buffer, if (bytes_read) { - (*buffer)[bytes_read] = 0; - *dest = *buffer; - length = strlen(*buffer) + 1; - *buffer_left -= length; - *buffer += length; + /* Do not overwrite already available metadata. Especially when reading + * tags with e.g. multiple genres / artists. This way only the first + * of multiple entries is used, all following are dropped. */ + if (*dest == NULL) + { + (*buffer)[bytes_read] = 0; + *dest = *buffer; + length = strlen(*buffer) + 1; + *buffer_left -= length; + *buffer += length; + } } else { diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 7afd97309f..0f804a521b 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -217,7 +217,7 @@ superdom.c -#ifdef HAVE_TEST_PLUGINS /* enable in advanced build options */ +#if 1//def HAVE_TEST_PLUGINS /* enable in advanced build options */ #ifdef HAVE_ADJUSTABLE_CPU_FREQ test_boost.c #endif -- 2.11.4.GIT