Author: yamakenz
Date: Sun Aug 19 02:58:49 2007
New Revision: 4863

Modified:
   trunk/uim/iconv.c
   trunk/uim/uim-helper.c

Log:
* uim/iconv.c
  - (uim_iconv_is_convertible, uim_iconv_create, uim_iconv_code_conv):
    Fix returning from a guarded region without calling
    uim_catch_error_end(). This problem caused SEGV on fatal error
* uim/uim-helper.c
  - (uim_helper_buffer_get_message): Ditto


Modified: trunk/uim/iconv.c
==============================================================================
--- trunk/uim/iconv.c   (original)
+++ trunk/uim/iconv.c   Sun Aug 19 02:58:49 2007
@@ -122,6 +122,7 @@
 uim_iconv_is_convertible(const char *tocode, const char *fromcode)
 {
   iconv_t ic;
+  uim_bool result;
 
   if (uim_catch_error_begin())
     return UIM_FALSE;
@@ -129,18 +130,25 @@
   assert(tocode);
   assert(fromcode);
 
-  if (check_encoding_equivalence(tocode, fromcode))
-    return UIM_TRUE;
+  do {
+    if (check_encoding_equivalence(tocode, fromcode)) {
+      result = UIM_TRUE;
+      break;
+    }
 
-  /* TODO cache the result */
-  ic = (iconv_t)uim_iconv_open(tocode, fromcode);
-  if (ic == (iconv_t)-1)
-    return UIM_FALSE;
-  iconv_close(ic);
+    /* TODO cache the result */
+    ic = (iconv_t)uim_iconv_open(tocode, fromcode);
+    if (ic == (iconv_t)-1) {
+      result = UIM_FALSE;
+      break;
+    }
+    iconv_close(ic);
+    result = UIM_TRUE;
+  } while (/* CONSTCOND */ 0);
 
   uim_catch_error_end();
 
-  return UIM_TRUE;
+  return result;
 }
 
 static const char **
@@ -219,14 +227,18 @@
   assert(tocode);
   assert(fromcode);
 
-  if (check_encoding_equivalence(tocode, fromcode))
-    return NULL;
+  do {
+    if (check_encoding_equivalence(tocode, fromcode)) {
+      ic = (iconv_t)0;
+      break;
+    }
 
-  ic = (iconv_t)uim_iconv_open(tocode, fromcode);
-  if (ic == (iconv_t)-1) {
-    /* since iconv_t is not explicit pointer, use 0 instead of NULL */
-    ic = (iconv_t)0;
-  }
+    ic = (iconv_t)uim_iconv_open(tocode, fromcode);
+    if (ic == (iconv_t)-1) {
+      /* since iconv_t is not explicit pointer, use 0 instead of NULL */
+      ic = (iconv_t)0;
+    }
+  } while (/* CONSTCOND */ 0);
 
   uim_catch_error_end();
 
@@ -244,25 +256,29 @@
   if (uim_catch_error_begin())
     return NULL;
 
-  if (!str)
-    return NULL;
+  do {
+    if (!str) {
+      copied = NULL;
+      break;
+    }
 
-  ic = (iconv_t)obj;
-  if (ic) {
-    len = strlen(str);
-    bufsize = (len + sizeof("")) * MBCHAR_LEN_MAX;
-    realbuf = alloca(bufsize);
-    memset(realbuf, 0, bufsize);
-
-    inbuf = str;
-    outbuf = realbuf;
-    iconv(ic, (ICONV_CONST char **)&inbuf, &len, &outbuf, &bufsize);
-    src = realbuf;
-  } else {
-    src = str;
-  }
+    ic = (iconv_t)obj;
+    if (ic) {
+      len = strlen(str);
+      bufsize = (len + sizeof("")) * MBCHAR_LEN_MAX;
+      realbuf = alloca(bufsize);
+      memset(realbuf, 0, bufsize);
+
+      inbuf = str;
+      outbuf = realbuf;
+      iconv(ic, (ICONV_CONST char **)&inbuf, &len, &outbuf, &bufsize);
+      src = realbuf;
+    } else {
+      src = str;
+    }
 
-  copied = uim_strdup(src);
+    copied = uim_strdup(src);
+  } while (/* CONSTCOND */ 0);
 
   uim_catch_error_end();
 

Modified: trunk/uim/uim-helper.c
==============================================================================
--- trunk/uim/uim-helper.c      (original)
+++ trunk/uim/uim-helper.c      Sun Aug 19 02:58:49 2007
@@ -268,12 +268,13 @@
     memcpy(msg, buf, msg_size);
     msg[msg_size] = '\0';
     uim_helper_buffer_shift(buf, msg_size);
-    return msg;
+  } else {
+    msg = NULL;
   }
 
   uim_catch_error_end();
 
-  return NULL;
+  return msg;
 }
 
 /* Public API for uim_issetugid(). */

Reply via email to