From 01c3b54051a0df6b127ae164bb6cab98281d24eb Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Wed, 25 Sep 2024 18:26:20 +0000 Subject: [PATCH] ICU-22767 Fix GCC warning and turn warning to errors See #3129 --- .github/workflows/icu4c.yml | 4 +- icu4c/source/common/ucnvmbcs.cpp | 5 +-- icu4c/source/common/ucurr.cpp | 8 +--- icu4c/source/common/ushape.cpp | 5 +++ icu4c/source/i18n/calendar.cpp | 4 +- icu4c/source/i18n/formattedvalue.cpp | 8 ++++ icu4c/source/i18n/number_rounding.cpp | 16 ++++---- icu4c/source/i18n/number_skeletons.cpp | 9 +++++ icu4c/source/test/cintltst/cbiditst.c | 1 + icu4c/source/test/cintltst/custrtrn.c | 18 ++++----- icu4c/source/test/cintltst/hpmufn.c | 2 +- icu4c/source/test/cintltst/ucptrietest.c | 8 +++- .../source/test/cintltst/uformattedvaluetst.c | 6 +-- icu4c/source/test/intltest/rbbitst.cpp | 2 +- icu4c/source/test/intltest/restsnew.cpp | 2 +- icu4c/source/test/iotest/stream.cpp | 2 +- icu4c/source/tools/ctestfw/ctest.c | 4 +- .../tools/icuexportdata/icuexportdata.cpp | 6 +-- icu4c/source/tools/makeconv/genmbcs.cpp | 40 +++++++++---------- 19 files changed, 88 insertions(+), 62 deletions(-) diff --git a/.github/workflows/icu4c.yml b/.github/workflows/icu4c.yml index 06c9bc25a7be..3edb1bfc014a 100644 --- a/.github/workflows/icu4c.yml +++ b/.github/workflows/icu4c.yml @@ -67,6 +67,8 @@ jobs: - name: ICU4C with gcc env: + CXXFLAGS: -Wextra -Werror -Wno-return-local-addr + CFLAGS: -Werror PREFIX: /tmp/icu-prefix run: | mkdir build; @@ -915,4 +917,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: icuexportdata_output - path: icuexportdata_tag-goes-here.zip \ No newline at end of file + path: icuexportdata_tag-goes-here.zip diff --git a/icu4c/source/common/ucnvmbcs.cpp b/icu4c/source/common/ucnvmbcs.cpp index f5507043bf35..d65c28474616 100644 --- a/icu4c/source/common/ucnvmbcs.cpp +++ b/icu4c/source/common/ucnvmbcs.cpp @@ -3146,11 +3146,8 @@ ucnv_MBCSGetNextUChar(UConverterToUnicodeArgs *pArgs, if(c<0) { if(U_SUCCESS(*pErrorCode) && source==sourceLimit && lastSourcetoUBytes; cnv->toULength = static_cast(source - lastSource); - do { - *bytes++=*lastSource++; - } while(lastSourcetoUBytes, lastSource, cnv->toULength); *pErrorCode=U_TRUNCATED_CHAR_FOUND; } else if(U_FAILURE(*pErrorCode)) { /* callback(illegal) */ diff --git a/icu4c/source/common/ucurr.cpp b/icu4c/source/common/ucurr.cpp index 282199257376..9eceb43aeb37 100644 --- a/icu4c/source/common/ucurr.cpp +++ b/icu4c/source/common/ucurr.cpp @@ -372,12 +372,8 @@ struct CReg : public icu::UMemory { CReg(const char16_t* _iso, const char* _id) : next(nullptr) { - int32_t len = static_cast(uprv_strlen(_id)); - if (len > static_cast(sizeof(id) - 1)) { - len = (sizeof(id)-1); - } - uprv_strncpy(id, _id, len); - id[len] = 0; + uprv_strncpy(id, _id, sizeof(id)-1); + id[sizeof(id)-1] = 0; u_memcpy(iso, _iso, ISO_CURRENCY_CODE_LENGTH); iso[ISO_CURRENCY_CODE_LENGTH] = 0; } diff --git a/icu4c/source/common/ushape.cpp b/icu4c/source/common/ushape.cpp index 00125635cb26..b7946dc3ce03 100644 --- a/icu4c/source/common/ushape.cpp +++ b/icu4c/source/common/ushape.cpp @@ -28,6 +28,7 @@ #include "ubidi_props.h" #include "uassert.h" +#include /* * This implementation is designed for 16-bit Unicode strings. * The main assumption is that the Arabic characters and their @@ -747,6 +748,10 @@ handleGeneratedSpaces(char16_t *dest, int32_t sourceLength, } } + if (static_cast(sourceLength) + 1 > std::numeric_limits::max() / U_SIZEOF_UCHAR) { + *pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR; + return 0; + } tempbuffer = static_cast(uprv_malloc((sourceLength + 1) * U_SIZEOF_UCHAR)); /* Test for nullptr */ if(tempbuffer == nullptr) { diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 96247174f70d..e713fb0195ed 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -828,9 +828,9 @@ Calendar::operator=(const Calendar &right) fWeekendCease = right.fWeekendCease; fWeekendCeaseMillis = right.fWeekendCeaseMillis; fNextStamp = right.fNextStamp; - uprv_strncpy(validLocale, right.validLocale, sizeof(validLocale)); - uprv_strncpy(actualLocale, right.actualLocale, sizeof(actualLocale)); + uprv_strncpy(validLocale, right.validLocale, sizeof(validLocale)-1); validLocale[sizeof(validLocale)-1] = 0; + uprv_strncpy(actualLocale, right.actualLocale, sizeof(actualLocale)-1); actualLocale[sizeof(validLocale)-1] = 0; } diff --git a/icu4c/source/i18n/formattedvalue.cpp b/icu4c/source/i18n/formattedvalue.cpp index aacd6ac70e09..f2bfdda6e465 100644 --- a/icu4c/source/i18n/formattedvalue.cpp +++ b/icu4c/source/i18n/formattedvalue.cpp @@ -193,6 +193,11 @@ ucfpos_close(UConstrainedFieldPosition* ptr) { } +// -Wreturn-local-addr first found in https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Warning-Options.html#Warning-Options +#if U_GCC_MAJOR_MINOR >= 409 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-local-addr" +#endif U_CAPI const char16_t* U_EXPORT2 ufmtval_getString( const UFormattedValue* ufmtval, @@ -213,6 +218,9 @@ ufmtval_getString( // defined to return memory owned by the ufmtval argument. return readOnlyAlias.getBuffer(); } +#if U_GCC_MAJOR_MINOR >= 409 +#pragma GCC diagnostic pop +#endif U_CAPI UBool U_EXPORT2 diff --git a/icu4c/source/i18n/number_rounding.cpp b/icu4c/source/i18n/number_rounding.cpp index 8f1aa453ada4..0f3975393c58 100644 --- a/icu4c/source/i18n/number_rounding.cpp +++ b/icu4c/source/i18n/number_rounding.cpp @@ -278,23 +278,23 @@ Precision IncrementPrecision::withMinFraction(int32_t minFrac) const { } FractionPrecision Precision::constructFraction(int32_t minFrac, int32_t maxFrac) { - FractionSignificantSettings settings; + FractionSignificantSettings settings{}; settings.fMinFrac = static_cast(minFrac); settings.fMaxFrac = static_cast(maxFrac); settings.fMinSig = -1; settings.fMaxSig = -1; - PrecisionUnion union_; + PrecisionUnion union_{}; union_.fracSig = settings; return {RND_FRACTION, union_}; } Precision Precision::constructSignificant(int32_t minSig, int32_t maxSig) { - FractionSignificantSettings settings; + FractionSignificantSettings settings{}; settings.fMinFrac = -1; settings.fMaxFrac = -1; settings.fMinSig = static_cast(minSig); settings.fMaxSig = static_cast(maxSig); - PrecisionUnion union_; + PrecisionUnion union_{}; union_.fracSig = settings; return {RND_SIGNIFICANT, union_}; } @@ -311,20 +311,20 @@ Precision::constructFractionSignificant( settings.fMaxSig = static_cast(maxSig); settings.fPriority = priority; settings.fRetain = retain; - PrecisionUnion union_; + PrecisionUnion union_{}; union_.fracSig = settings; return {RND_FRACTION_SIGNIFICANT, union_}; } IncrementPrecision Precision::constructIncrement(uint64_t increment, digits_t magnitude) { - IncrementSettings settings; + IncrementSettings settings{}; // Note: For number formatting, fIncrement is used for RND_INCREMENT but not // RND_INCREMENT_ONE or RND_INCREMENT_FIVE. However, fIncrement is used in all // three when constructing a skeleton. settings.fIncrement = increment; settings.fIncrementMagnitude = magnitude; settings.fMinFrac = magnitude > 0 ? 0 : -magnitude; - PrecisionUnion union_; + PrecisionUnion union_{}; union_.increment = settings; if (increment == 1) { // NOTE: In C++, we must return the correct value type with the correct union. @@ -339,7 +339,7 @@ IncrementPrecision Precision::constructIncrement(uint64_t increment, digits_t ma } CurrencyPrecision Precision::constructCurrency(UCurrencyUsage usage) { - PrecisionUnion union_; + PrecisionUnion union_{}; union_.currencyUsage = usage; return {RND_CURRENCY, union_}; } diff --git a/icu4c/source/i18n/number_skeletons.cpp b/icu4c/source/i18n/number_skeletons.cpp index 562a8663d057..67a38dad0737 100644 --- a/icu4c/source/i18n/number_skeletons.cpp +++ b/icu4c/source/i18n/number_skeletons.cpp @@ -1015,6 +1015,12 @@ blueprint_helpers::parseExponentSignOption(const StringSegment& segment, MacroPr return true; } +// The function is called by skeleton::parseOption which called by skeleton::parseSkeleton +// the data pointed in the return macros.unit is stack allocated in the parseSkeleton function. +#if U_GCC_MAJOR_MINOR >= 1204 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-pointer" +#endif void blueprint_helpers::parseCurrencyOption(const StringSegment& segment, MacroProps& macros, UErrorCode& status) { // Unlike ICU4J, have to check length manually because ICU4C CurrencyUnit does not check it for us @@ -1034,6 +1040,9 @@ void blueprint_helpers::parseCurrencyOption(const StringSegment& segment, MacroP // Slicing is OK macros.unit = currency; // NOLINT } +#if U_GCC_MAJOR_MINOR >= 1204 +#pragma GCC diagnostic pop +#endif void blueprint_helpers::generateCurrencyOption(const CurrencyUnit& currency, UnicodeString& sb, UErrorCode&) { diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c index 8b0a01057045..ee80366090aa 100644 --- a/icu4c/source/test/cintltst/cbiditst.c +++ b/icu4c/source/test/cintltst/cbiditst.c @@ -4730,6 +4730,7 @@ checkMaps(UBiDi *pBiDi, int32_t stringIndex, const char *src, const char *dest, ); testOK = false; } + memset(getIndexMap, 0, sizeof(getIndexMap)); for (i = 0; i < srcLen; i++) { idx = ubidi_getVisualIndex(pBiDi, i, &rc); assertSuccessful("ubidi_getVisualIndex", &rc); diff --git a/icu4c/source/test/cintltst/custrtrn.c b/icu4c/source/test/cintltst/custrtrn.c index 7987dacc9ff6..6a7890baec35 100644 --- a/icu4c/source/test/cintltst/custrtrn.c +++ b/icu4c/source/test/cintltst/custrtrn.c @@ -1527,7 +1527,7 @@ static void Test_strToJavaModifiedUTF8(void) { 0xee, 0x80, 0x81, 0xee, 0x80, 0x82, 0xee, 0x80, 0x83, 0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xb0, 0x80, 0xed, 0xa0, 0x80, 0xc0, 0x80, 0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf, - 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0xc3, 0xad, 0xe0, 0xb8, 0x8e, 0x6f + 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0xc3, 0xad, 0xe0, 0xb8, 0x8e, 0x6f, 0 }; static const UChar shortSrc[]={ 0xe01, 0xe1, 0x61 @@ -1554,7 +1554,7 @@ static void Test_strToJavaModifiedUTF8(void) { p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), &length, src, UPRV_LENGTHOF(src), &errorCode); if( U_FAILURE(errorCode) || p!=dest || - length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || + length!=(UPRV_LENGTHOF(expected)-1) || 0!=memcmp(dest, expected, length) || dest[length]!=0 ) { log_err("u_strToJavaModifiedUTF8(normal) failed - %s\n", u_errorName(errorCode)); @@ -1565,18 +1565,18 @@ static void Test_strToJavaModifiedUTF8(void) { p=u_strToJavaModifiedUTF8(dest, (int32_t)sizeof(dest), NULL, src, UPRV_LENGTHOF(src), &errorCode); if( U_FAILURE(errorCode) || p!=dest || - 0!=memcmp(dest, expected, UPRV_LENGTHOF(expected)) || - dest[UPRV_LENGTHOF(expected)]!=0 + 0!=memcmp(dest, expected, (UPRV_LENGTHOF(expected)-1)) || + dest[(UPRV_LENGTHOF(expected)-1)]!=0 ) { log_err("u_strToJavaModifiedUTF8(normal, pLength=NULL) failed - %s\n", u_errorName(errorCode)); } memset(dest, 0xff, sizeof(dest)); errorCode=U_ZERO_ERROR; length=-5; - p=u_strToJavaModifiedUTF8(dest, UPRV_LENGTHOF(expected), &length, + p=u_strToJavaModifiedUTF8(dest, (UPRV_LENGTHOF(expected)-1), &length, src, UPRV_LENGTHOF(src), &errorCode); if( errorCode!=U_STRING_NOT_TERMINATED_WARNING || p!=dest || - length!=UPRV_LENGTHOF(expected) || 0!=memcmp(dest, expected, length) || + length!=(UPRV_LENGTHOF(expected)-1) || 0!=memcmp(dest, expected, length) || dest[length]!=(char)0xff ) { log_err("u_strToJavaModifiedUTF8(tight) failed - %s\n", u_errorName(errorCode)); @@ -1604,10 +1604,10 @@ static void Test_strToJavaModifiedUTF8(void) { memset(dest, 0xff, sizeof(dest)); errorCode=U_ZERO_ERROR; length=-5; - p=u_strToJavaModifiedUTF8(dest, UPRV_LENGTHOF(expected)/2, &length, + p=u_strToJavaModifiedUTF8(dest, (UPRV_LENGTHOF(expected)-1)/2, &length, src, UPRV_LENGTHOF(src), &errorCode); if( errorCode!=U_BUFFER_OVERFLOW_ERROR || - length!=UPRV_LENGTHOF(expected) || dest[UPRV_LENGTHOF(expected)/2]!=(char)0xff + length!=(UPRV_LENGTHOF(expected)-1) || dest[(UPRV_LENGTHOF(expected)-1)/2]!=(char)0xff ) { log_err("u_strToJavaModifiedUTF8(overflow) failed - %s\n", u_errorName(errorCode)); } @@ -1617,7 +1617,7 @@ static void Test_strToJavaModifiedUTF8(void) { p=u_strToJavaModifiedUTF8(NULL, 0, &length, src, UPRV_LENGTHOF(src), &errorCode); if( errorCode!=U_BUFFER_OVERFLOW_ERROR || - length!=UPRV_LENGTHOF(expected) || dest[0]!=(char)0xff + length!=(UPRV_LENGTHOF(expected)-1) || dest[0]!=(char)0xff ) { log_err("u_strToJavaModifiedUTF8(pure preflighting) failed - %s\n", u_errorName(errorCode)); } diff --git a/icu4c/source/test/cintltst/hpmufn.c b/icu4c/source/test/cintltst/hpmufn.c index f27e57939959..959a4cbd8ba0 100644 --- a/icu4c/source/test/cintltst/hpmufn.c +++ b/icu4c/source/test/cintltst/hpmufn.c @@ -116,7 +116,7 @@ static void * U_CALLCONV myMemRealloc(const void *context, void *mem, size_t siz } retPtr = realloc(p, size+sizeof(ctest_AlignedMemory)); if (retPtr != NULL) { - p += sizeof(ctest_AlignedMemory); + retPtr += sizeof(ctest_AlignedMemory); } return retPtr; } diff --git a/icu4c/source/test/cintltst/ucptrietest.c b/icu4c/source/test/cintltst/ucptrietest.c index df32389bceec..ae5bc38e3b19 100644 --- a/icu4c/source/test/cintltst/ucptrietest.c +++ b/icu4c/source/test/cintltst/ucptrietest.c @@ -744,7 +744,13 @@ trieTestGolden(const char *testName, goto cleanup; } fseek(stream, 0, SEEK_SET); - fread(memoryBuffer, 1, fsize, stream); + long rsize = fread(memoryBuffer, 1, fsize, stream); + if (rsize != fsize) { + log_err( + "Golden files for '%s' fread %d bytes fail. Only get %d", + testName, fsize, rsize); + } + int32_t testResult = uprv_compareGoldenFiles( memoryBuffer, fsize, diff --git a/icu4c/source/test/cintltst/uformattedvaluetst.c b/icu4c/source/test/cintltst/uformattedvaluetst.c index edc745a3a888..ff7ca82452d9 100644 --- a/icu4c/source/test/cintltst/uformattedvaluetst.c +++ b/icu4c/source/test/cintltst/uformattedvaluetst.c @@ -144,13 +144,13 @@ static void AssertAllPartsEqual( UErrorCode status = U_ZERO_ERROR; char message[256]; - uprv_strncpy(message, messagePrefix, 256); + uprv_strncpy(message, messagePrefix, UPRV_LENGTHOF(message)-2); int32_t prefixEnd = (int32_t)uprv_strlen(messagePrefix); message[prefixEnd++] = ':'; message[prefixEnd++] = ' '; - U_ASSERT(prefixEnd < 256); + U_ASSERT(prefixEnd < UPRV_LENGTHOF(message)); -#define AAPE_MSG(suffix) (uprv_strncpy(message+prefixEnd, suffix, 256-prefixEnd)-prefixEnd) +#define AAPE_MSG(suffix) (uprv_strncpy(message+prefixEnd, suffix, UPRV_LENGTHOF(message)-prefixEnd)-prefixEnd) UFieldCategory _category = ucfpos_getCategory(ucfpos, &status); assertSuccess(AAPE_MSG("_"), &status); diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index 0ad50993b65f..1fe1cadcfb45 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -4584,7 +4584,7 @@ void RBBITest::RunMonkey(BreakIterator *bi, RBBIMonkeyKind &mk, const char *name UErrorCode status = U_ZERO_ERROR; u_charName(c, U_EXTENDED_CHAR_NAME, cName, sizeof(cName), &status); - char buffer[200]; + char buffer[280]; auto ret = snprintf(buffer, sizeof(buffer), "%4s %3i : %1s %1s %10s %-*s %-40s %-40s", currentLineFlag.c_str(), diff --git a/icu4c/source/test/intltest/restsnew.cpp b/icu4c/source/test/intltest/restsnew.cpp index a7bbf7717d9b..a8da3c437182 100644 --- a/icu4c/source/test/intltest/restsnew.cpp +++ b/icu4c/source/test/intltest/restsnew.cpp @@ -1489,7 +1489,7 @@ void NewResourceBundleTest::TestTrace() { assertEquals("Start position stability coverage", 0x3000, UTRACE_UDATA_START); - const void* context; + const void* context = nullptr; utrace_setFunctions(context, nullptr, nullptr, traceData); utrace_setLevel(UTRACE_VERBOSE); diff --git a/icu4c/source/test/iotest/stream.cpp b/icu4c/source/test/iotest/stream.cpp index 1b6303f1ee3e..907914daf3a5 100644 --- a/icu4c/source/test/iotest/stream.cpp +++ b/icu4c/source/test/iotest/stream.cpp @@ -76,7 +76,7 @@ static void U_CALLCONV TestStream() return; } ucnv_close(defConv); - strncpy(defConvName, ucnv_getDefaultName(), UPRV_LENGTHOF(defConvName)); + strncpy(defConvName, ucnv_getDefaultName(), UPRV_LENGTHOF(defConvName)-1); ucnv_setDefaultName("UTF-8"); static const char * const TESTSTRING = "\x20\x74\x48\x69\x73\xCE\xBC\xE2\x80\x82\x20\x6D\x75\x20\x77\x6F\x72\x6C\x64"; diff --git a/icu4c/source/tools/ctestfw/ctest.c b/icu4c/source/tools/ctestfw/ctest.c index 3ae9694a8308..7634526ad4e5 100644 --- a/icu4c/source/tools/ctestfw/ctest.c +++ b/icu4c/source/tools/ctestfw/ctest.c @@ -181,7 +181,9 @@ static TestNode *createTestNode(const char* name, int32_t nameLen) newNode->sibling = NULL; newNode->child = NULL; - strncpy( newNode->name, name, nameLen ); + if (nameLen > 0) { + strncpy( newNode->name, name, nameLen ); + } newNode->name[nameLen] = 0; return newNode; diff --git a/icu4c/source/tools/icuexportdata/icuexportdata.cpp b/icu4c/source/tools/icuexportdata/icuexportdata.cpp index 987a6bc7f6f8..0a96c9e0e62a 100644 --- a/icu4c/source/tools/icuexportdata/icuexportdata.cpp +++ b/icu4c/source/tools/icuexportdata/icuexportdata.cpp @@ -331,13 +331,13 @@ void dumpGeneralCategoryMask(FILE* f) { fprintf(f, "mask_for = \"General_Category\"\n"); - uint32_t minValue = u_getIntPropertyMinValue(UCHAR_GENERAL_CATEGORY); + int32_t minValue = u_getIntPropertyMinValue(UCHAR_GENERAL_CATEGORY); U_ASSERT(minValue >= 0); - uint32_t maxValue = u_getIntPropertyMaxValue(UCHAR_GENERAL_CATEGORY); + int32_t maxValue = u_getIntPropertyMaxValue(UCHAR_GENERAL_CATEGORY); U_ASSERT(maxValue >= 0); fprintf(f, "values = [\n"); - for (uint32_t v = minValue; v <= maxValue; v++) { + for (int32_t v = minValue; v <= maxValue; v++) { dumpValueEntry(uproperty, U_MASK(v), true, f); // We want to dump these masks "in order", which means they diff --git a/icu4c/source/tools/makeconv/genmbcs.cpp b/icu4c/source/tools/makeconv/genmbcs.cpp index 788fd9f75fb0..85fbcbd12e59 100644 --- a/icu4c/source/tools/makeconv/genmbcs.cpp +++ b/icu4c/source/tools/makeconv/genmbcs.cpp @@ -113,9 +113,9 @@ hexDigit(uint8_t digit) { } static inline char * -printBytes(char *buffer, const uint8_t *bytes, int32_t length) { +printBytes(char *buffer, size_t bufferLength, const uint8_t *bytes, int32_t length) { char *s=buffer; - while(length>0) { + while(length>0 && (static_cast(s-buffer) < bufferLength-3)) { *s++ = hexDigit(static_cast(*bytes >> 4)); *s++ = hexDigit(static_cast(*bytes & 0xf)); ++bytes; @@ -400,7 +400,7 @@ MBCSAddToUnicode(MBCSData *mbcsData, if(MBCS_ENTRY_IS_TRANSITION(entry)) { if(i==length) { fprintf(stderr, "error: byte sequence too short, ends in non-final state %hu: 0x%s (U+%x)\n", - static_cast(state), printBytes(buffer, bytes, length), static_cast(c)); + static_cast(state), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(c)); return false; } state = static_cast(MBCS_ENTRY_TRANSITION_STATE(entry)); @@ -408,21 +408,21 @@ MBCSAddToUnicode(MBCSData *mbcsData, } else { if(i(length - i), state, printBytes(buffer, bytes, length), static_cast(c)); + static_cast(length - i), state, printBytes(buffer, sizeof(buffer), bytes, length), static_cast(c)); return false; } switch(MBCS_ENTRY_FINAL_ACTION(entry)) { case MBCS_STATE_ILLEGAL: fprintf(stderr, "error: byte sequence ends in illegal state at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; case MBCS_STATE_CHANGE_ONLY: fprintf(stderr, "error: byte sequence ends in state-change-only at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; case MBCS_STATE_UNASSIGNED: fprintf(stderr, "error: byte sequence ends in unassigned state at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; case MBCS_STATE_FALLBACK_DIRECT_16: case MBCS_STATE_VALID_DIRECT_16: @@ -437,11 +437,11 @@ MBCSAddToUnicode(MBCSData *mbcsData, } if(flag>=0) { fprintf(stderr, "error: duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); return false; } else if(VERBOSE) { fprintf(stderr, "duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); } /* * Continue after the above warning @@ -467,16 +467,16 @@ MBCSAddToUnicode(MBCSData *mbcsData, if((old=mbcsData->unicodeCodeUnits[offset])!=0xfffe || (old=removeFallback(mbcsData, offset))!=-1) { if(flag>=0) { fprintf(stderr, "error: duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); return false; } else if(VERBOSE) { fprintf(stderr, "duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); } } if(c>=0x10000) { fprintf(stderr, "error: code point does not fit into valid-16-bit state at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; } if(flag>0) { @@ -505,11 +505,11 @@ MBCSAddToUnicode(MBCSData *mbcsData, } if(flag>=0) { fprintf(stderr, "error: duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(real)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(real)); return false; } else if(VERBOSE) { fprintf(stderr, "duplicate codepage byte sequence at U+%04x<->0x%s see U+%04x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(real)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(real)); } } if(flag>0) { @@ -543,7 +543,7 @@ MBCSAddToUnicode(MBCSData *mbcsData, default: /* reserved, must never occur */ fprintf(stderr, "internal error: byte sequence reached reserved action code, entry 0x%02x: 0x%s (U+%x)\n", - static_cast(entry), printBytes(buffer, bytes, length), static_cast(c)); + static_cast(entry), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(c)); return false; } @@ -699,7 +699,7 @@ MBCSAddFromUnicode(MBCSData *mbcsData, (!IGNORE_SISO_CHECK && (*bytes==0xe || *bytes==0xf)) ) { fprintf(stderr, "error: illegal mapping to SI or SO for SI/SO codepage: U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; } @@ -738,7 +738,7 @@ MBCSAddFromUnicode(MBCSData *mbcsData, if(newTop>MBCS_MAX_STAGE_2_TOP) { fprintf(stderr, "error: too many stage 2 entries at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; } @@ -786,7 +786,7 @@ MBCSAddFromUnicode(MBCSData *mbcsData, if (newTop > MBCS_STAGE_3_MBCS_SIZE * static_cast(maxCharLength)) { fprintf(stderr, "error: too many code points at U+%04x<->0x%s\n", - static_cast(c), printBytes(buffer, bytes, length)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length)); return false; } /* each block has 16*maxCharLength bytes */ @@ -881,11 +881,11 @@ MBCSAddFromUnicode(MBCSData *mbcsData, if((mbcsData->stage2[idx+(nextOffset>>MBCS_STAGE_2_SHIFT)]&(1UL<<(16+(c&0xf))))!=0 || old!=0) { if(flag>=0) { fprintf(stderr, "error: duplicate Unicode code point at U+%04x<->0x%s see 0x%02x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); return false; } else if(VERBOSE) { fprintf(stderr, "duplicate Unicode code point at U+%04x<->0x%s see 0x%02x\n", - static_cast(c), printBytes(buffer, bytes, length), static_cast(old)); + static_cast(c), printBytes(buffer, sizeof(buffer), bytes, length), static_cast(old)); } /* continue after the above warning if the precision of the mapping is unspecified */