aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-14 13:26:02 +0100
committerMax Kellermann <max@duempel.org>2013-12-14 13:44:57 +0100
commit1da0526072db26a9a84c68cba45e511aee0641fa (patch)
tree037f4646b8b1b57c2ba0fc1d67e5300f4f175a9f
parent635a67afac8e8af1a848d67dbfc287eb9b67dd70 (diff)
downloadmpd-1da0526072db26a9a84c68cba45e511aee0641fa.tar.gz
mpd-1da0526072db26a9a84c68cba45e511aee0641fa.tar.xz
mpd-1da0526072db26a9a84c68cba45e511aee0641fa.zip
decoder/flac: VorbisComment_Entry is null-terminated
Don't duplicate the buffer just to null-terminate the string. According to libFLAC API documentation, the string is already null-terminated.
Diffstat (limited to '')
-rw-r--r--src/decoder/FlacMetadata.cxx25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/decoder/FlacMetadata.cxx b/src/decoder/FlacMetadata.cxx
index a3d62d07a..b3dbc6114 100644
--- a/src/decoder/FlacMetadata.cxx
+++ b/src/decoder/FlacMetadata.cxx
@@ -28,8 +28,6 @@
#include "util/ASCII.hxx"
#include "util/SplitString.hxx"
-#include <glib.h>
-
#include <string.h>
static bool
@@ -39,7 +37,7 @@ flac_find_float_comment(const FLAC__StreamMetadata *block,
int offset;
size_t pos;
int len;
- unsigned char tmp, *p;
+ unsigned char *p;
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
cmnt);
@@ -52,11 +50,7 @@ flac_find_float_comment(const FLAC__StreamMetadata *block,
return false;
p = &block->data.vorbis_comment.comments[offset].entry[pos];
- tmp = p[len];
- p[len] = '\0';
*fl = (float)atof((char *)p);
- p[len] = tmp;
-
return true;
}
@@ -117,21 +111,19 @@ flac_parse_mixramp(const FLAC__StreamMetadata *block)
/**
* Checks if the specified name matches the entry's name, and if yes,
- * returns the comment value (not null-temrinated).
+ * returns the comment value;
*/
static const char *
flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
- const char *name, size_t *length_r)
+ const char *name)
{
size_t name_length = strlen(name);
const char *comment = (const char*)entry->entry;
- if (entry->length <= name_length ||
- !StringEqualsCaseASCII(comment, name, name_length))
+ if (!StringEqualsCaseASCII(comment, name, name_length))
return nullptr;
if (comment[name_length] == '=') {
- *length_r = entry->length - name_length - 1;
return comment + name_length + 1;
}
@@ -147,14 +139,9 @@ flac_copy_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const char *name, TagType tag_type,
const struct tag_handler *handler, void *handler_ctx)
{
- const char *value;
- size_t value_length;
-
- value = flac_comment_value(entry, name, &value_length);
+ const char *value = flac_comment_value(entry, name);
if (value != nullptr) {
- char *p = g_strndup(value, value_length);
- tag_handler_invoke_tag(handler, handler_ctx, tag_type, p);
- g_free(p);
+ tag_handler_invoke_tag(handler, handler_ctx, tag_type, value);
return true;
}