diff --git a/icu4c/source/common/ucnv_cb.c b/icu4c/source/common/ucnv_cb.c index 4f76352cad..9cbf25e607 100644 --- a/icu4c/source/common/ucnv_cb.c +++ b/icu4c/source/common/ucnv_cb.c @@ -6,10 +6,10 @@ * ucnv_cb.c: * External APIs for the ICU's codeset conversion library * Helena Shih - * + * * Modification History: * - * Date Name Description + * Date Name Description * 7/28/2000 srl Implementation */ @@ -35,50 +35,50 @@ ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err) { - int32_t togo; - int8_t toerr; - int32_t i; + int32_t togo; + int8_t toerr; + int32_t i; - if((args->targetLimit - args->target) >= length) /* If the buffer fits.. */ - { - uprv_memcpy(args->target, source, length); - args->target += length; - if(args->offsets) /* set all the offsets to the same # */ + if((args->targetLimit - args->target) >= length) /* If the buffer fits.. */ { - for(i=0;ioffsets++) = offsetIndex; - } + uprv_memcpy(args->target, source, length); + args->target += length; + if(args->offsets) /* set all the offsets to the same # */ + { + for(i=0;ioffsets++) = offsetIndex; + } + } } - } - else - { - togo = args->targetLimit - args->target; - - uprv_memcpy(args->target, source, togo); - args->target += togo; - - if(args->offsets) + else { - for(i=0;ioffsets++) = offsetIndex; - } + togo = (int32_t)(args->targetLimit - args->target); + + uprv_memcpy(args->target, source, togo); + args->target += togo; + + if(args->offsets) + { + for(i=0;ioffsets++) = offsetIndex; + } + } + + /* Now, copy the remainder into the errbuff */ + source += togo; + toerr = (int8_t)(length - togo); + + uprv_memcpy(args->converter->charErrorBuffer + + args->converter->charErrorBufferLength, + source, + toerr * sizeof(source[0])); + args->converter->charErrorBufferLength += toerr; + + *err = U_BUFFER_OVERFLOW_ERROR; + } - - /* Now, copy the remainder into the errbuff */ - source += togo; - toerr = (int8_t)(length - togo); - - uprv_memcpy(args->converter->charErrorBuffer + - args->converter->charErrorBufferLength, - source, - toerr * sizeof(source[0])); - args->converter->charErrorBufferLength += toerr; - - *err = U_BUFFER_OVERFLOW_ERROR; - - } } U_CAPI void U_EXPORT2 @@ -88,118 +88,119 @@ ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err) { - /* - This is a fun one. Recursion can occur - we're basically going to - just retry shoving data through the same converter. Note, if you got - here through some kind of invalid sequence, you maybe should emit a + /* + This is a fun one. Recursion can occur - we're basically going to + just retry shoving data through the same converter. Note, if you got + here through some kind of invalid sequence, you maybe should emit a reset sequence of some kind and/or call ucnv_reset(). Since this IS an actual conversion, take care that you've changed the callback or the data, or you'll get an infinite loop. - + Please set the err value to something reasonable before calling into this. - */ + */ - char *oldTarget; + char *oldTarget; - if(U_FAILURE(*err)) - { - return; - } - - oldTarget = args->target; - - ucnv_fromUnicode(args->converter, - &args->target, - args->targetLimit, - source, - sourceLimit, - NULL, /* no offsets */ - FALSE, /* no flush */ - err); - - if(args->offsets) - { - while (args->target != oldTarget) /* if it moved at all.. */ + if(U_FAILURE(*err)) { - *(args->offsets)++ = offsetIndex; - oldTarget++; + return; } - } - /* Note, if you did something like used a Stop subcallback, things would get interesting. - In fact, here's where we want to return the partially consumed in-source! - */ - if(*err == U_BUFFER_OVERFLOW_ERROR) - /* && (*source < sourceLimit && args->target >= args->targetLimit) - -- S. Hrcek */ - { + oldTarget = args->target; + + ucnv_fromUnicode(args->converter, + &args->target, + args->targetLimit, + source, + sourceLimit, + NULL, /* no offsets */ + FALSE, /* no flush */ + err); + + if(args->offsets) + { + while (args->target != oldTarget) /* if it moved at all.. */ + { + *(args->offsets)++ = offsetIndex; + oldTarget++; + } + } + + /* + Note, if you did something like used a Stop subcallback, things would get interesting. + In fact, here's where we want to return the partially consumed in-source! + */ + if(*err == U_BUFFER_OVERFLOW_ERROR) + /* && (*source < sourceLimit && args->target >= args->targetLimit) + -- S. Hrcek */ + { /* Overflowed the target. Now, we'll write into the charErrorBuffer. - It's a fixed size. If we overflow it... Hmm */ - char *newTarget; - const char *newTargetLimit; - UErrorCode err2 = U_ZERO_ERROR; + It's a fixed size. If we overflow it... Hmm */ + char *newTarget; + const char *newTargetLimit; + UErrorCode err2 = U_ZERO_ERROR; - int8_t errBuffLen; + int8_t errBuffLen; - errBuffLen = args->converter->charErrorBufferLength; + errBuffLen = args->converter->charErrorBufferLength; - /* start the new target at the first free slot in the errbuff.. */ - newTarget = (char *)(args->converter->charErrorBuffer + errBuffLen); - - newTargetLimit = (char *)(args->converter->charErrorBuffer + - sizeof(args->converter->charErrorBuffer)); + /* start the new target at the first free slot in the errbuff.. */ + newTarget = (char *)(args->converter->charErrorBuffer + errBuffLen); - if(newTarget >= newTargetLimit) - { - *err = U_INTERNAL_PROGRAM_ERROR; - return; - } + newTargetLimit = (char *)(args->converter->charErrorBuffer + + sizeof(args->converter->charErrorBuffer)); - /* We're going to tell the converter that the errbuff len is empty. + if(newTarget >= newTargetLimit) + { + *err = U_INTERNAL_PROGRAM_ERROR; + return; + } + + /* We're going to tell the converter that the errbuff len is empty. This prevents the existing errbuff from being 'flushed' out onto - itself. If the errbuff is needed by the converter this time, + itself. If the errbuff is needed by the converter this time, we're hosed - we're out of space! */ - args->converter->charErrorBufferLength = 0; - - ucnv_fromUnicode(args->converter, - &newTarget, - newTargetLimit, - source, - sourceLimit, - NULL, - FALSE, - &err2); + args->converter->charErrorBufferLength = 0; - /* We can go ahead and overwrite the length here. We know just how + ucnv_fromUnicode(args->converter, + &newTarget, + newTargetLimit, + source, + sourceLimit, + NULL, + FALSE, + &err2); + + /* We can go ahead and overwrite the length here. We know just how to recalculate it. */ - args->converter->charErrorBufferLength = (int8_t)( - newTarget - (char*)args->converter->charErrorBuffer); + args->converter->charErrorBufferLength = (int8_t)( + newTarget - (char*)args->converter->charErrorBuffer); - if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR)) - { - /* now we're REALLY in trouble. - Internal program error - callback oughtn't to have written this much - data! - */ - *err = U_INTERNAL_PROGRAM_ERROR; - return; - } - else - { - /* sub errs could be invalid/truncated/illegal chars or w/e. - These might want to be passed on up.. But the problem is, we already - need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these - other errs.. */ + if((newTarget >= newTargetLimit) || (err2 == U_BUFFER_OVERFLOW_ERROR)) + { + /* now we're REALLY in trouble. + Internal program error - callback shouldn't have written this much + data! + */ + *err = U_INTERNAL_PROGRAM_ERROR; + return; + } + else + { + /* sub errs could be invalid/truncated/illegal chars or w/e. + These might want to be passed on up.. But the problem is, we already + need to pass U_BUFFER_OVERFLOW_ERROR. That has to override these + other errs.. */ - /* - if(U_FAILURE(err2)) - ?? - */ + /* + if(U_FAILURE(err2)) + ?? + */ + } } - } } U_CAPI void U_EXPORT2 @@ -231,55 +232,55 @@ ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err) { - int32_t togo; - int8_t toerr; - int32_t i; - - if(U_FAILURE(*err)) - { - return; - } + int32_t togo; + int8_t toerr; + int32_t i; - - if((args->targetLimit - args->target) >= length) /* If the buffer fits.. */ - { - uprv_memcpy(args->target, source, length * sizeof(args->target[0]) ); - args->target += length; - if(args->offsets) /* set all the offsets to the same # */ + if(U_FAILURE(*err)) { - for(i=0;ioffsets++) = offsetIndex; - } - } - } - else - { - togo = args->targetLimit - args->target; - - uprv_memcpy(args->target, source, togo * sizeof(args->target[0]) ); - args->target += togo; - - if(args->offsets) - { - for(i=0;ioffsets++) = offsetIndex; - } + return; } - /* Now, copy the remainder into the errbuff */ - source += togo; - toerr = (int8_t)(length - togo); - - uprv_memcpy(args->converter->UCharErrorBuffer + - args->converter->UCharErrorBufferLength, - source, - toerr * sizeof(source[0])); - args->converter->UCharErrorBufferLength += toerr; - *err = U_BUFFER_OVERFLOW_ERROR; - } + if((args->targetLimit - args->target) >= length) /* If the buffer fits.. */ + { + uprv_memcpy(args->target, source, length * sizeof(args->target[0]) ); + args->target += length; + if(args->offsets) /* set all the offsets to the same # */ + { + for(i=0;ioffsets++) = offsetIndex; + } + } + } + else + { + togo = (int32_t)(args->targetLimit - args->target); + + uprv_memcpy(args->target, source, togo * sizeof(args->target[0]) ); + args->target += togo; + + if(args->offsets) + { + for(i=0;ioffsets++) = offsetIndex; + } + } + + /* Now, copy the remainder into the errbuff */ + source += togo; + toerr = (int8_t)(length - togo); + + uprv_memcpy(args->converter->UCharErrorBuffer + + args->converter->UCharErrorBufferLength, + source, + toerr * sizeof(source[0])); + args->converter->UCharErrorBufferLength += toerr; + + *err = U_BUFFER_OVERFLOW_ERROR; + } } U_CAPI void U_EXPORT2 @@ -287,12 +288,12 @@ ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args, int32_t offsetIndex, UErrorCode * err) { - static const UChar kSubstituteChar1 = 0x1A, kSubstituteChar = 0xFFFD; + static const UChar kSubstituteChar1 = 0x1A, kSubstituteChar = 0xFFFD; - /* could optimize this case, just one uchar */ - if(args->converter->invalidCharLength == 1 && args->converter->subChar1 != 0) { - ucnv_cbToUWriteUChars(args, &kSubstituteChar1, 1, offsetIndex, err); - } else { - ucnv_cbToUWriteUChars(args, &kSubstituteChar, 1, offsetIndex, err); - } + /* could optimize this case, just one uchar */ + if(args->converter->invalidCharLength == 1 && args->converter->subChar1 != 0) { + ucnv_cbToUWriteUChars(args, &kSubstituteChar1, 1, offsetIndex, err); + } else { + ucnv_cbToUWriteUChars(args, &kSubstituteChar, 1, offsetIndex, err); + } } diff --git a/icu4c/source/common/ucnv_cnv.c b/icu4c/source/common/ucnv_cnv.c index f79d30b2d3..3180ca99cc 100644 --- a/icu4c/source/common/ucnv_cnv.c +++ b/icu4c/source/common/ucnv_cnv.c @@ -215,7 +215,7 @@ ucnv_getNextUCharFromToUImpl(UConverterToUnicodeArgs *pArgs, /* convert this byte and check the result */ toU(pArgs, pErrorCode); if(U_SUCCESS(*pErrorCode)) { - int32_t length=pArgs->target-buffer; + int32_t length=(int32_t)(pArgs->target-buffer); /* this test is UTF-16 specific */ if(/* some output and diff --git a/icu4c/source/common/ucnv_io.c b/icu4c/source/common/ucnv_io.c index bab3ed7978..1fa83ae4df 100644 --- a/icu4c/source/common/ucnv_io.c +++ b/icu4c/source/common/ucnv_io.c @@ -577,7 +577,7 @@ ucnv_io_setDefaultConverterName(const char *converterName) { defaultConverterName=name; } else { /* do not set the name if the alias lookup failed and it is too long */ - int32_t length=uprv_strlen(converterName); + int32_t length=(int32_t)(uprv_strlen(converterName)); if(lengthoffsets) - args->offsets[myTarget - args->target]=mySource - args->source - 1-(myData->isStateDBCS); + if(args->offsets) { + args->offsets[myTarget - args->target]=(int32_t)(mySource - args->source - 1-(myData->isStateDBCS)); + } *(myTarget++)=(UChar)targetUniChar; } @@ -258,7 +259,7 @@ SAVE_STATE: UConverterCallbackReason reason; int32_t currentOffset ; - int32_t saveIndex = myTarget - args->target; + int32_t saveIndex = (int32_t)(myTarget - args->target); args->converter->invalidCharLength=0; @@ -274,12 +275,12 @@ SAVE_STATE: args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[0]-0x80); args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)(tempBuf[1]-0x80); - currentOffset= mySource - args->source -2; + currentOffset= (int32_t)(mySource - args->source -2); } else{ args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char)mySourceChar; - currentOffset= mySource - args->source -1; + currentOffset= (int32_t)(mySource - args->source -1); } args->offsets = args->offsets?args->offsets+(myTarget - args->target):0; args->target = myTarget; @@ -340,8 +341,8 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args, int32_t* offsets = args->offsets; int32_t mySourceIndex = 0; int32_t myTargetIndex = 0; - int32_t targetLength = args->targetLimit - args->target; - int32_t mySourceLength = args->sourceLimit - args->source; + int32_t targetLength = (int32_t)(args->targetLimit - args->target); + int32_t mySourceLength = (int32_t)(args->sourceLimit - args->source); int32_t length=0; uint32_t targetUniChar = 0x0000; UChar32 mySourceChar = 0x0000,c=0x0000; @@ -519,8 +520,8 @@ getTrail: /*Update the local Indexes so that the conversion *can restart at the right points */ - myTargetIndex = args->target - (char*)myTarget; - mySourceIndex = args->source - mySource; + myTargetIndex = (int32_t)(args->target - (char*)myTarget); + mySourceIndex = (int32_t)(args->source - mySource); args->offsets = saveOffsets; saveIndex = myTargetIndex - saveIndex; if(args->offsets){ diff --git a/icu4c/source/common/ucnvisci.c b/icu4c/source/common/ucnvisci.c index e0e4ec8e30..dc3506edb3 100644 --- a/icu4c/source/common/ucnvisci.c +++ b/icu4c/source/common/ucnvisci.c @@ -133,7 +133,7 @@ _ISCIIOpen(UConverter *cnv, const char *name,const char *locale,uint32_t options cnv->extraInfo = uprv_malloc (sizeof (UConverterDataISCII)); if(cnv->extraInfo != NULL) { - int len=0; + int32_t len=0; UConverterDataISCII *converterData=(UConverterDataISCII *) cnv->extraInfo; converterData->contextCharToUnicode=NO_CHAR_MARKER; cnv->toUnicodeStatus = missingCharMarker; @@ -150,7 +150,7 @@ _ISCIIOpen(UConverter *cnv, const char *name,const char *locale,uint32_t options converterData->isFirstBuffer=TRUE; uprv_strcpy(converterData->name,"ISCII,version="); - len = uprv_strlen(converterData->name); + len = (int32_t)uprv_strlen(converterData->name); converterData->name[len]= (char)((options & UCNV_OPTIONS_VERSION_MASK) + '0'); converterData->name[len+1]=0; }else{ @@ -757,17 +757,17 @@ static const uint16_t nuktaSpecialCases[][2]={ if(targetByteUnit <= 0xFF){ \ *(target)++ = (uint8_t)(targetByteUnit); \ if(offsets){ \ - *(offsets++) = source - args->source-1; \ + *(offsets++) = (int32_t)(source - args->source-1); \ } \ }else{ \ *(target)++ = (uint8_t)(targetByteUnit>>8); \ if(offsets){ \ - *(offsets++) = source - args->source-1; \ + *(offsets++) = (int32_t)(source - args->source-1); \ } \ if(target < targetLimit){ \ *(target)++ = (uint8_t) targetByteUnit; \ if(offsets){ \ - *(offsets++) = source - args->source-1; \ + *(offsets++) = (int32_t)(source - args->source-1); \ } \ }else{ \ args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = \ @@ -986,7 +986,7 @@ getTrail: char* saveTarget =NULL; int32_t* saveOffsets =NULL; int currentOffset =0; - int saveIndex =0; + int32_t saveIndex =0; args->converter->invalidUCharLength = 0; @@ -1022,7 +1022,7 @@ getTrail: reason, err); - saveIndex = args->target - (char*)target; + saveIndex = (int32_t)(args->target - (char*)target); if(args->offsets){ args->offsets = saveOffsets; while(saveIndex-->0){ @@ -1093,7 +1093,7 @@ static const int32_t lookupTable[][2]={ if(targettargetLimit){ \ *(target)++ = (UChar)targetUniChar; \ if(offsets){ \ - *(offsets)++ = offset; \ + *(offsets)++ = (int32_t)(offset); \ } \ }else{ \ args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++] = \ @@ -1318,13 +1318,11 @@ CALLBACK: const char *saveSource = args->source; UChar *saveTarget = args->target; int32_t *saveOffsets = NULL; - int32_t currentOffset; - int32_t saveIndex = target - args->target; + int32_t currentOffset = (int32_t)(source - args->source -1); + int32_t saveIndex = (int32_t)(target - args->target); args->converter->invalidCharLength=0; - currentOffset= source - args->source -1; - args->converter->invalidCharBuffer[args->converter->invalidCharLength++] = (char) sourceChar; diff --git a/icu4c/source/common/ucnvscsu.c b/icu4c/source/common/ucnvscsu.c index 0aa0f26e3e..4b99a2bd67 100644 --- a/icu4c/source/common/ucnvscsu.c +++ b/icu4c/source/common/ucnvscsu.c @@ -578,11 +578,11 @@ callback: byteOne=scsu->toUByteOne; /* update target and deal with offsets if necessary */ - offsets=ucnv_updateCallbackOffsets(offsets, pArgs->target-target, sourceIndex); + offsets=ucnv_updateCallbackOffsets(offsets, (int32_t)(pArgs->target-target), sourceIndex); target=pArgs->target; /* update the source pointer and index */ - sourceIndex=nextSourceIndex+((const uint8_t *)pArgs->source-source); + sourceIndex=(int32_t)(nextSourceIndex+((const uint8_t *)pArgs->source-source)); source=(const uint8_t *)pArgs->source; /* @@ -1112,7 +1112,7 @@ _SCSUFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs, source=pArgs->source; sourceLimit=pArgs->sourceLimit; target=(uint8_t *)pArgs->target; - targetCapacity=pArgs->targetLimit-pArgs->target; + targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target); offsets=pArgs->offsets; /* get the state machine state */ @@ -1594,13 +1594,13 @@ callback: c=cnv->fromUSurrogateLead; /* update target and deal with offsets if necessary */ - offsets=ucnv_updateCallbackOffsets(offsets, ((uint8_t *)pArgs->target)-target, sourceIndex); + offsets=ucnv_updateCallbackOffsets(offsets, (int32_t)(((uint8_t *)pArgs->target)-target), sourceIndex); target=(uint8_t *)pArgs->target; /* update the source pointer and index */ - sourceIndex=nextSourceIndex+(pArgs->source-source); + sourceIndex=(int32_t)(nextSourceIndex+(pArgs->source-source)); source=pArgs->source; - targetCapacity=(uint8_t *)pArgs->targetLimit-target; + targetCapacity=(int32_t)((uint8_t *)pArgs->targetLimit-target); /* * If the callback overflowed the target, then we need to @@ -1660,7 +1660,7 @@ _SCSUFromUnicode(UConverterFromUnicodeArgs *pArgs, source=pArgs->source; sourceLimit=pArgs->sourceLimit; target=(uint8_t *)pArgs->target; - targetCapacity=pArgs->targetLimit-pArgs->target; + targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target); /* get the state machine state */ isSingleByteMode=scsu->fromUIsSingleByteMode; @@ -2081,7 +2081,7 @@ callback: target=(uint8_t *)pArgs->target; source=pArgs->source; - targetCapacity=(uint8_t *)pArgs->targetLimit-target; + targetCapacity=(int32_t)((uint8_t *)pArgs->targetLimit-target); /* * If the callback overflowed the target, then we need to