X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..46f4442e9a5a4f3b98b7c1083586332f6a8a99a4:/icuSources/io/sprintf.c?ds=inline diff --git a/icuSources/io/sprintf.c b/icuSources/io/sprintf.c index 0d90b561..91d29c56 100644 --- a/icuSources/io/sprintf.c +++ b/icuSources/io/sprintf.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 2001-2004, International Business Machines +* Copyright (C) 2001-2008, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -54,6 +54,7 @@ u_sprintf_pad_and_justify(void *context, { u_localized_print_string *output = (u_localized_print_string *)context; int32_t written = 0; + int32_t lengthOfResult = resultLen; resultLen = ufmt_min(resultLen, output->available); @@ -88,6 +89,10 @@ u_sprintf_pad_and_justify(void *context, else { written = u_sprintf_write(output, result, resultLen); } + + if (written >= 0 && lengthOfResult > written) { + return lengthOfResult; + } return written; } @@ -216,6 +221,7 @@ u_vsnprintf_u(UChar *buffer, va_list ap) { int32_t written = 0; /* haven't written anything yet */ + int32_t result = 0; /* test the return value of u_printf_parse */ u_localized_print_string outStr; @@ -232,8 +238,8 @@ u_vsnprintf_u(UChar *buffer, } /* parse and print the whole format string */ - u_printf_parse(&g_sprintf_stream_handler, patternSpecification, &outStr, &outStr, &outStr.fBundle, &written, ap); - + result = u_printf_parse(&g_sprintf_stream_handler, patternSpecification, &outStr, &outStr, &outStr.fBundle, &written, ap); + /* Terminate the buffer, if there's room. */ if (outStr.available > 0) { buffer[outStr.len - outStr.available] = 0x0000; @@ -242,6 +248,10 @@ u_vsnprintf_u(UChar *buffer, /* Release the cloned bundle, if we cloned it. */ u_locbund_close(&outStr.fBundle); + /* parsing error */ + if (result < 0) { + return result; + } /* return # of UChars written */ return written; }