@@ -60,16 +60,12 @@ doWriteForward(const char16_t *src, int32_t srcLength,
6060 char16_t *dest, int32_t destSize,
6161 uint16_t options,
6262 UErrorCode *pErrorCode) {
63- if (srcLength<=0 ) {
64- *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
65- return 0 ;
66- }
6763 /* optimize for several combinations of options */
6864 switch (options&(UBIDI_REMOVE_BIDI_CONTROLS|UBIDI_DO_MIRRORING)) {
6965 case 0 : {
7066 /* simply copy the LTR run to the destination */
7167 int32_t length=srcLength;
72- if (destSize<length) {
68+ if (!destSize || destSize<length) {
7369 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
7470 return srcLength;
7571 }
@@ -83,7 +79,7 @@ doWriteForward(const char16_t *src, int32_t srcLength,
8379 int32_t i=0 , j=0 ;
8480 UChar32 c;
8581
86- if (destSize<srcLength) {
82+ if (!destSize || destSize<srcLength) {
8783 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
8884 return srcLength;
8985 }
@@ -178,11 +174,6 @@ doWriteReverse(const char16_t *src, int32_t srcLength,
178174 int32_t i, j;
179175 UChar32 c;
180176
181- if (srcLength<=0 ) {
182- *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
183- return 0 ;
184- }
185-
186177 /* optimize for several combinations of options */
187178 switch (options&(UBIDI_REMOVE_BIDI_CONTROLS|UBIDI_DO_MIRRORING|UBIDI_KEEP_BASE_COMBINING)) {
188179 case 0 :
@@ -192,7 +183,7 @@ doWriteReverse(const char16_t *src, int32_t srcLength,
192183 * and there is no mirroring and no keeping combining characters
193184 * with their base characters.
194185 */
195- if (destSize<srcLength) {
186+ if (!destSize || destSize<srcLength) {
196187 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
197188 return srcLength;
198189 }
@@ -220,7 +211,7 @@ doWriteReverse(const char16_t *src, int32_t srcLength,
220211 * and there is no mirroring.
221212 * We do need to keep combining characters with their base characters.
222213 */
223- if (destSize<srcLength) {
214+ if (!destSize || destSize<srcLength) {
224215 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
225216 return srcLength;
226217 }
@@ -269,7 +260,7 @@ doWriteReverse(const char16_t *src, int32_t srcLength,
269260 src-=srcLength;
270261 }
271262
272- if (destSize<i) {
263+ if (!destSize || destSize<i) {
273264 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
274265 return i;
275266 }
0 commit comments