[PATCH] Bad error checking after iconv() call



Hello,

there's bad return-value checking after iconv() call in
translate_character() in charsets.c:

count = iconv (cd, &ibuf, &ibuflen, &obuf, &obuflen);
if (count >= 0 && ibuflen == 0)
....

Please note that count is size_t, what is at the most machines unsigned
int so the left side of the condition is always true independently on
the count value. [(size_t)(-1) is returned in case iconv() fails] This
may lead to some weird drawing errors. Attached patch fixes this problem
and makes translate_character() nicer a bit.

Cheers,
Jindrich

-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
ChangeLog:

	* charsets.c (get_codepage_index): Fixed bad error checking after iconv() call.

--- mc-4.6.1a-20050202/src/charsets.c.iconv-error	2004-08-30 12:38:00.000000000 +0200
+++ mc-4.6.1a-20050202/src/charsets.c	2005-02-07 10:31:57.523987520 +0100
@@ -142,17 +142,16 @@ get_codepage_index (const char *id)
 static char
 translate_character (iconv_t cd, char c)
 {
-    char outbuf[4], *obuf;
+    char obuf[4];
     size_t ibuflen, obuflen, count;
 
     ICONV_CONST char *ibuf = &c;
-    obuf = outbuf;
     ibuflen = 1;
-    obuflen = 4;
+    obuflen = sizeof(obuf);
 
-    count = iconv (cd, &ibuf, &ibuflen, &obuf, &obuflen);
-    if (count >= 0 && ibuflen == 0)
-	return outbuf[0];
+    count = iconv (cd, &ibuf, &ibuflen, (char **)&obuf, &obuflen);
+    if (count != (size_t)(-1) && ibuflen == 0)
+	return obuf[0];
 
     return UNKNCHAR;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]