summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2010-01-09 01:06:36 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2010-01-09 01:06:36 +0800
commit558ab0fbd5bbbe6a3bcd14a5398c2b2285a2753b (patch)
tree8a257c121d467f7245eb5e043d30e96b15fdd101
parentb046b4ad7e01c186470497ebba60c49ae1d8e8d7 (diff)
utfconverter: fixed utf-32 encoding/decoding
-rw-r--r--utfconverter.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/utfconverter.c b/utfconverter.c
index e031cba..34c7fe0 100644
--- a/utfconverter.c
+++ b/utfconverter.c
@@ -201,10 +201,10 @@ utf32_encode(struct converter *conv,
if (!inbuf)
return UNICONV_SUCCESS;
- if (inleft * 4 > outleft)
- return UNICONV_E2BIG;
-
while (inleft) {
+ if (outleft < 4)
+ return UNICONV_E2BIG;
+
if (uc->little_endian) {
(*outbuf)[0] = ((**inbuf) & 0x000000ff) >> 0;
(*outbuf)[1] = ((**inbuf) & 0x0000ff00) >> 8;
@@ -237,10 +237,11 @@ utf32_decode(struct converter *conv,
if (inleft & 3)
return UNICONV_EINVAL;
- if (inleft / 4 > outleft)
- return UNICONV_E2BIG;
while (inleft) {
+ if (!outleft)
+ return UNICONV_E2BIG;
+
if (uc->little_endian)
**outbuf =
((*inbuf)[0] << 0) |