ICU-471 improve checks for preflighting

X-SVN-Rev: 2228
This commit is contained in:
Markus Scherer 2000-08-14 23:05:10 +00:00
parent 45de64dfbf
commit 9f63dce881

View File

@ -101,8 +101,9 @@ u_shapeArabic(const UChar *source, int32_t sourceLength,
return 0;
}
/* also make sure that no reserved options values are used */
if( source==NULL || sourceLength<-1 || dest==NULL || destSize<0 ||
/* make sure that no reserved options values are used; allow dest==NULL only for preflighting */
if( source==NULL || sourceLength<-1 ||
dest==NULL && destSize!=0 || destSize<0 ||
options>=U_SHAPE_DIGIT_TYPE_RESERVED ||
(options&U_SHAPE_LENGTH_MASK)==U_SHAPE_LENGTH_RESERVED ||
(options&U_SHAPE_LETTERS_MASK)==U_SHAPE_LETTERS_RESERVED ||
@ -121,8 +122,9 @@ u_shapeArabic(const UChar *source, int32_t sourceLength,
}
/* check that source and destination do not overlap */
if( source<=dest && dest<source+sourceLength ||
dest<=source && source<dest+destSize
if( dest!=NULL &&
(source<=dest && dest<source+sourceLength ||
dest<=source && source<dest+destSize)
) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
@ -138,6 +140,7 @@ u_shapeArabic(const UChar *source, int32_t sourceLength,
* just make sure the destination is large enough and copy the string.
*/
if(destSize<sourceLength) {
/* this catches preflighting, too */
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
return sourceLength;
}