]> granicus.if.org Git - icu/commitdiff
ICU-22206 Fix unsafe mix of UBool
authorFrank Tang <ftang@chromium.org>
Fri, 18 Nov 2022 04:49:37 +0000 (20:49 -0800)
committerFrank Yung-Fong Tang <ftang@google.com>
Fri, 18 Nov 2022 18:36:55 +0000 (10:36 -0800)
Fix "unsafe mix of type 'UBool' and type 'bool' in operation:

16 files changed:
icu4c/source/common/rbbiscan.cpp
icu4c/source/common/ucnvisci.cpp
icu4c/source/common/udata.cpp
icu4c/source/common/uidna.cpp
icu4c/source/common/uresbund.cpp
icu4c/source/common/usprep.cpp
icu4c/source/common/utext.cpp
icu4c/source/i18n/calendar.cpp
icu4c/source/i18n/dcfmtsym.cpp
icu4c/source/i18n/dtitvinf.cpp
icu4c/source/i18n/gregocal.cpp
icu4c/source/i18n/regexcmp.cpp
icu4c/source/i18n/search.cpp
icu4c/source/i18n/usearch.cpp
icu4c/source/i18n/uspoof_conf.cpp
icu4c/source/io/uscanf_p.cpp

index 8232bd94e4777ce46ba73775a2e596635b8f6cd8..87d31f8af403d4ac31a0360c653dd0e1675fa507 100644 (file)
@@ -918,7 +918,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
             //   Toggle quoting mode.
             //   Return either '('  or ')', because quotes cause a grouping of the quoted text.
             fQuoteMode = !fQuoteMode;
