зеркало из https://github.com/mozilla/gecko-dev.git
Bug 757366 - Don't cast pointers to 'name'-table data to uint16_t*, as they may not be 16-bit-aligned. r=jrmuizel
This commit is contained in:
Родитель
60fef630a5
Коммит
2a3be4b384
|
@ -918,16 +918,18 @@ IsValidSFNTVersion(uint32_t version)
|
||||||
version == TRUETYPE_TAG('t','r','u','e');
|
version == TRUETYPE_TAG('t','r','u','e');
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy and swap UTF-16 values, assume no surrogate pairs, can be in place
|
// Copy and swap UTF-16 values, assume no surrogate pairs, can be in place.
|
||||||
|
// aInBuf and aOutBuf are NOT necessarily 16-bit-aligned, so we should avoid
|
||||||
|
// accessing them directly as uint16_t* values.
|
||||||
|
// aLen is count of UTF-16 values, so the byte buffers are twice that.
|
||||||
static void
|
static void
|
||||||
CopySwapUTF16(const uint16_t *aInBuf, uint16_t *aOutBuf, uint32_t aLen)
|
CopySwapUTF16(const char* aInBuf, char* aOutBuf, uint32_t aLen)
|
||||||
{
|
{
|
||||||
const uint16_t *end = aInBuf + aLen;
|
const char* end = aInBuf + aLen * 2;
|
||||||
while (aInBuf < end) {
|
while (aInBuf < end) {
|
||||||
uint16_t value = *aInBuf;
|
uint8_t b0 = *aInBuf++;
|
||||||
*aOutBuf = (value >> 8) | (value & 0xff) << 8;
|
*aOutBuf++ = *aInBuf++;
|
||||||
aOutBuf++;
|
*aOutBuf++ = b0;
|
||||||
aInBuf++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1446,13 +1448,13 @@ gfxFontUtils::DecodeFontName(const char *aNameData, int32_t aByteLen,
|
||||||
if (csName[0] == 0) {
|
if (csName[0] == 0) {
|
||||||
// empty charset name: data is utf16be, no need to instantiate a converter
|
// empty charset name: data is utf16be, no need to instantiate a converter
|
||||||
uint32_t strLen = aByteLen / 2;
|
uint32_t strLen = aByteLen / 2;
|
||||||
#ifdef IS_LITTLE_ENDIAN
|
|
||||||
aName.SetLength(strLen);
|
aName.SetLength(strLen);
|
||||||
CopySwapUTF16(reinterpret_cast<const uint16_t*>(aNameData),
|
#ifdef IS_LITTLE_ENDIAN
|
||||||
reinterpret_cast<uint16_t*>(aName.BeginWriting()), strLen);
|
CopySwapUTF16(aNameData, reinterpret_cast<char*>(aName.BeginWriting()),
|
||||||
|
strLen);
|
||||||
#else
|
#else
|
||||||
aName.Assign(reinterpret_cast<const char16_t*>(aNameData), strLen);
|
memcpy(aName.BeginWriting(), aNameData, strLen * 2);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче