]> granicus.if.org Git - icu/commitdiff
ICU-21001 Fixing problems found by running valgrind.
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Tue, 3 Mar 2020 08:44:59 +0000 (00:44 -0800)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Thu, 5 Mar 2020 22:34:20 +0000 (14:34 -0800)
This makes fixes in order to run the icu4c tests (intltest, cintltst,
iotest, and icuinfo) cleanly under valgrind with --leak-check=full.

13 files changed:
icu4c/source/common/ucurr.cpp
icu4c/source/common/unames.cpp
icu4c/source/common/uresbund.cpp
icu4c/source/common/uscript.cpp
icu4c/source/i18n/calendar.cpp
icu4c/source/i18n/dtptngen.cpp
icu4c/source/i18n/gender.cpp
icu4c/source/i18n/name2uni.cpp
icu4c/source/i18n/numsys.cpp
icu4c/source/test/intltest/dadrcal.cpp
icu4c/source/test/intltest/dadrfmt.cpp
icu4c/source/test/intltest/tztest.cpp
icu4c/source/tools/icuinfo/icuinfo.cpp

index dfee3bd300059568c2bc8aebd3d6d1c575447766..5eacc4a99bc03fedb3ad251231dc16f93f68fd87 100644 (file)
@@ -866,7 +866,7 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_
     *total_currency_name_count = 0;
     *total_currency_symbol_count = 0;
     const UChar* s = NULL;
