diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-09-03 03:11:58 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-03 03:14:17 -0700 |
commit | 3f29cbaf360c5e9542c7b9e6648626d6e0ea8b1e (patch) | |
tree | 49dd735d55dd8d5964c4273998a2f3fc454534bb /src/utf8.c | |
parent | 86d4a80b0069b2be368bfe4af164be5ff72a48b4 (diff) | |
parent | cdc9bb460e9536577d2747d51c76306a91b3d064 (diff) | |
download | mpd-3f29cbaf360c5e9542c7b9e6648626d6e0ea8b1e.tar.gz mpd-3f29cbaf360c5e9542c7b9e6648626d6e0ea8b1e.tar.xz mpd-3f29cbaf360c5e9542c7b9e6648626d6e0ea8b1e.zip |
Merge branch 'mk/tag'
* mk/tag: (22 commits)
tag: fix segfault on update
utf8.h: Fix build (broken os_compat.h #include)
tag: optimize tag_dup(), copy item references
tag: fix the shout and oggflac plugins
const pointers
tag: static directory name
tag: try not to reallocate tag.items in every add() call
song: don't export newNullSong()
tag: try not to duplicate the input string
tag: pass length to fix_utf8()
added "length" parameter to validUtf8String()
assert value!=NULL in fix_utf8()
tag: converted macro fixUtf8() to an inline function
tag: added a pool for tag items
tag: converted tag_item.value to a char array
removed tree.c
tag: converted MpdTag.items to a pointer list
tag: moved code to tag_id3.c
wavpack: tag_new() cannot fail
tag: converted tag_add_item() to an inline function
...
Diffstat (limited to 'src/utf8.c')
-rw-r--r-- | src/utf8.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/utf8.c b/src/utf8.c index e8f3dbdde..1b03f5d20 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -69,10 +69,12 @@ static char utf8_to_latin1_char(const char *inUtf8) return (char)(c + utf8[1]); } -static unsigned int validateUtf8Char(const char *inUtf8Char) +static unsigned int validateUtf8Char(const char *inUtf8Char, size_t length) { const unsigned char *utf8Char = (const unsigned char *)inUtf8Char; + assert(length > 0); + if (utf8Char[0] < 0x80) return 1; @@ -84,7 +86,7 @@ static unsigned int validateUtf8Char(const char *inUtf8Char) t = (t >> 1); count++; } - if (count > 5) + if (count > 5 || (size_t)count > length) return 0; for (i = 1; i <= count; i++) { if (utf8Char[i] < 0x80 || utf8Char[i] > 0xBF) @@ -95,15 +97,17 @@ static unsigned int validateUtf8Char(const char *inUtf8Char) return 0; } -int validUtf8String(const char *string) +int validUtf8String(const char *string, size_t length) { unsigned int ret; - while (*string) { - ret = validateUtf8Char(string); + while (length > 0) { + ret = validateUtf8Char(string, length); + assert((size_t)ret <= length); if (0 == ret) return 0; string += ret; + length -= ret; } return 1; @@ -118,7 +122,7 @@ char *utf8StrToLatin1Dup(const char *utf8) size_t len = 0; while (*utf8) { - count = validateUtf8Char(utf8); + count = validateUtf8Char(utf8, INT_MAX); if (!count) { free(ret); return NULL; @@ -140,7 +144,7 @@ char *utf8_to_latin1(char *dest, const char *utf8) size_t len = 0; while (*utf8) { - count = validateUtf8Char(utf8); + count = validateUtf8Char(utf8, INT_MAX); if (count) { *(cp++) = utf8_to_latin1_char(utf8); utf8 += count; |