From 14b35e4fbf62b49613d0f7675b0605e2ca58e92e Mon Sep 17 00:00:00 2001 From: Jeff Genovy <29107334+jefgen@users.noreply.github.com> Date: Wed, 19 Sep 2018 10:05:27 -0700 Subject: [PATCH] ICU-20147 Fix MSVC warning C4251, and fix a few other warnings too. (#134) --- icu4c/source/common/locid.cpp | 12 +++++++----- icu4c/source/i18n/gregocal.cpp | 2 +- icu4c/source/i18n/gregoimp.h | 2 +- icu4c/source/i18n/number_types.h | 2 +- icu4c/source/io/ufmt_cmn.cpp | 2 +- icu4c/source/io/uprintf.cpp | 2 +- icu4c/source/io/ustream.cpp | 2 +- icu4c/source/tools/gencfu/gencfu.cpp | 2 +- icu4c/source/tools/gencnval/gencnval.c | 2 +- icu4c/source/tools/gensprep/gensprep.c | 2 +- icu4c/source/tools/pkgdata/pkgdata.cpp | 4 ++-- icu4c/source/tools/toolutil/filestrm.cpp | 4 ++-- icu4c/source/tools/toolutil/filetools.cpp | 2 +- icu4c/source/tools/toolutil/package.cpp | 4 ++-- icu4c/source/tools/toolutil/udbgutil.cpp | 6 +++--- 15 files changed, 26 insertions(+), 24 deletions(-) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 5e1942912e0..17f109dffe4 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -739,7 +739,7 @@ Locale::addLikelySubtags(UErrorCode& status) { // The maximized locale ID string is often longer, but there is no good // heuristic to estimate just how much longer. Leave that to CharString. CharString maximizedLocaleID; - int32_t maximizedLocaleIDCapacity = uprv_strlen(fullName); + int32_t maximizedLocaleIDCapacity = static_cast(uprv_strlen(fullName)); char* buffer; int32_t reslen; @@ -798,7 +798,7 @@ Locale::minimizeSubtags(UErrorCode& status) { // "en__POSIX"), minimized locale ID strings will be either the same length // or shorter than their input. CharString minimizedLocaleID; - int32_t minimizedLocaleIDCapacity = uprv_strlen(fullName); + int32_t minimizedLocaleIDCapacity = static_cast(uprv_strlen(fullName)); char* buffer; int32_t reslen; @@ -948,7 +948,7 @@ Locale::toLanguageTag(ByteSink& sink, UErrorCode& status) const // All simple language tags will have the exact same length as BCP-47 // strings as they have as ICU locale IDs (like "en-US" for "en_US"). LocalMemory scratch; - int32_t scratch_capacity = uprv_strlen(fullName); + int32_t scratch_capacity = static_cast(uprv_strlen(fullName)); if (scratch_capacity == 0) { scratch_capacity = 3; // "und" @@ -1320,7 +1320,9 @@ public: if (key == nullptr) { status = U_ILLEGAL_ARGUMENT_ERROR; } else { - if (resultLength != nullptr) *resultLength = uprv_strlen(key); + if (resultLength != nullptr) { + *resultLength = static_cast(uprv_strlen(key)); + } return key; } } @@ -1489,7 +1491,7 @@ Locale::getUnicodeKeywordValue(StringPiece keywordName, return; } - sink.Append(unicode_value, uprv_strlen(unicode_value)); + sink.Append(unicode_value, static_cast(uprv_strlen(unicode_value))); } void diff --git a/icu4c/source/i18n/gregocal.cpp b/icu4c/source/i18n/gregocal.cpp index a4a464626a8..71faeb09501 100644 --- a/icu4c/source/i18n/gregocal.cpp +++ b/icu4c/source/i18n/gregocal.cpp @@ -572,7 +572,7 @@ int32_t GregorianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, julianDay += isLeap?kLeapNumDays[month]:kNumDays[month]; } - return julianDay; + return static_cast(julianDay); } int32_t GregorianCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month) const diff --git a/icu4c/source/i18n/gregoimp.h b/icu4c/source/i18n/gregoimp.h index 4fd868f4150..06eb3238451 100644 --- a/icu4c/source/i18n/gregoimp.h +++ b/icu4c/source/i18n/gregoimp.h @@ -300,7 +300,7 @@ inline int32_t Grego::millisToJulianDay(double millis) { inline int32_t Grego::gregorianShift(int32_t eyear) { int64_t y = (int64_t)eyear-1; - int32_t gregShift = ClockMath::floorDivide(y, (int64_t)400) - ClockMath::floorDivide(y, (int64_t)100) + 2; + int32_t gregShift = static_cast(ClockMath::floorDivide(y, (int64_t)400) - ClockMath::floorDivide(y, (int64_t)100) + 2); return gregShift; } diff --git a/icu4c/source/i18n/number_types.h b/icu4c/source/i18n/number_types.h index 8e39936e4e1..00a6818869f 100644 --- a/icu4c/source/i18n/number_types.h +++ b/icu4c/source/i18n/number_types.h @@ -190,7 +190,7 @@ class U_I18N_API Modifier { * A fill-in for getParameters(). obj will always be set; if non-null, the other * two fields are also safe to read. */ - struct Parameters { + struct U_I18N_API Parameters { const ModifierStore* obj = nullptr; int8_t signum; StandardPlural::Form plural; diff --git a/icu4c/source/io/ufmt_cmn.cpp b/icu4c/source/io/ufmt_cmn.cpp index c539729b87a..0b6c18ff966 100644 --- a/icu4c/source/io/ufmt_cmn.cpp +++ b/icu4c/source/io/ufmt_cmn.cpp @@ -235,7 +235,7 @@ ufmt_defaultCPToUnicode(const char *s, int32_t sSize, return 0; if(sSize <= 0) { - sSize = uprv_strlen(s) + 1; + sSize = static_cast(uprv_strlen(s)) + 1; } /* perform the conversion in one swoop */ diff --git a/icu4c/source/io/uprintf.cpp b/icu4c/source/io/uprintf.cpp index d433707ded9..3c9effaadaf 100644 --- a/icu4c/source/io/uprintf.cpp +++ b/icu4c/source/io/uprintf.cpp @@ -183,7 +183,7 @@ u_vfprintf( UFILE *f, else { pattern = buffer; } - u_charsToUChars(patternSpecification, pattern, size); + u_charsToUChars(patternSpecification, pattern, static_cast(size)); /* do the work */ count = u_vfprintf_u(f, pattern, ap); diff --git a/icu4c/source/io/ustream.cpp b/icu4c/source/io/ustream.cpp index 948521a7fef..51676ea0f54 100644 --- a/icu4c/source/io/ustream.cpp +++ b/icu4c/source/io/ustream.cpp @@ -123,7 +123,7 @@ operator>>(STD_ISTREAM& stream, UnicodeString& str) /* Was the character consumed? */ if (us != uBuffer) { /* Reminder: ibm-1390 & JISX0213 can output 2 Unicode code points */ - int32_t uBuffSize = us-uBuffer; + int32_t uBuffSize = static_cast(us-uBuffer); int32_t uBuffIdx = 0; while (uBuffIdx < uBuffSize) { U16_NEXT(uBuffer, uBuffIdx, uBuffSize, ch32); diff --git a/icu4c/source/tools/gencfu/gencfu.cpp b/icu4c/source/tools/gencfu/gencfu.cpp index c4098c8cac3..1ac9ad3fd8a 100644 --- a/icu4c/source/tools/gencfu/gencfu.cpp +++ b/icu4c/source/tools/gencfu/gencfu.cpp @@ -319,7 +319,7 @@ int main(int argc, char **argv) { return NULL; } - long t = fread(result, 1, fileSize, file); + long t = static_cast(fread(result, 1, fileSize, file)); if (t != fileSize) { delete [] result; fclose(file); diff --git a/icu4c/source/tools/gencnval/gencnval.c b/icu4c/source/tools/gencnval/gencnval.c index 8d2a04c1ac7..04ad747e077 100644 --- a/icu4c/source/tools/gencnval/gencnval.c +++ b/icu4c/source/tools/gencnval/gencnval.c @@ -965,7 +965,7 @@ createNormalizedAliasStrings(char *normalizedStrings, const char *origStringBloc if (currStrLen > 0) { int32_t normStrLen; ucnv_io_stripForCompare(normalizedStrings, origStringBlock); - normStrLen = uprv_strlen(normalizedStrings); + normStrLen = (int32_t)uprv_strlen(normalizedStrings); if (normStrLen > 0) { uprv_memset(normalizedStrings + normStrLen, 0, currStrSize - normStrLen); } diff --git a/icu4c/source/tools/gensprep/gensprep.c b/icu4c/source/tools/gensprep/gensprep.c index e3466379e12..a9c9efac95b 100644 --- a/icu4c/source/tools/gensprep/gensprep.c +++ b/icu4c/source/tools/gensprep/gensprep.c @@ -355,7 +355,7 @@ strprepProfileLineFn(void *context, if (*s == '@') { /* special directive */ s++; - length = fields[0][1] - s; + length = (int32_t)(fields[0][1] - s); if (length >= NORMALIZE_DIRECTIVE_LEN && uprv_strncmp(s, NORMALIZE_DIRECTIVE, NORMALIZE_DIRECTIVE_LEN) == 0) { options[NORMALIZE].doesOccur = TRUE; diff --git a/icu4c/source/tools/pkgdata/pkgdata.cpp b/icu4c/source/tools/pkgdata/pkgdata.cpp index 942a55d77cc..b2cd0ab5eb9 100644 --- a/icu4c/source/tools/pkgdata/pkgdata.cpp +++ b/icu4c/source/tools/pkgdata/pkgdata.cpp @@ -511,7 +511,7 @@ main(int argc, char* argv[]) { static int runCommand(const char* command, UBool specialHandling) { char *cmd = NULL; char cmdBuffer[SMALL_BUFFER_MAX_SIZE]; - int32_t len = strlen(command); + int32_t len = static_cast(strlen(command)); if (len == 0) { return 0; @@ -1226,7 +1226,7 @@ static int32_t pkg_installFileMode(const char *installDir, const char *srcDir, c if (f != NULL) { for(;;) { if (T_FileStream_readLine(f, buffer, SMALL_BUFFER_MAX_SIZE) != NULL) { - bufferLength = uprv_strlen(buffer); + bufferLength = static_cast(uprv_strlen(buffer)); /* Remove new line character. */ if (bufferLength > 0) { buffer[bufferLength-1] = 0; diff --git a/icu4c/source/tools/toolutil/filestrm.cpp b/icu4c/source/tools/toolutil/filestrm.cpp index 2653747727f..a926848985a 100644 --- a/icu4c/source/tools/toolutil/filestrm.cpp +++ b/icu4c/source/tools/toolutil/filestrm.cpp @@ -104,14 +104,14 @@ T_FileStream_tmpfile() U_CAPI int32_t U_EXPORT2 T_FileStream_read(FileStream* fileStream, void* addr, int32_t len) { - return fread(addr, 1, len, (FILE*)fileStream); + return static_cast(fread(addr, 1, len, (FILE*)fileStream)); } U_CAPI int32_t U_EXPORT2 T_FileStream_write(FileStream* fileStream, const void* addr, int32_t len) { - return fwrite(addr, 1, len, (FILE*)fileStream); + return static_cast(fwrite(addr, 1, len, (FILE*)fileStream)); } U_CAPI void U_EXPORT2 diff --git a/icu4c/source/tools/toolutil/filetools.cpp b/icu4c/source/tools/toolutil/filetools.cpp index 176a791b0df..6e88c94b520 100644 --- a/icu4c/source/tools/toolutil/filetools.cpp +++ b/icu4c/source/tools/toolutil/filetools.cpp @@ -134,7 +134,7 @@ static int32_t whichFileModTimeIsLater(const char *file1, const char *file2) { /* Swap the file separater character given with the new one in the file path. */ U_CAPI void U_EXPORT2 swapFileSepChar(char *filePath, const char oldFileSepChar, const char newFileSepChar) { - for (int32_t i = 0, length = uprv_strlen(filePath); i < length; i++) { + for (int32_t i = 0, length = static_cast(uprv_strlen(filePath)); i < length; i++) { filePath[i] = (filePath[i] == oldFileSepChar ) ? newFileSepChar : filePath[i]; } } diff --git a/icu4c/source/tools/toolutil/package.cpp b/icu4c/source/tools/toolutil/package.cpp index d96c6dd36dd..f4e428a37e7 100644 --- a/icu4c/source/tools/toolutil/package.cpp +++ b/icu4c/source/tools/toolutil/package.cpp @@ -610,7 +610,7 @@ Package::readPackage(const char *filename) { memcpy(prefix, s, ++prefixLength); // include the / } else { // Use the package basename as prefix. - int32_t inPkgNameLength=strlen(inPkgName); + int32_t inPkgNameLength= static_cast(strlen(inPkgName)); memcpy(prefix, inPkgName, inPkgNameLength); prefixLength=inPkgNameLength; @@ -1043,7 +1043,7 @@ Package::addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOw memset(items+idx, 0, sizeof(Item)); // copy the item's name - items[idx].name=allocString(TRUE, strlen(name)); + items[idx].name=allocString(TRUE, static_cast(strlen(name))); strcpy(items[idx].name, name); pathToTree(items[idx].name); } else { diff --git a/icu4c/source/tools/toolutil/udbgutil.cpp b/icu4c/source/tools/toolutil/udbgutil.cpp index dcc80ebe069..285f68a0ec6 100644 --- a/icu4c/source/tools/toolutil/udbgutil.cpp +++ b/icu4c/source/tools/toolutil/udbgutil.cpp @@ -400,7 +400,7 @@ U_CAPI int32_t paramStatic(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { if(param->paramStr==NULL) return paramEmpty(param,target,targetCapacity,status); if(U_FAILURE(*status))return 0; - int32_t len = uprv_strlen(param->paramStr); + int32_t len = static_cast(uprv_strlen(param->paramStr)); if(target!=NULL) { uprv_strncpy(target,param->paramStr,uprv_min(len,targetCapacity)); } @@ -412,14 +412,14 @@ static const char *nullString = "(null)"; static int32_t stringToStringBuffer(char *target, int32_t targetCapacity, const char *str, UErrorCode *status) { if(str==NULL) str=nullString; - int32_t len = uprv_strlen(str); + int32_t len = static_cast(uprv_strlen(str)); if (U_SUCCESS(*status)) { if(target!=NULL) { uprv_strncpy(target,str,uprv_min(len,targetCapacity)); } } else { const char *s = u_errorName(*status); - len = uprv_strlen(s); + len = static_cast(uprv_strlen(s)); if(target!=NULL) { uprv_strncpy(target,s,uprv_min(len,targetCapacity)); } -- 2.40.0