From 38e883f1fbc97fc33a01af93cd0a82f971390b51 Mon Sep 17 00:00:00 2001 From: waker Date: Mon, 7 Feb 2011 22:20:35 +0100 Subject: fixed junklib utf8 validation --- junklib.c | 6 +++--- utf8.c | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/junklib.c b/junklib.c index 635a2307..e8ea3b00 100644 --- a/junklib.c +++ b/junklib.c @@ -320,10 +320,10 @@ int ddb_iconv (const char *cs_out, const char *cs_in, char *out, int outlen, con // to utf8 branch if (!strcmp (cs_out, UTF8_STR)) { if (!strcmp (cs_in, UTF8_STR)) { - int valid = u8_valid (in, inlen, NULL); + memcpy (out, in, inlen); + out[inlen] = 0; + int valid = u8_valid (out, inlen, NULL); if (valid) { - memcpy (out, in, inlen); - out[inlen] = 0; len = inlen; } } diff --git a/utf8.c b/utf8.c index bb115e64..c303b9a1 100644 --- a/utf8.c +++ b/utf8.c @@ -590,14 +590,13 @@ int u8_valid (const char *str, /* See that we covered the entire length if a length was * passed in, or that we ended on a nul if not */ - if (max_len >= 0 && - p != (str + max_len)) + if (max_len >= 0 && p != (str + max_len) && *p != 0) { return 0; - else if (max_len < 0 && - *p != '\0') + } + else if (max_len < 0 && *p != '\0') { return 0; - else - return 1; + } + return 1; } #if 0 -- cgit v1.2.3