From fcab06125025e86dbad42e49af1c0b5c2a3085fb Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 5 Sep 2007 06:27:59 +0000 Subject: [PATCH] Hopefully stop the crashes on database init on ARM (and SH1) targets when comment tags using UTF-16 are present. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14618 a1c6a512-1295-4272-9138-f99709370657 --- firmware/id3.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/firmware/id3.c b/firmware/id3.c index 8051e461f1..2a894aab10 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -512,16 +512,19 @@ static int unicode_len(char encoding, const void* string) int len = 0; if (encoding == 0x01 || encoding == 0x02) { - short* s = (short*) string; - - while (*s++) { - } - - len = (void*) s - string; + bool iswchar; + const char *s = string; + /* string might be unaligned, so using short* can crash on ARM and SH1 */ + do { + iswchar = (*s++ != 0); + iswchar |= (*s++ != 0); + } while (iswchar); + + len = s - (const char*) string; } else { len = strlen((char*) string) + 1; } - + return len; }