From 96876653d9bc8ecc9bcb8161805db1b6cd064945 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 2 Dec 2010 19:17:46 +0000 Subject: [PATCH] ICU-8205 fix improper swap of uspoof, also add to swap test X-SVN-Rev: 29139 --- icu4c/source/i18n/uspoof_impl.cpp | 12 +++++++----- icu4c/source/i18n/uspoof_impl.h | 7 +++++-- icu4c/source/test/cintltst/udatatst.c | 4 ++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/icu4c/source/i18n/uspoof_impl.cpp b/icu4c/source/i18n/uspoof_impl.cpp index 3cc69b81aba..d8a0b9b3d5b 100644 --- a/icu4c/source/i18n/uspoof_impl.cpp +++ b/icu4c/source/i18n/uspoof_impl.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2008-2009, International Business Machines +* Copyright (C) 2008-2010, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -942,17 +942,19 @@ uspoof_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *ou // Script Sets. The data is an array of int32_t sectionStart = ds->readUInt32(spoofDH->fScriptSets); - sectionLength = ds->readUInt32(spoofDH->fScriptSetsLength) * 4; + sectionLength = ds->readUInt32(spoofDH->fScriptSetsLength) * sizeof(ScriptSet); ds->swapArray32(ds, inBytes+sectionStart, sectionLength, outBytes+sectionStart, status); // And, last, swap the header itself. // int32_t fMagic // swap this - // uint8_t fFormatVersion[4] // Do not swap this - // int32_t all the rest // Swap the rest, all is 32 bit stuff. + // uint8_t fFormatVersion[4] // Do not swap this, just copy + // int32_t fLength and all the rest // Swap the rest, all is 32 bit stuff. // uint32_t magic = ds->readUInt32(spoofDH->fMagic); ds->writeUInt32((uint32_t *)&outputDH->fMagic, magic); - ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8, &outputDH->fLength, status); + uprv_memcpy(outputDH->fFormatVersion, spoofDH->fFormatVersion, sizeof(spoofDH->fFormatVersion)); + // swap starting at fLength + ds->swapArray32(ds, &spoofDH->fLength, sizeof(SpoofDataHeader)-8 /* minus magic and fFormatVersion[4] */, &outputDH->fLength, status); return totalSize; } diff --git a/icu4c/source/i18n/uspoof_impl.h b/icu4c/source/i18n/uspoof_impl.h index 175e00ee924..750ef8017c5 100644 --- a/icu4c/source/i18n/uspoof_impl.h +++ b/icu4c/source/i18n/uspoof_impl.h @@ -1,6 +1,6 @@ /* *************************************************************************** -* Copyright (C) 2008-2009, International Business Machines Corporation +* Copyright (C) 2008-2010, International Business Machines Corporation * and others. All Rights Reserved. *************************************************************************** * @@ -22,6 +22,8 @@ #if !UCONFIG_NO_NORMALIZATION +#ifdef XP_CPLUSPLUS + U_NAMESPACE_BEGIN // The maximium length (in UTF-16 UChars) of the skeleton replacement string resulting from @@ -331,7 +333,7 @@ class SpoofData: public UMemory { // //--------------------------------------------------------------------------------------- struct SpoofDataHeader { - int32_t fMagic; // (0x8345fdef) + int32_t fMagic; // (0x3845fdef) uint8_t fFormatVersion[4]; // Data Format. Same as the value in struct UDataInfo // if there is one associated with this data. int32_t fLength; // Total lenght in bytes of this spoof data, @@ -395,6 +397,7 @@ struct SpoofDataHeader { U_NAMESPACE_END +#endif /* XP_CPLUSPLUS */ /** * Endianness swap function for binary spoof data. diff --git a/icu4c/source/test/cintltst/udatatst.c b/icu4c/source/test/cintltst/udatatst.c index 64bbe9f0f4d..a454245263d 100644 --- a/icu4c/source/test/cintltst/udatatst.c +++ b/icu4c/source/test/cintltst/udatatst.c @@ -55,6 +55,9 @@ #include "propname.h" #include "rbbidata.h" +/* swapping implementation in i18n */ +#include "uspoof_impl.h" + U_CAPI int32_t U_EXPORT2 unorm2_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, @@ -1330,6 +1333,7 @@ static const struct { #endif #if !UCONFIG_NO_NORMALIZATION {"nfc", "nrm", unorm2_swap}, + {"confusables", "cfu", uspoof_swap}, #endif {"unames", "icu", uchar_swapNames} };