prelude-lml/master: Let libICU handle nul termination on string convertion

[email protected] Mon, 8 Feb 2010 11:24:48 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit a21f61092512230a6bf53edcbd4033ef63e15b3a
Author: Yoann Vandoorselaere <[email protected]>
Date:   Fri Feb 5 15:26:29 2010 +0100

    Let libICU handle nul termination on string convertion
    
    Since libICU already Nul terminate output string when converting
    to UTF8, let libICU handle the work. Fix 1.0.0rc1 regression.


========================================

 src/lml-charset.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

========================================

diff --git a/src/lml-charset.c b/src/lml-charset.c
index 73450b9..cc6e7c0 100644
--- a/src/lml-charset.c
+++ b/src/lml-charset.c
@@ -127,16 +127,14 @@ static int _charset_convert(lml_charset_t *lc, const char *in, size_t inlen, cha
                 return -1;
         }
 
-        ucnv_convertEx(lc->to, lc->from, &target, *out + maxlen, &in, in + inlen, NULL, NULL, NULL, NULL, 0, TRUE, &status);
-        if ( U_FAILURE(status) ) {
+        ucnv_convertEx(lc->to, lc->from, &target, *out + maxlen + 1, &in, in + inlen, NULL, NULL, NULL, NULL, 0, TRUE, &status);
+        if ( U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING ) {
                 prelude_log(PRELUDE_LOG_ERR, "ICU: failed converting input to UTF-8: %s.\n", u_errorName(status));
                 free(*out);
                 return -1;
         }
 
         *outlen = target - *out;
-        target[*outlen] = '\0';
-
         return 0;
 }
 
@@ -197,7 +195,7 @@ static int _charset_convert(lml_charset_t *lc, const char *in, size_t inlen, cha
         }
 
         *outlen = (bkpolen - olen);
-        outp[0] = '\0';
+        *outp = '\0';
 
         return 0;
 }
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-technologies.com/mailman/listinfo/prelude-cvslog