From 03eea13fa336cd9c8d3e6e926cf5c77b98f5bc06 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 30 Sep 2010 10:41:11 +0800 Subject: add duplicate entry check in taglib_add_tag --- utils/storage/tag_utility.cpp | 11 ++++++++++- utils/storage/tag_utility.h | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'utils/storage') diff --git a/utils/storage/tag_utility.cpp b/utils/storage/tag_utility.cpp index 21d84b0..31a5e63 100644 --- a/utils/storage/tag_utility.cpp +++ b/utils/storage/tag_utility.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "tag_utility.h" @@ -63,10 +64,18 @@ bool taglib_add_tag(int line_type, const char * line_tag, int num_of_values, const char * required_tags[], const char * ignored_tags[]){ GArray * tag_array = (GArray *) g_ptr_array_index(g_tagutils_stack, g_tagutils_stack->len - 1); + + /* some duplicate tagname or line_type check here. */ + for ( size_t i = 0; i < tag_array->len; ++i) { + tag_entry * entry = &g_array_index(tag_array, tag_entry, i); + if ( entry->m_line_type == line_type || + strcmp( entry->m_line_tag, line_tag ) == 0 ) + return false; + } + tag_entry entry = tag_entry_copy(line_type, line_tag, num_of_values, (char **)required_tags, (char **)ignored_tags); - /* TODO: maybe also do some duplicate tagname or line_type check here. */ g_array_append_val(tag_array, entry); return true; } diff --git a/utils/storage/tag_utility.h b/utils/storage/tag_utility.h index fd5e89e..0b7ed7a 100644 --- a/utils/storage/tag_utility.h +++ b/utils/storage/tag_utility.h @@ -69,8 +69,9 @@ bool taglib_fini(); #define TAGLIB_IGNORED_TAGS const char * ignored_tags_saved[] #define TAGLIB_END_ADD_TAG \ - taglib_add_tag(line_type_saved, line_tag_saved, num_of_values_saved, \ - required_tags_saved, ignored_tags_saved); \ + assert(taglib_add_tag(line_type_saved, line_tag_saved, \ + num_of_values_saved, \ + required_tags_saved, ignored_tags_saved)); \ }; #endif -- cgit