Share

id3lib

Tracker: Patches

5 Unicode16 writing bug - ID: 1016290
Last Update: Comment added ( nobody )

Unicode16 writing bug, in src\io_helpers.cpp

Bug Description: Some Chinese encoded utf16
characters such as '21691' which should be
written '54BB' were being written 54FF because the '|
data[i+1];
' was ORing a negative number '-69' signed instead of
unsigned '187', casting the string to unsigned char fixes
the bug.

function:

size_t io::writeUnicodeText(ID3_Writer& writer, String
data, bool bom)

right code:

unsigned char *pdata = (unsigned char *)
data.c_str();
for (size_t i = 0; i < size; i += 2)
{
unicode_t ch = (pdata[i] << 8) |
pdata[i+1];
writer.writeChars((const unsigned
char*) &ch, 2);
}


wrong code:

for (size_t i = 0; i < size; i += 2)
{
unicode_t ch = (data[i] << 8) | data
[i+1];
writer.writeChars((const unsigned
char*) &ch, 2);
}


Spoon ( spoon- ) - 2004-08-25 21:17

5

Open

None

Nobody/Anonymous

None

None

Public


Comment ( 1 )




Date: 2006-12-09 14:49
Sender: nobody

Logged In: NO

I have used the following and it works too:

for (size_t i = 0; i < size; i += 2)
{
unicode_t ch = (static_cast<unsigned char>(data[i]) << 8) |
static_cast<unsigned char>(data[i+1]);
writer.writeChars((const unsigned char*) &ch, 2);
}



Log in to comment.

Attached File

No Files Currently Attached

Change

No changes have been made to this artifact.