From: Marc Cromme Date: Mon, 7 May 2007 08:15:34 +0000 (+0000) Subject: corrected error handeling in UErrorCode icu_utf16_from_utf8() to X-Git-Tag: PAZPAR2.1.0.0~174 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=1ea74f79189dfde78b3b65e7355774da84efd0dc;p=pazpar2-moved-to-github.git corrected error handeling in UErrorCode icu_utf16_from_utf8() to mirror the error handeling in UErrorCode icu_utf16_from_utf8_cstr(); --- diff --git a/src/icu_bug_2.c b/src/icu_bug_2.c index d283d9d..25d4a28 100644 --- a/src/icu_bug_2.c +++ b/src/icu_bug_2.c @@ -160,20 +160,31 @@ UErrorCode icu_utf16_from_utf8(struct icu_buf_utf16 * dest16, struct icu_buf_utf8 * src8, UErrorCode * status) { - printf("icu_utf16_from_utf8 - needs correcting, see icu_utf16_from_utf8_cstr\n"); - - u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &(dest16->utf16_len), + int32_t utf16_len = 0; + + u_strFromUTF8(dest16->utf16, dest16->utf16_cap, + &utf16_len, (const char *) src8->utf8, src8->utf8_len, status); - + // check for buffer overflow, resize and retry - if (dest16->utf16_len > dest16->utf16_cap){ - printf("icu_utf16_from_utf8 need resize\n"); - icu_buf_utf16_resize(dest16, dest16->utf16_len * 2); + if (*status == U_BUFFER_OVERFLOW_ERROR + //|| dest16->utf16_len > dest16->utf16_cap + ){ + icu_buf_utf16_resize(dest16, utf16_len * 2); *status = U_ZERO_ERROR; - u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &(dest16->utf16_len), - (const char*) src8->utf8, src8->utf8_len, status); + u_strFromUTF8(dest16->utf16, dest16->utf16_cap, + &utf16_len, + (const char *) src8->utf8, src8->utf8_len, status); } + if (*status != U_BUFFER_OVERFLOW_ERROR + && utf16_len < dest16->utf16_cap) + dest16->utf16_len = utf16_len; + else { + dest16->utf16[0] = (UChar) 0; + dest16->utf16_len = 0; + } + return *status; }; @@ -190,7 +201,6 @@ UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16, u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &utf16_len, - //&(dest16->utf16_len), src8cstr, src8cstr_len, status); // check for buffer overflow, resize and retry @@ -201,7 +211,6 @@ UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16, *status = U_ZERO_ERROR; u_strFromUTF8(dest16->utf16, dest16->utf16_cap, &utf16_len, - //&(dest16->utf16_len), src8cstr, src8cstr_len, status); }