-            if (fQuoteMode == true) {
+            if (fQuoteMode) {
                 c.fChar = chLParen;
             } else {
                 c.fChar = chRParen;
index 4d747e1ff843ba201ce708c0b3e579d97d64a86a..839f7ff9c62e8b206681386e61405071822aa739 100644 (file)
@@ -1472,7 +1472,7 @@ UConverter_toUnicode_ISCII_OFFSETS_LOGIC(UConverterToUnicodeArgs *args, UErrorCo
             if (targetUniChar != missingCharMarker) {
                 /* now save the targetUniChar for delayed write */
                 *toUnicodeStatus = (UChar) targetUniChar;
-                if (data->resetToDefaultToUnicode==true) {
+                if (data->resetToDefaultToUnicode) {
                     data->currentDeltaToUnicode = data->defDeltaToUnicode;
                     data->currentMaskToUnicode = data->defMaskToUnicode;
                     data->resetToDefaultToUnicode=false;
index 2bc74c97898c886182277ccfd1873bd047e5090c..c5d0a9feb7b5987693c44b008f4b8cb86a037d12 100644 (file)
@@ -568,7 +568,7 @@ const char *UDataPathIterator::next(UErrorCode *pErrorCode)
         /* check for .dat files */
         pathBasename = findBasename(pathBuffer.data());
 
-        if(checkLastFour == true && 
+        if(checkLastFour && 
            (pathLen>=4) &&
            uprv_strncmp(pathBuffer.data() +(pathLen-4), suffix.data(), 4)==0 && /* suffix matches */
            uprv_strncmp(findBasename(pathBuffer.data()), basename, basenameLen)==0  && /* base matches */
index 1cbdeec32727949913b21e9e0f140692b49de37a..7135a166f218dfb20312691e0452052df0ee1c3a 100644 (file)
@@ -287,7 +287,7 @@ _internal_toASCII(const UChar* src, int32_t srcLength,
             failPos = j;
         }
     }
-    if(useSTD3ASCIIRules == true){
+    if(useSTD3ASCIIRules){
         // verify 3a and 3b
         // 3(a) Verify the absence of non-LDH ASCII code points; that is, the
         //  absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.
@@ -731,7 +731,7 @@ uidna_IDNToASCII(  const UChar *src, int32_t srcLength,
             remainingDestCapacity = 0;
         }
 
-        if(done == true){
+        if(done){
             break;
         }
 
@@ -829,7 +829,7 @@ uidna_IDNToUnicode(  const UChar* src, int32_t srcLength,
             remainingDestCapacity = 0;
         }
 
-        if(done == true){
+        if(done){
             break;
         }
 
index 81fb90e138464fafb99c4bdde4c2b8930c2c3ba2..b0beae76cd5603b75d05ed35d442c8a45122c59e 100644 (file)
@@ -2449,7 +2449,7 @@ U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, con
         res = res_getTableItemByKey(&resB->getResData(), resB->fRes, &t, &key);
         if(res == RES_BOGUS) {
             key = inKey;
-            if(resB->fHasFallback == true) {
+            if(resB->fHasFallback) {
                 dataEntry = getFallbackData(resB, &key, &res, status);
                 if(U_SUCCESS(*status)) {
                     /* check if resB->fResPath gives the right name here */
@@ -2504,7 +2504,7 @@ U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, c
 
         if(res == RES_BOGUS) {
             key = inKey;
-            if(resB->fHasFallback == true) {
+            if(resB->fHasFallback) {
                 dataEntry = getFallbackData(resB, &key, &res, status);
                 if(U_SUCCESS(*status)) {
                     switch (RES_GET_TYPE(res)) {
index 50d16081d1dd24ea1f3ac652968f09f4edb15f48..8175dc7fa8254d8cad40e9f04b7c2c06da3586e8 100644 (file)
@@ -160,7 +160,7 @@ usprep_internal_flushCache(UBool noRefCount){
         key  = (UStringPrepKey *) e->key.pointer;
 
         if ((noRefCount== false && profile->refCount == 0) || 
-             noRefCount== true) {
+             noRefCount) {
             deletedNum++;
             uhash_removeElement(SHARED_DATA_HASHTABLE, e);
 
@@ -746,16 +746,16 @@ usprep_prepare(   const UStringPrepProfile* profile,
             }
         }
     }
-    if(profile->checkBiDi == true){
+    if(profile->checkBiDi){
         // satisfy 2
-        if( leftToRight == true && rightToLeft == true){
+        if( leftToRight && rightToLeft){
             *status = U_STRINGPREP_CHECK_BIDI_ERROR;
             uprv_syntaxError(b2,(rtlPos>ltrPos) ? rtlPos : ltrPos, b2Len, parseError);
             return 0;
         }
 
         //satisfy 3
-        if( rightToLeft == true && 
+        if( rightToLeft && 
             !((firstCharDir == U_RIGHT_TO_LEFT || firstCharDir == U_RIGHT_TO_LEFT_ARABIC) &&
               (direction == U_RIGHT_TO_LEFT || direction == U_RIGHT_TO_LEFT_ARABIC))
            ){
index 548e6a60f31fdfca65d172c69d12ce108a7e65e4..89e3d669f6e60e36126257408e8b60104ca625c2 100644 (file)
@@ -223,7 +223,7 @@ utext_current32(UText *ut) {
             trail = ut->chunkContents[ut->chunkOffset];
         }
         UBool r = ut->pFuncs->access(ut, nativePosition, false);  // reverse iteration flag loads preceding chunk
-        U_ASSERT(r==true);
+        U_ASSERT(r);
         ut->chunkOffset = originalOffset;
         if(!r) {
             return U_SENTINEL;
index 6e2278ba686e7a525a42aaf319fc77bf975903db..0c736681248d31d4d8d1cc1eccc4b059962e84b3 100644 (file)
@@ -3508,7 +3508,7 @@ int32_t Calendar::handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t w
     switch(bestField) {
     case UCAL_WEEK_OF_YEAR:
         if(woy == 1) {
-            if(jan1InPrevYear == true) {
+            if(jan1InPrevYear) {
                 // the first week of January is in the previous year
                 // therefore WOY1 is always solidly within yearWoy
                 return yearWoy;
index 5d06c189fbef05884fb1306f1518ee7772cd505b..fa5920aaa50776c6846075903e9ca5b2776cd2c5 100644 (file)
@@ -329,11 +329,13 @@ struct CurrencySpacingSink : public ResourceSink {
         // both beforeCurrency and afterCurrency were found in CLDR.
         static const char* defaults[] = { "[:letter:]", "[:digit:]", " " };
         if (!hasBeforeCurrency || !hasAfterCurrency) {
-            for (UBool beforeCurrency = 0; beforeCurrency <= true; beforeCurrency++) {
-                for (int32_t pattern = 0; pattern < UNUM_CURRENCY_SPACING_COUNT; pattern++) {
-                    dfs.setPatternForCurrencySpacing((UCurrencySpacing)pattern,
-                        beforeCurrency, UnicodeString(defaults[pattern], -1, US_INV));
-                }
+            for (int32_t pattern = 0; pattern < UNUM_CURRENCY_SPACING_COUNT; pattern++) {
+                dfs.setPatternForCurrencySpacing((UCurrencySpacing)pattern,
+                    false, UnicodeString(defaults[pattern], -1, US_INV));
+            }
+            for (int32_t pattern = 0; pattern < UNUM_CURRENCY_SPACING_COUNT; pattern++) {
+                dfs.setPatternForCurrencySpacing((UCurrencySpacing)pattern,
+                    true, UnicodeString(defaults[pattern], -1, US_INV));
             }
         }
     }
index f5fb86ce581206ac06049bb03b370f1a62f2a329..0a30cf14419cb41e98cc74443cbfeaf16dfadf86 100644 (file)
@@ -504,7 +504,7 @@ DateIntervalInfo::setIntervalPatternInternally(const UnicodeString& skeleton,
     }
 
     patternsOfOneSkeleton[index] = intervalPattern;
-    if ( emptyHash == true ) {
+    if ( emptyHash ) {
         fIntervalPatterns->put(skeleton, patternsOfOneSkeleton, status);
     }
 }
@@ -748,7 +748,7 @@ U_CALLCONV dtitvinfHashTableValueComparator(UHashTok val1, UHashTok val2) {
     const UnicodeString* pattern2 = (UnicodeString*)val2.pointer;
     UBool ret = true;
     int8_t i;
-    for ( i = 0; i < DateIntervalInfo::kMaxIntervalPatternIndex && ret == true; ++i ) {
+    for ( i = 0; i < DateIntervalInfo::kMaxIntervalPatternIndex && ret ; ++i ) {
         ret = (pattern1[i] == pattern2[i]);
     }
     return ret;
index 882d25b4a2a1dfb1ee260494f85aa030f30ac5bb..0e00127e314a149157e0941e3a24226b1648aea2 100644 (file)
@@ -487,7 +487,7 @@ int32_t GregorianCalendar::handleComputeJulianDay(UCalendarDateFields bestField)
         // The following check handles portions of the cutover year BEFORE the
         // cutover itself happens.
         //if ((fIsGregorian==true) != (jd >= fCutoverJulianDay)) {  /*  cutoverJulianDay)) { */
-        if ((fIsGregorian==true) != (jd >= fCutoverJulianDay)) {  /*  cutoverJulianDay)) { */
+        if ((fIsGregorian) != (jd >= fCutoverJulianDay)) {  /*  cutoverJulianDay)) { */
 #if defined (U_DEBUG_CAL)
             fprintf(stderr, "%s:%d: jd [invert] %d\n", 
                 __FILE__, __LINE__, jd);
index 4b507002d63a40b20fc881a4ea036b9585381d68..adc8f700c7ff4be641e6c1fc22b359312944cdeb 100644 (file)
@@ -4065,7 +4065,7 @@ void RegexCompile::nextChar(RegexPatternChar &c) {
                 if (c.fChar == (UChar32)-1) {
                     break;     // End of Input
                 }
-                if  (c.fChar == chPound && fEOLComments == true) {
+                if  (c.fChar == chPound && fEOLComments) {
                     // Start of a comment.  Consume the rest of it, until EOF or a new line
                     for (;;) {
                         c.fChar = nextCharLL();
index 56d9b74409874ff80ec3c0521dde8f239672ee61..d55902bfa7b0de029cbe80e44b0079a2eb6c9d8c 100644 (file)
@@ -81,10 +81,9 @@ USearchAttributeValue SearchIterator::getAttribute(
 {
     switch (attribute) {
     case USEARCH_OVERLAP :
-        return (m_search_->isOverlap == true ? USEARCH_ON : USEARCH_OFF);
+        return (m_search_->isOverlap ? USEARCH_ON : USEARCH_OFF);
     case USEARCH_CANONICAL_MATCH :
-        return (m_search_->isCanonicalMatch == true ? USEARCH_ON : 
-                                                                USEARCH_OFF);
+        return (m_search_->isCanonicalMatch ? USEARCH_ON : USEARCH_OFF);
     case USEARCH_ELEMENT_COMPARISON :
         {
             int16_t value = m_search_->elementComparisonType;
@@ -242,7 +241,7 @@ int32_t SearchIterator::next(UErrorCode &status)
         int32_t matchindex  = m_search_->matchedIndex;
         int32_t     matchlength = m_search_->matchedLength;
         m_search_->reset = false;
-        if (m_search_->isForwardSearching == true) {
+        if (m_search_->isForwardSearching) {
             int32_t textlength = m_search_->textLength;
             if (offset == textlength || matchindex == textlength || 
                 (matchindex != USEARCH_DONE && 
@@ -295,7 +294,7 @@ int32_t SearchIterator::previous(UErrorCode &status)
         }
         
         int32_t matchindex = m_search_->matchedIndex;
-        if (m_search_->isForwardSearching == true) {
+        if (m_search_->isForwardSearching) {
             // switching direction. 
             // if matchedIndex == USEARCH_DONE, it means that either a 
             // setOffset has been called or that next ran off the text
index 0fecd709e74161c7dfb74db1e5e5a1356bd59533..39f76a1b98512d47ee994b12b1a545494cbed903 100644 (file)
@@ -819,11 +819,9 @@ U_CAPI USearchAttributeValue U_EXPORT2 usearch_getAttribute(
     if (strsrch) {
         switch (attribute) {
         case USEARCH_OVERLAP :
-            return (strsrch->search->isOverlap == true ? USEARCH_ON :
-                                                        USEARCH_OFF);
+            return (strsrch->search->isOverlap ? USEARCH_ON : USEARCH_OFF);
         case USEARCH_CANONICAL_MATCH :
-            return (strsrch->search->isCanonicalMatch == true ? USEARCH_ON :
-                                                               USEARCH_OFF);
+            return (strsrch->search->isCanonicalMatch ? USEARCH_ON : USEARCH_OFF);
         case USEARCH_ELEMENT_COMPARISON :
             {
                 int16_t value = strsrch->search->elementComparisonType;
@@ -1249,7 +1247,7 @@ U_CAPI int32_t U_EXPORT2 usearch_previous(UStringSearch *strsrch,
         }
 
         int32_t matchedindex = search->matchedIndex;
-        if (search->isForwardSearching == true) {
+        if (search->isForwardSearching) {
             // switching direction.
             // if matchedIndex == USEARCH_DONE, it means that either a
             // setOffset has been called or that next ran off the text
index 5ecc59c12a8c851b940e0156dfba73613d6cf887..376ac64e3ce2e1ea783f9c8af2311d571537ecd9 100644 (file)
@@ -407,7 +407,7 @@ void ConfusabledataBuilder::build(const char * confusables, int32_t confusablesL
 //
 void ConfusabledataBuilder::outputData(UErrorCode &status) {
 
-    U_ASSERT(fSpoofImpl->fSpoofData->fDataOwned == true);
+    U_ASSERT(fSpoofImpl->fSpoofData->fDataOwned);
 
     //  The Key Table
     //     While copying the keys to the runtime array,
index 9b27e2ebf8d44d124244a301e45b4a2c38f0910b..26a790dd9b6368fcc68fa214a81ca2cd2c69b181 100644 (file)
@@ -323,7 +323,7 @@ u_scanf_skip_leading_ws(UFILE   *input,
     UBool isNotEOF;
 
     /* skip all leading ws in the input */
-    while( ((isNotEOF = ufile_getch(input, &c)) == true) && (c == pad || u_isWhitespace(c)) )
+    while( ((isNotEOF = ufile_getch(input, &c))==(UBool)true) && (c == pad || u_isWhitespace(c)) )
     {
         count++;
     }
@@ -357,7 +357,7 @@ u_scanf_skip_leading_positive_sign(UFILE   *input,
 
         if (U_SUCCESS(localStatus)) {
             /* skip all leading ws in the input */
-            while( ((isNotEOF = ufile_getch(input, &c)) == true) && (count < symbolLen && c == plusSymbol[count]) )
+            while( ((isNotEOF = ufile_getch(input, &c))==(UBool)true) && (count < symbolLen && c == plusSymbol[count]) )
             {
                 count++;
             }
@@ -868,7 +868,7 @@ u_scanf_string_handler(UFILE        *input,
         return -1;
 
     while( (info->fWidth == -1 || count < info->fWidth) 
-        && ((isNotEOF = ufile_getch(input, &c)) == true)
+        && ((isNotEOF = ufile_getch(input, &c))==(UBool)true)
         && (!info->fIsString || (c != info->fPadChar && !u_isWhitespace(c))))
     {
 
@@ -959,7 +959,7 @@ u_scanf_ustring_handler(UFILE       *input,
     count = 0;
 
     while( (info->fWidth == -1 || count < info->fWidth)
-        && ((isNotEOF = ufile_getch(input, &c)) == true)
+        && ((isNotEOF = ufile_getch(input, &c))==(UBool)true)
         && (!info->fIsString || (c != info->fPadChar && !u_isWhitespace(c))))
     {
 
@@ -1262,7 +1262,7 @@ u_scanf_scanset_handler(UFILE       *input,
 
         /* grab characters one at a time and make sure they are in the scanset */
         while(chLeft > 0) {
-            if ( ((isNotEOF = ufile_getch32(input, &c)) == true) && uset_contains(scanset, c) ) {
+            if ( ((isNotEOF = ufile_getch32(input, &c))==(UBool)true) && uset_contains(scanset, c) ) {
                 readCharacter = true;
                 if (!info->fSkipArg) {
                     int32_t idx = 0;