-    char locale[ULOC_FULLNAME_CAPACITY];
+    char locale[ULOC_FULLNAME_CAPACITY] = "";
     uprv_strcpy(locale, loc);
     const icu::Hashtable *currencySymbolsEquiv = getCurrSymbolsEquiv();
     for (;;) {
@@ -941,7 +941,7 @@ collectCurrencyNames(const char* locale,
     // Look up the Currencies resource for the given locale.
     UErrorCode ec2 = U_ZERO_ERROR;
 
-    char loc[ULOC_FULLNAME_CAPACITY];
+    char loc[ULOC_FULLNAME_CAPACITY] = "";
     uloc_getName(locale, loc, sizeof(loc), &ec2);
     if (U_FAILURE(ec2) || ec2 == U_STRING_NOT_TERMINATED_WARNING) {
         ec = U_ILLEGAL_ARGUMENT_ERROR;
index cde8b5ad7e51d4366ffe3469eb5dea2c5a428c21..5776058f957f40f8762474be06de08104730de4c 100644 (file)
@@ -1519,7 +1519,8 @@ U_CAPI UChar32 U_EXPORT2
 u_charFromName(UCharNameChoice nameChoice,
                const char *name,
                UErrorCode *pErrorCode) {
-    char upper[120], lower[120];
+    char upper[120] = {0};
+    char lower[120] = {0};
     FindName findName;
     AlgorithmicRange *algRange;
     uint32_t *p;
index 6c0e760389d7536b3121d11e421e1c3bc056f28f..97df4a85ebe1c2fb16492d0fec0810754f59f9d7 100644 (file)
@@ -2611,8 +2611,8 @@ ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
     char defVal[1024] = ""; /* default value for given locale */
     char defLoc[1024] = ""; /* default value for given locale */
     char base[1024] = ""; /* base locale */
-    char found[1024];
-    char parent[1024];
+    char found[1024] = "";
+    char parent[1024] = "";
     char full[1024] = "";
     UResourceBundle bund1, bund2;
     UResourceBundle *res = NULL;
index 98528c158b4387d2e347d750396516375e89a045..f8bd7e7fdd1ae25943159145af4b9406049aac04 100644 (file)
@@ -58,8 +58,8 @@ static int32_t
 getCodesFromLocale(const char *locale,
                    UScriptCode *scripts, int32_t capacity, UErrorCode *err) {
     UErrorCode internalErrorCode = U_ZERO_ERROR;
-    char lang[8];
-    char script[8];
+    char lang[8] = {0};
+    char script[8] = {0};
     int32_t scriptLength;
     if(U_FAILURE(*err)) { return 0; }
     // Multi-script languages, equivalent to the LocaleScript data
index c043bb31861ad86ebb82d54904e16a2c8b2e7ece..981f09c574065703c2f12c7e450e2e68bb675575 100644 (file)
@@ -958,7 +958,7 @@ Calendar::makeInstance(const Locale& aLocale, UErrorCode& success) {
 #endif
         c->setWeekData(aLocale, c->getType(), success);  // set the correct locale (this was an indirected calendar)
 
-        char keyword[ULOC_FULLNAME_CAPACITY];
+        char keyword[ULOC_FULLNAME_CAPACITY] = "";
         UErrorCode tmpStatus = U_ZERO_ERROR;
         l.getKeywordValue("calendar", keyword, ULOC_FULLNAME_CAPACITY, tmpStatus);
         if (U_SUCCESS(tmpStatus) && uprv_strcmp(keyword, "iso8601") == 0) {
index af92b785680dc1e37d52f2a5e2826a43362eb66d..4d4a3e5b2675696a5ff90135eee45d7052af1ea9 100644 (file)
@@ -324,6 +324,7 @@ DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) {
 DateTimePatternGenerator::DateTimePatternGenerator(UErrorCode &status) :
     skipMatcher(nullptr),
     fAvailableFormatKeyHash(nullptr),
+    fDefaultHourFormatChar(0),
     internalErrorCode(U_ZERO_ERROR)
 {
     fp = new FormatParser();
@@ -338,6 +339,7 @@ DateTimePatternGenerator::DateTimePatternGenerator(UErrorCode &status) :
 DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorCode &status) :
     skipMatcher(nullptr),
     fAvailableFormatKeyHash(nullptr),
+    fDefaultHourFormatChar(0),
     internalErrorCode(U_ZERO_ERROR)
 {
     fp = new FormatParser();
@@ -356,6 +358,7 @@ DateTimePatternGenerator::DateTimePatternGenerator(const DateTimePatternGenerato
     UObject(),
     skipMatcher(nullptr),
     fAvailableFormatKeyHash(nullptr),
+    fDefaultHourFormatChar(0),
     internalErrorCode(U_ZERO_ERROR)
 {
     fp = new FormatParser();
@@ -1639,7 +1642,7 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
                             && (typeValue!= UDATPG_YEAR_FIELD || reqFieldChar==CAP_Y))
                             ? reqFieldChar
                             : field.charAt(0);
-                    if (typeValue == UDATPG_HOUR_FIELD) {
+                    if (typeValue == UDATPG_HOUR_FIELD && fDefaultHourFormatChar != 0) {
                         // The adjustment here is required to match spec (https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-hour).
                         // It is necessary to match the hour-cycle preferred by the Locale.
                         // Given that, we need to do the following adjustments:
index 32ddbf9a667a7a2536be2ca80fba081bf1a7ecbc..dc5def6ad350974267337344073cbf9c2e49479e 100644 (file)
@@ -160,7 +160,7 @@ const GenderInfo* GenderInfo::loadInstance(const Locale& locale, UErrorCode& sta
   if (s == NULL) {
     return &gObjs[NEUTRAL];
   }
-  char type_str[256];
+  char type_str[256] = "";
   u_UCharsToChars(s, type_str, resLen + 1);
   if (uprv_strcmp(type_str, gNeutralStr) == 0) {
     return &gObjs[NEUTRAL];
index 52bab80e3dad653160fb5dcf2d46d432a94a5bcf..dcf8d852e2c20e5544c4feede8c964009110e55a 100644 (file)
@@ -190,6 +190,7 @@ void NameUnicodeTransliterator::handleTransliterate(Replaceable& text, UTransPos
                 }
 
                 if (uprv_isInvariantUString(name.getBuffer(), len)) {
+                    cbuf[0] = 0;
                     name.extract(0, len, cbuf, maxLen, US_INV);
 
                     UErrorCode status = U_ZERO_ERROR;
index ee530e8d333b6bd22ed1d91dfef32f7f31a10801..62d555aad282dcb8973fcb0b4a94e5c2d8bc2955 100644 (file)
@@ -118,7 +118,7 @@ NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) {
 
     UBool nsResolved = TRUE;
     UBool usingFallback = FALSE;
-    char buffer[ULOC_KEYWORDS_CAPACITY];
+    char buffer[ULOC_KEYWORDS_CAPACITY] = "";
     int32_t count = inLocale.getKeywordValue("numbers", buffer, sizeof(buffer), status);
     if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
         // the "numbers" keyword exceeds ULOC_KEYWORDS_CAPACITY; ignore and use default.
index 08c9cec95c320347afc7815c9fd50727f88bf7c9..c74f387714d42f6437d12feb6802c8c970d1b63f 100644 (file)
@@ -448,7 +448,7 @@ void DataDrivenCalendarTest::processTest(TestData *testData) {
     //Calendar *cal= NULL;
     //const UChar *arguments= NULL;
     //int32_t argLen = 0;
-    char testType[256];
+    char testType[256] = "";
     const DataMap *settings= NULL;
     //const UChar *type= NULL;
     UErrorCode status = U_ZERO_ERROR;
index a382bd5ec366d45fe497847d86f43e087e3c272c..bff134a2662866d623a867ae8b2b91b84710347e 100644 (file)
@@ -330,7 +330,7 @@ void DataDrivenFormatTest::processTest(TestData *testData) {
     //Format *cal= NULL;
     //const UChar *arguments= NULL;
     //int32_t argLen = 0;
-    char testType[256];
+    char testType[256] = "";
     const DataMap *settings= NULL;
     //const UChar *type= NULL;
     UErrorCode status = U_ZERO_ERROR;
index 9346610931c4c842b5b2c901b03aa9f48fc2c904..17492a7a13b93d534d5c7ed7319c7f806195cfcd 100644 (file)
@@ -537,7 +537,7 @@ TimeZoneTest::TestGetAvailableIDsNew()
     const UnicodeString *id1, *id2;
     UnicodeString canonicalID;
     UBool isSystemID;
-    char region[4];
+    char region[4] = {0};
     int32_t zoneCount;
 
     any = canonical = canonicalLoc = any_US = canonical_US = canonicalLoc_US = any_W5 = any_CA_W5 = any_US_E14 = NULL;
index fee17cf685c5de0d2d5cdc9e40ee3e6eb4082a33..934825924f56aa0b036aae1847011bd5452e3f53 100644 (file)
@@ -58,6 +58,12 @@ static void do_init() {
     }
 }
 
+static void do_cleanup() {
+  if (icuInitted) {
+    u_cleanup();
+    icuInitted = FALSE;
+  }
+}
 
 void cmd_millis()
 {
@@ -295,5 +301,7 @@ main(int argc, char* argv[]) {
       cmd_version(FALSE, errorCode);  /* at least print the version # */
     }
 
+    do_cleanup();
+
     return U_FAILURE(errorCode);
 }