]> granicus.if.org Git - icu/commitdiff
ICU-20147 Fix MSVC warning C4251, and fix a few other warnings too. (#134)
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Wed, 19 Sep 2018 17:05:27 +0000 (10:05 -0700)
committerShane Carr <shane@unicode.org>
Thu, 27 Sep 2018 21:27:41 +0000 (14:27 -0700)
15 files changed:
icu4c/source/common/locid.cpp
icu4c/source/i18n/gregocal.cpp
icu4c/source/i18n/gregoimp.h
icu4c/source/i18n/number_types.h
icu4c/source/io/ufmt_cmn.cpp
icu4c/source/io/uprintf.cpp
icu4c/source/io/ustream.cpp
icu4c/source/tools/gencfu/gencfu.cpp
icu4c/source/tools/gencnval/gencnval.c
icu4c/source/tools/gensprep/gensprep.c
icu4c/source/tools/pkgdata/pkgdata.cpp
icu4c/source/tools/toolutil/filestrm.cpp
icu4c/source/tools/toolutil/filetools.cpp
icu4c/source/tools/toolutil/package.cpp
icu4c/source/tools/toolutil/udbgutil.cpp

index 5e1942912e04615436881a7faa7b46b7eaf3d287..17f109dffe419ee32592faff7c27ee3c6a94581d 100644 (file)
@@ -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<int32_t>(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<int32_t>(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<char> scratch;
-    int32_t scratch_capacity = uprv_strlen(fullName);
+    int32_t scratch_capacity = static_cast<int32_t>(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<int32_t>(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<int32_t>(uprv_strlen(unicode_value)));
 }
 
 void
index a4a464626a8690ae3a2ef9b762a5deff692b3bf4..71faeb095010b56f24640a4c2e2976fbf653f34c 100644 (file)
@@ -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<int32_t>(julianDay);
 }
 
 int32_t GregorianCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month)  const
index 4fd868f4150aafb45b3bfd5244ce3571422604d6..06eb32384511e48924b0b41acd00aeacd1ef213b 100644 (file)
@@ -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<int32_t>(ClockMath::floorDivide(y, (int64_t)400) - ClockMath::floorDivide(y, (int64_t)100) + 2);
   return gregShift;
 }
 
index 8e39936e4e1583b861b3174ed937c08ad4406d33..00a6818869fdc22d898912d9d928f396d1e7f9a4 100644 (file)
@@ -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;
index c539729b87abf9973b7d1fe8e0642ff8552511f5..0b6c18ff966178cba8d958eaadf09aeef325c9ff 100644 (file)
@@ -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<int32_t>(uprv_strlen(s)) + 1;
     }
     
     /* perform the conversion in one swoop */
index d433707ded9e58c4a4b808fe28ab23c6330bd325..3c9effaadaffc0584fdb307695c33c8e74700b75 100644 (file)
@@ -183,7 +183,7 @@ u_vfprintf(    UFILE        *f,
     else {
         pattern = buffer;
     }
-    u_charsToUChars(patternSpecification, pattern, size);
+    u_charsToUChars(patternSpecification, pattern, static_cast<int32_t>(size));
 
     /* do the work */
     count = u_vfprintf_u(f, pattern, ap);
index 948521a7fef3782951952464af71dcb253bf6d0c..51676ea0f545e910241c06c1fa3f0a60a5839f29 100644 (file)
@@ -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<int32_t>(us-uBuffer);
                 int32_t uBuffIdx = 0;
                 while (uBuffIdx < uBuffSize) {
                     U16_NEXT(uBuffer, uBuffIdx, uBuffSize, ch32);
index c4098c8cac3b50198c2e6780e5a525553a0f3c88..1ac9ad3fd8a39da4a74ba593d50dcb7f0bb1cc89 100644 (file)
@@ -319,7 +319,7 @@ int  main(int argc, char **argv) {
         return NULL;
     }
 
-    long t = fread(result, 1, fileSize, file);
+    long t = static_cast<long>(fread(result, 1, fileSize, file));
     if (t != fileSize)  {
         delete [] result;
         fclose(file);
index 8d2a04c1ac7db234b8ea84fa5d9c817ae6dd3255..04ad747e07721879ccafdff3b1aadb4153b1099c 100644 (file)
@@ -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);
             }
index e3466379e12934435974d09ebbe8f0791da3a2fb..a9c9efac95bfb580db8a4e7ef5557cf965fe61a0 100644 (file)
@@ -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;
index 942a55d77ccc309ad4fa2938c1ef95eca278627c..b2cd0ab5eb9709a5294f5c6226908dfdade105e7 100644 (file)
@@ -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<int32_t>(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<int32_t>(uprv_strlen(buffer));
                 /* Remove new line character. */
                 if (bufferLength > 0) {
                     buffer[bufferLength-1] = 0;
index 2653747727fd80004f95a078ce4dde3215738b53..a926848985a8e1edcbbf74e65f49d99c5f03c4da 100644 (file)
@@ -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<int32_t>(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<int32_t>(fwrite(addr, 1, len, (FILE*)fileStream));
 }
 
 U_CAPI void U_EXPORT2
index 176a791b0df853040d6c4291a01dbebb5b3cf79f..6e88c94b5200b5f6cee5d9819a74e4389a7a6869 100644 (file)
@@ -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<int32_t>(uprv_strlen(filePath)); i < length; i++) {
         filePath[i] = (filePath[i] == oldFileSepChar ) ? newFileSepChar : filePath[i];
     }
 }
index d96c6dd36ddb410237e36056291cb83844d86326..f4e428a37e7153f033c74a1a6f61db5b7093f303 100644 (file)
@@ -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<int32_t>(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<int32_t>(strlen(name)));
         strcpy(items[idx].name, name);
         pathToTree(items[idx].name);
     } else {
index dcc80ebe069519a49501753e8707cee7600043d9..285f68a0ec66a1607c64003d8b266583b4f8f0fb 100644 (file)
@@ -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<int32_t>(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<int32_t>(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<int32_t>(uprv_strlen(s));
     if(target!=NULL) {
       uprv_strncpy(target,s,uprv_min(len,targetCapacity));
     }