From 301814f85f06b20f311fd1fb82903cf9b0ebb932 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Fri, 10 Jan 2014 08:35:00 +0000 Subject: [PATCH] ICU-10624 Compiler warning cleanups, continued. X-SVN-Rev: 34855 --- icu4c/source/test/cintltst/capitst.c | 6 +-- icu4c/source/test/cintltst/ccapitst.c | 3 +- icu4c/source/test/cintltst/cdattst.c | 3 +- icu4c/source/test/cintltst/cloctst.c | 3 +- icu4c/source/test/cintltst/cnumtst.c | 3 +- icu4c/source/test/cintltst/custrtrn.c | 4 +- icu4c/source/test/intltest/caltest.cpp | 3 +- icu4c/source/test/intltest/dtfmttst.cpp | 60 ++++++++++++------------- icu4c/source/test/intltest/plurults.cpp | 4 +- icu4c/source/test/intltest/tufmtts.cpp | 6 ++- icu4c/source/tools/pkgdata/pkgdata.cpp | 4 +- 11 files changed, 53 insertions(+), 46 deletions(-) diff --git a/icu4c/source/test/cintltst/capitst.c b/icu4c/source/test/cintltst/capitst.c index c5097891b92..d4ca6d8d369 100644 --- a/icu4c/source/test/cintltst/capitst.c +++ b/icu4c/source/test/cintltst/capitst.c @@ -1,5 +1,5 @@ /******************************************************************** - * Copyright (c) 1997-2013, International Business Machines + * Copyright (c) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************/ /***************************************************************************** @@ -2417,10 +2417,10 @@ static void TestStrcollNull(void) { const UChar u16han[] = {0x5c71, 0x5ddd, 0}; const int32_t u16hanLen = 2; - const char u8asc[] = {0x49, 0x42, 0x4D, 0}; + const char *u8asc = "\x49\x42\x4D"; const int32_t u8ascLen = 3; - const char u8han[] = {0xE5, 0xB1, 0xB1, 0xE5, 0xB7, 0x9D, 0}; + const char *u8han = "\xE5\xB1\xB1\xE5\xB7\x9D"; const int32_t u8hanLen = 6; coll = ucol_open(NULL, &status); diff --git a/icu4c/source/test/cintltst/ccapitst.c b/icu4c/source/test/cintltst/ccapitst.c index fcedd9a3499..b238ee65d7c 100644 --- a/icu4c/source/test/cintltst/ccapitst.c +++ b/icu4c/source/test/cintltst/ccapitst.c @@ -837,7 +837,8 @@ static void TestConvert() /*Reads the BOM*/ - fread(&BOM, sizeof(UChar), 1, ucs_file_in); + size_t numRead = fread(&BOM, sizeof(UChar), 1, ucs_file_in); + (void)numRead; if (BOM!=0xFEFF && BOM!=0xFFFE) { log_err("File Missing BOM...Bailing!\n"); diff --git a/icu4c/source/test/cintltst/cdattst.c b/icu4c/source/test/cintltst/cdattst.c index a84bf96bb62..13ac0c52ecb 100644 --- a/icu4c/source/test/cintltst/cdattst.c +++ b/icu4c/source/test/cintltst/cdattst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2013, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -1492,6 +1492,7 @@ static void TestContext(void) { char bbuf1[kBbufMax]; char bbuf2[kBbufMax]; int32_t len = udat_format(udfmt, today, ubuf, kUbufMax, NULL, &status); + (void)len; if ( U_FAILURE(status) ) { log_err("FAIL: udat_format today for locale %s, capitalizationContext %d, status %s\n", textRelContextItemPtr->locale, (int)textRelContextItemPtr->capitalizationContext, u_errorName(status) ); diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 89b46ad4077..37f3c61b47a 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2013, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /***************************************************************************** @@ -1094,6 +1094,7 @@ static void TestDisplayNameBrackets() log_data_err("uldn_open fails for displayLocale %s, status=%s\n", itemPtr->displayLocale, u_errorName(status)); } #endif + (void)ulen; /* Suppress variable not used warning */ } } diff --git a/icu4c/source/test/cintltst/cnumtst.c b/icu4c/source/test/cintltst/cnumtst.c index 4a8f366d1db..202497eca09 100644 --- a/icu4c/source/test/cintltst/cnumtst.c +++ b/icu4c/source/test/cintltst/cnumtst.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2013, International Business Machines Corporation and + * Copyright (c) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -2339,6 +2339,7 @@ static void TestUNumberingSystem(void) { itemPtr->locale, itemPtr->numsys, itemPtr->radix, itemPtr->isAlgorithmic, numsys, radix, isAlgorithmic); } ulen = unumsys_getDescription(unumsys, ubuf, kNumSysDescripBufMax, &status); + (void)ulen; // Suppress variable not used warning. if ( U_FAILURE(status) || u_strcmp(ubuf, itemPtr->description) != 0 ) { log_data_err("unumsys description for locale %s, description unexpected and/or status %\n", myErrorName(status)); } diff --git a/icu4c/source/test/cintltst/custrtrn.c b/icu4c/source/test/cintltst/custrtrn.c index 847a1f2fe37..c30f76d487a 100644 --- a/icu4c/source/test/cintltst/custrtrn.c +++ b/icu4c/source/test/cintltst/custrtrn.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2001-2013, International Business Machines Corporation and + * Copyright (c) 2001-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** @@ -851,7 +851,7 @@ static void Test_UChar_UTF8_API(void){ * Test with an illegal lead byte that would be followed by more than 3 trail bytes. * See ticket #10371. */ - static const char src[1]={ 0xf8 }; + static const char src[1]={ (char)0xf8 }; UChar out16[10]; err=U_ZERO_ERROR; u_strFromUTF8(out16, LENGTHOF(out16), NULL, src, 1, &err); diff --git a/icu4c/source/test/intltest/caltest.cpp b/icu4c/source/test/intltest/caltest.cpp index 81842ae379a..5c30426e9bb 100644 --- a/icu4c/source/test/intltest/caltest.cpp +++ b/icu4c/source/test/intltest/caltest.cpp @@ -1,6 +1,6 @@ /************************************************************************ * COPYRIGHT: - * Copyright (c) 1997-2013, International Business Machines Corporation + * Copyright (c) 1997-2014, International Business Machines Corporation * and others. All Rights Reserved. ************************************************************************/ #include "unicode/utypes.h" @@ -2912,6 +2912,7 @@ void CalendarTest::TestHebrewMonthValidation() { // 5777 is NOT a lear year and does not have month Adar I pCal->set(5777, HebrewCalendar::ADAR_1, 1); d = pCal->getTime(status); + (void)d; if (status == U_ILLEGAL_ARGUMENT_ERROR) { logln("Info: U_ILLEGAL_ARGUMENT_ERROR, because 5777 Adar I 1 is not a valid date."); } else { diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index 5be24f0edf2..4bcf22dc557 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2013, International Business Machines + * Copyright (c) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************/ @@ -4218,38 +4218,38 @@ void DateFormatTest::TestDateFormatLeniency() { { NULL, true, UnicodeString(""), UnicodeString(""), UnicodeString("") } }; UErrorCode status = U_ZERO_ERROR; - Calendar* cal = Calendar::createInstance(status); + LocalPointer cal(Calendar::createInstance(status)); if (U_FAILURE(status)) { dataerrln(UnicodeString("FAIL: Unable to create Calendar for default timezone and locale.")); - } else { - cal->setTime(july022008, status); - const TestDateFormatLeniencyItem * itemPtr; - for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) { - - Locale locale = Locale::createFromName(itemPtr->locale); - status = U_ZERO_ERROR; - ParsePosition pos(0); - SimpleDateFormat * sdmft = new SimpleDateFormat(itemPtr->pattern, locale, status); - if (U_FAILURE(status)) { - dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status)); - continue; - } - sdmft->setLenient(itemPtr->leniency); - sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency, status).setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, status); - /*UDate d = */sdmft->parse(itemPtr->parseString, pos); - - delete sdmft; - if(pos.getErrorIndex() > -1) - if(itemPtr->expectedResult.length() != 0) { - errln("error: unexpected error - " + itemPtr->parseString + " - error index " + pos.getErrorIndex() + " - leniency " + itemPtr->leniency); - continue; - } else { - continue; - } - } + return; + } + cal->setTime(july022008, status); + const TestDateFormatLeniencyItem * itemPtr; + LocalPointer sdmft; + for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) { + + Locale locale = Locale::createFromName(itemPtr->locale); + status = U_ZERO_ERROR; + ParsePosition pos(0); + sdmft.adoptInstead(new SimpleDateFormat(itemPtr->pattern, locale, status)); + if (U_FAILURE(status)) { + dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status)); + continue; + } + sdmft->setLenient(itemPtr->leniency); + sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency, status). + setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, status); + UDate d = sdmft->parse(itemPtr->parseString, pos); + (void)d; + + // TODO: Ticket 10625. Nothing here is checking the expected result when the parse succeeds. + + if ((pos.getErrorIndex() > -1) && (itemPtr->expectedResult.length() != 0)) { + errln("error: unexpected error - " + itemPtr->parseString + + " - error index " + pos.getErrorIndex() + + " - leniency " + itemPtr->leniency); + } } - delete cal; - } #endif /* #if !UCONFIG_NO_FORMATTING */ diff --git a/icu4c/source/test/intltest/plurults.cpp b/icu4c/source/test/intltest/plurults.cpp index 9f8346cb756..8fce96f76db 100644 --- a/icu4c/source/test/intltest/plurults.cpp +++ b/icu4c/source/test/intltest/plurults.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 2007-2013, International Business Machines Corporation and +* Copyright (C) 2007-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************** @@ -224,7 +224,7 @@ void PluralRulesTest::testAPI(/*char *par*/) for (int32_t i=0; iselect(fData[i])== KEYWORD_A) != isKeywordA[i]) { errln("File %s, Line %d, ERROR: plural rules for decimal fractions test failed!\n" - " number = %g, expected %s", __FILE__, __LINE__, fData[i], isKeywordA?"TRUE":"FALSE"); + " number = %g, expected %s", __FILE__, __LINE__, fData[i], isKeywordA[i]?"TRUE":"FALSE"); } } diff --git a/icu4c/source/test/intltest/tufmtts.cpp b/icu4c/source/test/intltest/tufmtts.cpp index a1f4104c76e..ce1a9450320 100644 --- a/icu4c/source/test/intltest/tufmtts.cpp +++ b/icu4c/source/test/intltest/tufmtts.cpp @@ -1,5 +1,5 @@ /******************************************************************** - * Copyright (c) 2008-2013, International Business Machines Corporation and + * Copyright (c) 2008-2014, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -21,6 +21,8 @@ #include #endif +#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) + void TimeUnitTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) { if (exec) logln("TestSuite TimeUnitTest"); switch (index) { @@ -387,7 +389,7 @@ void TimeUnitTest::test10219Plurals() { dataerrln("generating NumberFormat Object failed: %s", u_errorName(status)); return; } - for (int32_t i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) { + for (int32_t i = 0; i < LENGTHOF(expected); ++i) { nf->setMaximumFractionDigits(i); nf->setRoundingMode(DecimalFormat::kRoundDown); tuf.setNumberFormat(*nf, status); diff --git a/icu4c/source/tools/pkgdata/pkgdata.cpp b/icu4c/source/tools/pkgdata/pkgdata.cpp index a7626336b53..d3c1eac5dea 100644 --- a/icu4c/source/tools/pkgdata/pkgdata.cpp +++ b/icu4c/source/tools/pkgdata/pkgdata.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2000-2013, International Business Machines + * Copyright (C) 2000-2014, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * file name: pkgdata.cpp @@ -1985,7 +1985,7 @@ static void loadLists(UPKGOptions *o, UErrorCode *status) if (cmdBuf[0] != 0) { uprv_strncat(cmdBuf, U_FILE_SEP_STRING, 1024); } - uprv_strncat(cmdBuf, cmd, 1024); + uprv_strncat(cmdBuf, cmd, 1023); if(verbose) { fprintf(stdout, "# Calling icu-config: %s\n", cmdBuf); -- 2.40.0