Enlightenment CVS committal

Author  : kwo
Project : e16
Module  : e

Dir     : e16/e/src


Modified Files:
        lang.c 


Log Message:
Fix potential crash if iconv_open fails.
Issue warnings for unavailable encoding conversions.

===================================================================
RCS file: /cvs/e/e16/e/src/lang.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- lang.c      10 May 2008 23:22:31 -0000      1.25
+++ lang.c      26 Jun 2008 21:57:22 -0000      1.26
@@ -60,11 +60,8 @@
    pi = (char *)txt;
    po = buf;
    ni = (len > 0) ? len : strlen(txt);
-   if (!icd)
-     {
-       Eprintf("*** WARNING - Missing conversion\n");
-       return Estrndup(txt, ni);
-     }
+   if (icd == BAD_CD)
+      return Estrndup(txt, ni);
    no = sizeof(buf);
    err = iconv(icd, &pi, &ni, &po, &no);
 
@@ -73,6 +70,18 @@
    return po;
 }
 
+static              iconv_t
+EiconvOpen(const char *to, const char *from)
+{
+   iconv_t             icd;
+
+   icd = iconv_open(to, from);
+   if (icd == BAD_CD)
+      Eprintf("*** WARNING - Missing conversion %s->%s\n", from, to);
+
+   return icd;
+}
+
 #endif
 
 #if 0                          /* Unused */
@@ -167,11 +176,11 @@
       enc = nl_langinfo(CODESET);
 
 #if SIZEOF_WCHAR_T == 4
-   iconv_cd_str2wcs = iconv_open("UCS-4", enc);
-   iconv_cd_wcs2str = iconv_open(enc, "UCS-4");
+   iconv_cd_str2wcs = EiconvOpen("UCS-4", enc);
+   iconv_cd_wcs2str = EiconvOpen(enc, "UCS-4");
 #else
-   iconv_cd_str2wcs = iconv_open("WCHAR_T", enc);
-   iconv_cd_wcs2str = iconv_open(enc, "WCHAR_T");
+   iconv_cd_str2wcs = EiconvOpen("WCHAR_T", enc);
+   iconv_cd_wcs2str = EiconvOpen(enc, "WCHAR_T");
 #endif
 
    if (iconv_cd_str2wcs != BAD_CD && iconv_cd_wcs2str != BAD_CD)
@@ -385,15 +394,15 @@
 #if HAVE_ICONV
    if (Mode.locale.utf8_int)
      {
-       iconv_cd_loc2int = iconv_open("UTF-8", enc_loc);
-       iconv_cd_int2loc = iconv_open(enc_loc, "UTF-8");
+       iconv_cd_loc2int = EiconvOpen("UTF-8", enc_loc);
+       iconv_cd_int2loc = EiconvOpen(enc_loc, "UTF-8");
        iconv_cd_utf82int = iconv_cd_int2utf8 = BAD_CD;
      }
    else
      {
        iconv_cd_loc2int = iconv_cd_int2loc = BAD_CD;
-       iconv_cd_utf82int = iconv_open(enc_loc, "UTF-8");
-       iconv_cd_int2utf8 = iconv_open("UTF-8", enc_loc);
+       iconv_cd_utf82int = EiconvOpen(enc_loc, "UTF-8");
+       iconv_cd_int2utf8 = EiconvOpen("UTF-8", enc_loc);
      }
 #endif
 }



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to