From 4cc513278c16a7e221a8dc114a8a5467493fef77 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 5 Nov 2004 17:21:42 +0000 Subject: [PATCH] ICU-3905 Fix some compiler warnings X-SVN-Rev: 16767 --- icu4c/source/common/uloc.c | 357 ++++++++++++------------ icu4c/source/test/cintltst/capitst.c | 4 +- icu4c/source/test/cintltst/cg7coll.c | 8 +- icu4c/source/test/cintltst/crestst.c | 4 +- icu4c/source/test/cintltst/cucdtst.c | 5 +- icu4c/source/test/cintltst/custrtrn.c | 4 +- icu4c/source/test/cintltst/custrtst.c | 2 +- icu4c/source/test/cintltst/uenumtst.c | 4 +- icu4c/source/test/intltest/loctest.cpp | 4 +- icu4c/source/test/intltest/restsnew.cpp | 4 +- icu4c/source/test/intltest/ucaconf.cpp | 2 +- 11 files changed, 200 insertions(+), 198 deletions(-) diff --git a/icu4c/source/common/uloc.c b/icu4c/source/common/uloc.c index c5f199d15c7..400031888f2 100644 --- a/icu4c/source/common/uloc.c +++ b/icu4c/source/common/uloc.c @@ -2776,36 +2776,36 @@ uloc_getISOCountries() } typedef struct { - float q; - char *locale; + float q; + char *locale; } _acceptLangItem; static int uloc_acceptLanguageCompare(const void *a, const void *b) { - const _acceptLangItem *aa = (const _acceptLangItem*)a; - const _acceptLangItem *bb = (const _acceptLangItem*)b; + const _acceptLangItem *aa = (const _acceptLangItem*)a; + const _acceptLangItem *bb = (const _acceptLangItem*)b; - int rc = 0; - if(bb->q < aa->q) { - rc = -1; /* A > B */ - } else if(bb->q > aa->q) { - rc = 1; /* A < B */ - } else { - rc = 0; /* A = B */ - } + int rc = 0; + if(bb->q < aa->q) { + rc = -1; /* A > B */ + } else if(bb->q > aa->q) { + rc = 1; /* A < B */ + } else { + rc = 0; /* A = B */ + } + + if(rc==0) { + rc = uprv_stricmp(aa->locale, bb->locale); + } - if(rc==0) { - rc = uprv_stricmp(aa->locale, bb->locale); - } - #if defined(ULOC_DEBUG) - /* fprintf(stderr, "a:[%s:%g], b:[%s:%g] -> %d\n", - aa->locale, aa->q, - bb->locale, bb->q, - rc);*/ + /* fprintf(stderr, "a:[%s:%g], b:[%s:%g] -> %d\n", + aa->locale, aa->q, + bb->locale, bb->q, + rc);*/ #endif - return rc; + return rc; } /* @@ -2814,92 +2814,92 @@ mt-mt, ja;q=0.76, en-us;q=0.95, en;q=0.92, en-gb;q=0.89, fr;q=0.87, iu-ca;q=0.84 U_CAPI int32_t U_EXPORT2 uloc_acceptLanguageFromHTTP(char *result, int32_t resultAvailable, UAcceptResult *outResult, - const char *httpAcceptLanguage, - UEnumeration* availableLocales, - UErrorCode *status) + const char *httpAcceptLanguage, + UEnumeration* availableLocales, + UErrorCode *status) { - _acceptLangItem j[200]; - char **strs; - char tmp[ULOC_FULLNAME_CAPACITY +1]; - int32_t n = 0; - const char *itemEnd; - const char *paramEnd; - const char *s; - const char *t; - int32_t res; - int32_t i; - int32_t l = uprv_strlen(httpAcceptLanguage); + _acceptLangItem j[200]; + char **strs; + char tmp[ULOC_FULLNAME_CAPACITY +1]; + int32_t n = 0; + const char *itemEnd; + const char *paramEnd; + const char *s; + const char *t; + int32_t res; + int32_t i; + int32_t l = uprv_strlen(httpAcceptLanguage); - if(U_FAILURE(*status)) { - return -1; - } + if(U_FAILURE(*status)) { + return -1; + } - for(s=httpAcceptLanguage;s&&*s;) { - while(isspace(*s)) /* eat space at the beginning */ - s++; - itemEnd=uprv_strchr(s,','); - paramEnd=uprv_strchr(s,';'); - if(!itemEnd) { - itemEnd = httpAcceptLanguage+l; /* end of string */ - } - if(paramEnd && paramEnds)&&isspace(*t);t--) - ; - j[n].locale = uprv_strndup(s,(t+1)-s); - uloc_canonicalize(j[n].locale,tmp,sizeof(tmp)/sizeof(tmp[0]),status); - if(strcmp(j[n].locale,tmp)) { - uprv_free(j[n].locale); - j[n].locale=uprv_strdup(tmp); - } + for(s=httpAcceptLanguage;s&&*s;) { + while(isspace(*s)) /* eat space at the beginning */ + s++; + itemEnd=uprv_strchr(s,','); + paramEnd=uprv_strchr(s,';'); + if(!itemEnd) { + itemEnd = httpAcceptLanguage+l; /* end of string */ + } + if(paramEnd && paramEnds)&&isspace(*t);t--) + ; + j[n].locale = uprv_strndup(s,(t+1)-s); + uloc_canonicalize(j[n].locale,tmp,sizeof(tmp)/sizeof(tmp[0]),status); + if(strcmp(j[n].locale,tmp)) { + uprv_free(j[n].locale); + j[n].locale=uprv_strdup(tmp); + } #if defined(ULOC_DEBUG) - /*fprintf(stderr,"%d: s <%s> q <%g>\n", n, j[n].locale, j[n].q);*/ + /*fprintf(stderr,"%d: s <%s> q <%g>\n", n, j[n].locale, j[n].q);*/ #endif - n++; - s = itemEnd; - while(*s==',') { /* eat duplicate commas */ - s++; + n++; + s = itemEnd; + while(*s==',') { /* eat duplicate commas */ + s++; + } + if(n>=(sizeof(j)/sizeof(j[0]))) { /* overflowed */ + *status = U_INTERNAL_PROGRAM_ERROR; + return -1; + } } - if(n>=(sizeof(j)/sizeof(j[0]))) { /* overflowed */ - *status = U_INTERNAL_PROGRAM_ERROR; - return -1; - } - } - qsort(j, n, sizeof(j[0]), uloc_acceptLanguageCompare); - strs = uprv_malloc((size_t)(sizeof(strs[0])*n)); - for(i=0;i q <%g>\n", i, j[i].locale, j[i].q);*/ + /*fprintf(stderr,"%d: s <%s> q <%g>\n", i, j[i].locale, j[i].q);*/ #endif - strs[i]=j[i].locale; - } - res = uloc_acceptLanguage(result, resultAvailable, outResult, - (const char**)strs, n, availableLocales, status); - for(i=0;i0) { - uprv_strncpy(result, l, uprv_min(len, resultAvailable)); - } - for(j=0;jmaxLen) { - maxLen = len; - } + UErrorCode *status) +{ + int32_t i,j; + int32_t len; + int32_t maxLen=0; + char tmp[ULOC_FULLNAME_CAPACITY+1]; + const char *l; + char **fallbackList; + if(U_FAILURE(*status)) { + return -1; } - uenum_reset(availableLocales, status); - /* save off parent info */ - if(uloc_getParent(acceptList[i], tmp, sizeof(tmp)/sizeof(tmp[0]), status)!=0) { - fallbackList[i] = uprv_strdup(tmp); - } else { - fallbackList[i]=0; - } - } - - for(maxLen--;maxLen>0;maxLen--) { + fallbackList = uprv_malloc((size_t)(sizeof(fallbackList[0])*acceptListCount)); for(i=0;i0) { - uprv_strncpy(result, l, uprv_min(len, resultAvailable)); + if(len>0) { + uprv_strncpy(result, l, uprv_min(len, resultAvailable)); + } + for(j=0;jmaxLen) { + maxLen = len; } - uprv_free(fallbackList); - return u_terminateChars(result, resultAvailable, len, status); - } } uenum_reset(availableLocales, status); - - if(uloc_getParent(fallbackList[i], tmp, sizeof(tmp)/sizeof(tmp[0]), status)!=0) { - fallbackList[i] = uprv_strdup(tmp); + /* save off parent info */ + if(uloc_getParent(acceptList[i], tmp, sizeof(tmp)/sizeof(tmp[0]), status)!=0) { + fallbackList[i] = uprv_strdup(tmp); } else { - fallbackList[i]=0; + fallbackList[i]=0; } - } } - if(outResult) { - *outResult = ULOC_ACCEPT_FAILED; + + for(maxLen--;maxLen>0;maxLen--) { + for(i=0;i0) { + uprv_strncpy(result, l, uprv_min(len, resultAvailable)); + } + for(i=0;icurrChar = (cont->array)[cont->currIndex]; - *resultLength = uprv_strlen(cont->currChar); + *resultLength = (int32_t)strlen(cont->currChar); u_charsToUChars(cont->currChar, cont->currUChar, *resultLength); cont->currIndex++; return cont->currUChar; @@ -84,7 +84,7 @@ chArrayNext(UEnumeration *en, int32_t *resultLength, UErrorCode *status) { } cont->currChar = (cont->array)[cont->currIndex]; - *resultLength = uprv_strlen(cont->currChar); + *resultLength = (int32_t)strlen(cont->currChar); cont->currIndex++; return cont->currChar; } diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 2b5014d0074..c1f324157e2 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -1703,8 +1703,8 @@ LocaleTest::TestGetBaseName(void) { * prefix + '_' + x, then return 1. Otherwise return a value < 0. */ static UBool _loccmp(const char* string, const char* prefix) { - int32_t slen = uprv_strlen(string), - plen = uprv_strlen(prefix); + int32_t slen = (int32_t)strlen(string), + plen = (int32_t)strlen(prefix); int32_t c = uprv_strncmp(string, prefix, plen); /* 'root' is "less than" everything */ if (uprv_strcmp(prefix, "root") == 0) { diff --git a/icu4c/source/test/intltest/restsnew.cpp b/icu4c/source/test/intltest/restsnew.cpp index 72d7da05ecd..e2b4d79f480 100644 --- a/icu4c/source/test/intltest/restsnew.cpp +++ b/icu4c/source/test/intltest/restsnew.cpp @@ -1099,7 +1099,7 @@ NewResourceBundleTest::TestNewTypes() { UnicodeString str = theBundle.getStringEx("testescape",status); CONFIRM_UErrorCode(status, U_ZERO_ERROR); if(U_SUCCESS(status)){ - u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1); + u_charsToUChars(expect,uExpect,(int32_t)uprv_strlen(expect)+1); if(str.compare(uExpect)!=0){ errln("Did not get the expected string for testescape expected. Expected : " +UnicodeString(uExpect )+ " Got: " + str); @@ -1111,7 +1111,7 @@ NewResourceBundleTest::TestNewTypes() { UnicodeString str = theBundle.getStringEx("test_underscores",status); expect ="test message ...."; CONFIRM_UErrorCode(status, U_ZERO_ERROR); - u_charsToUChars(expect,uExpect,uprv_strlen(expect)+1); + u_charsToUChars(expect,uExpect,(int32_t)uprv_strlen(expect)+1); if(str.compare(uExpect)!=0){ errln("Did not get the expected string for test_underscores.\n"); } diff --git a/icu4c/source/test/intltest/ucaconf.cpp b/icu4c/source/test/intltest/ucaconf.cpp index 8ab42e963e3..2320d7ddda7 100644 --- a/icu4c/source/test/intltest/ucaconf.cpp +++ b/icu4c/source/test/intltest/ucaconf.cpp @@ -115,7 +115,7 @@ void UCAConformanceTest::openTestFile(const char *type) char buffer[1024]; uprv_strcpy(buffer, testDataPath); uprv_strcat(buffer, type); - int32_t bufLen = uprv_strlen(buffer); + int32_t bufLen = (int32_t)uprv_strlen(buffer); // we try to open 3 files: // path/CollationTest_type.txt