]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/io/sprintf.c
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / io / sprintf.c
index 0d90b561befd2119050a3341c7419f8c40d25cf9..91d29c56f061ac5a1f3a22f45dd9c544630a78d7 100644 (file)
@@ -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;
 }