[openi18n-im:01106] Re: report on unitLE crashes

Leon Ho <[email protected]>
Newsgroups gmane.comp.internationalization.input-methods
Message-ID <[email protected]>
Hi Hideki, Sriram

I have had fixed those with patches and committed to cvs a while ago.

Attached is the patch I have in my rpm package and I am using it while I
was testing. I did:

<snip>
--- iiimf-xcin/src/gen_inp.c    2004-08-16 16:18:25.000000000 +1000
+++ iiimf-xcin.changed/src/gen_inp.c    2004-10-07 14:40:00.000000000
+1000
@@ -128,7 +128,8 @@

     inpinfo->n_selkey = cf->header.n_selkey;
     mcch_size = inpinfo->n_selkey;
-    mcch = calloc(1, mcch_size * sizeof(wch_t));
+    mcch = calloc(mcch_size, sizeof(wch_t));
+    inpinfo->mcch = realloc( inpinfo->mcch, mcch_size * sizeof
(wch_t) );

     do
     {
@@ -150,7 +151,7 @@

 /*  ---ignore rule idx < inpinfo->n_selkey && */
     for ( idx=0; idx < n_ich ; idx++ )
-        memmove((void *)&inpinfo->mcch[idx], (void *)&mcch[idx], sizeof
(wch_t));
+        memcpy((void *)&inpinfo->mcch[idx], (void *)&mcch[idx], sizeof
(wch_t));
         /*inpinfo->mcch[idx].wch = mcch[idx].wch;*/
     inpinfo->n_mcch = idx;
</snip>

and

<snip>
--- iiimf-xcin/src/xmlconf.c    2004-08-16 15:59:02.000000000 +1000
+++ iiimf-xcin.changed/src/xmlconf.c    2004-10-07 14:39:45.000000000
+1000
@@ -140,9 +140,11 @@
 {
     if (inputstyles){
         imnodes *node = inputstyles->first;
+        imnodes *nextnode;
         while( node != inputstyles->last ){
+            nextnode = node->next;
             free(node);
-            node = node->next;
+            node = nextnode;
         }
         free((langim*) inputstyles);
     }
</snip>

Is it something similar to yours? I used valgrind to search for mem
errors.

Regards,
Leon

On Mon, 2004-10-25 at 18:51 -0700, Hideki Hiura wrote:
> Leon,
> it seems that the initial allocation to inpinfo->mcch is missing?
> Adding 
> 
>     inpinfo->mcch = calloc(1, mcch_size * sizeof(wch_t));
> 
> before the do loop for realloc in match_keystroke will fix the problem.
> 
> Also, practically it works, but efence does not allow :-) is the code
> in freeConf() in xmlconf.c
>         while( node != inputstyles->last ){
>             free(node);
>             node = node->next;
> 	}
> 
> We changed it to 
> 
>         imnodes *temp;
>         while( node != inputstyles->last ){
>             temp = node;
>             node = node->next;
>             free(temp);
>         }
> 
> then the problems are gone...Just a live update.:-).
> 
> > From: Hideki Hiura <[email protected]>
> > Subject: [openi18n-im:01102] Re: report on unitLE crashes
> > Date: Mon, 25 Oct 2004 18:20:32 -0700 (PDT)
> >
> > Leon,
> > 
> > > From: Leon Ho <[email protected]>
> > > Anyone see this segfault from unitLE? This happens when starts loading
> > > or switching to unitLE (i.e. LANG=bn_IN.UTF-8 gedit)
> > 
> > This seems to be memery trashing, so the trashing might happen somewhere
> > before.
> > 
> > So we linked htt_server with efence to trace this problem, and efence
> > caught the suspected memory trash when we switched between xcin and unit.
> > As you know the efence detects the memory overrun or accessing to the
> > already freed memory by causing segfault, so this does not happen if you
> > don't link with efence. 
> > 
> > So it seems that we need to check the validity of the arguments passed all the way to match_keystroke().
> > 
> > I'm not sure if this is the reason, but if there is a memory trashing in 
> > xcin, and crashing in unit happens when you switch from xcin to unit, it
> > explains that we have not seen til you've reported , as we did not test 
> > with the xcin module before....but they can be totally different two 
> > problems :-).
> > 
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > [Switching to Thread 1104403376 (LWP 31007)]
> > 0x40339173 in memmove () from /lib/tls/libc.so.6
> > (gdb) where 10
> > #0  0x40339173 in memmove () from /lib/tls/libc.so.6
> > #1  0x41a0cfae in match_keystroke (cf=0x4c233000, inpinfo=0x4c237000, iccf=0x4ce16000)
> >     at gen_inp.c:153
> > #2  0x41a0fa4f in receive_keylist (s=0x4b9c4000, keylist=0xf46f5000) at key_event.c:271
> > #3  0x41a0c1e2 in if_xcin_SendEvent (s=Variable "s" is not available.
> > ) at xcin.c:674
> > #4  0x08089b23 in if_SendEvent (s=0x4b9c4000, e=0x41d3d940) at SunIM.c:472
> > #5  0x0806e76d in LEContext::send_event (this=0x4b9b8000, pimlex=0x4204d000, pimevent=0x41d3d940)
> >     at LE.cpp:396
> > #6  0x080730a5 in IMInputContext::send_event (this=0x4204b000, pimlex=0x4204d000, 
> >     pimevent=0x41d3d940) at IMInputContext.cpp:117
> > #7  0x0807fa3b in IIIMP_ICState_REQUESTED::forward_event (this=0x4ce14000, pmes=0x4ce0c000)
> >     at IIIMP_ICState.cpp:650
> > #8  0x0807d465 in IIIMP_ICState::message_proc (this=0x4204f000, x_pmes=0x4ce0c000)
> >     at IIIMP_ICState.cpp:79
> > #9  0x080773bd in ICState::deliver (this=0x4204f000, message=0x4ce0c000) at ICState.cpp:17
iiimf-le-xcin-0.1.7-mem-event-status.patch (text/x-patch, 6.1 KB)
--- iiimf-xcin/src/gen_inp.c	2004-08-16 16:18:25.000000000 +1000
+++ iiimf-xcin.changed/src/gen_inp.c	2004-10-07 14:40:00.000000000 +1000
@@ -128,7 +128,8 @@
 
     inpinfo->n_selkey = cf->header.n_selkey;
     mcch_size = inpinfo->n_selkey;  
-    mcch = calloc(1, mcch_size * sizeof(wch_t));
+    mcch = calloc(mcch_size, sizeof(wch_t));
+    inpinfo->mcch = realloc( inpinfo->mcch, mcch_size * sizeof(wch_t) );
 
     do
     {
@@ -150,7 +151,7 @@
 
 /*  ---ignore rule idx < inpinfo->n_selkey && */
     for ( idx=0; idx < n_ich ; idx++ )
-        memmove((void *)&inpinfo->mcch[idx], (void *)&mcch[idx], sizeof(wch_t));
+        memcpy((void *)&inpinfo->mcch[idx], (void *)&mcch[idx], sizeof(wch_t));
         /*inpinfo->mcch[idx].wch = mcch[idx].wch;*/
     inpinfo->n_mcch = idx;
 
--- iiimf-xcin/src/key_event.c	2004-10-15 14:21:07.710678128 +1000
+++ iiimf-xcin.changed/src/key_event.c	2004-10-15 14:27:36.147626000 +1000
@@ -108,9 +108,15 @@
         session_data->luc_commit = False;
         return key_backspace_preedit(s, UTFCHARLen(session_data->preedit_buf));
     }    
-    else if(k->keyCode == IM_VK_SPACE || k->keyCode == IM_VK_ENTER)
+    else if(k->keyCode == IM_VK_SPACE){
+            lookup_next(s);
+            lookup_draw(s);
+            return True;
+    }
+    else if(k->keyCode == IM_VK_ENTER){
         if(lookup_commit(s, 0))
             return True;
+    }
 
     /* check if numbers are keyname, if not then process further */
     /* XXX fix in v.2 on not only checking '1' */
@@ -152,7 +158,7 @@
             else
                 name = session_data->cf->inp_cname;
             
-            utf8_to_utf16(name, (char *)session_data->on_string, strlen(session_data->cf->inp_cname)); 
+            utf8_to_utf16(name, (char *)session_data->on_string, strlen(name)); 
         }
 
         status_draw(s);
@@ -214,16 +220,6 @@
                 
         if(keylist_chgtab(s, session_data->cur_im)) return True;
     }
-    /* used to commit char in the luc window using SPACE */
-    //else if (k->keyCode == IM_VK_SPACE || k->keyCode == IM_VK_ACCEPT)
-    /*else if (k->keyCode == IM_VK_ACCEPT)
-    {
-        if (i>0)
-            if(lookup_commit(s, 0))
-                return True;
-        else 
-            return False;
-    }*/
     else if (k->keyCode == IM_VK_SPACE && i > 0 && session_data->luc_start )
     {
         session_data->luc_commit = True;
@@ -248,25 +244,29 @@
             UTFCHAR buf; int j;
             if (session_data->imnode->n_preedit == 1) {
                 buf = (UTFCHAR)UTF8toUnicode((wchar_t)session_data->cf->header.keyname[key2code(k->keyChar)].wch);
-                /* check if buf is there, otherwise don't ignore it and pass to committed area. i.e. some input styles on , and . characters */
-                if (buf)
+                /* check if buf is there, otherwise don't ignore it if it is not in preedit mode yet and pass to committed area. i.e. some input styles on , and . characters */
+                if (buf){
                     session_data->preedit_buf[i] = buf;
-                else
+                    session_data->preedit_buf[i+session_data->imnode->n_preedit] = 0;
+                    session_data->iccf->keystroke[i/session_data->imnode->n_preedit] = (char)k->keyChar;
+                    session_data->iccf->keystroke[i/session_data->imnode->n_preedit+1] = 0;
+                }
+                else if (session_data->preedit_buf[0] == 0)
                     return False;
             } else {
                 for(j=0; j<session_data->imnode->n_preedit; j++) {
                     buf =             
                       (UTFCHAR)UTF8toUnicode((wchar_t)session_data->cf->header.keyname[key2code(k->keyChar)].s[j]);
-                   if (buf)
+                   if (buf){
                        session_data->preedit_buf[i+j] = buf;
-                   else
+                        session_data->preedit_buf[i+session_data->imnode->n_preedit] = 0;
+                        session_data->iccf->keystroke[i/session_data->imnode->n_preedit] = (char)k->keyChar;
+                        session_data->iccf->keystroke[i/session_data->imnode->n_preedit+1] = 0;
+                   }
+                   else if (session_data->preedit_buf[0] == 0)
                        return False;
                 }
             }
-            session_data->preedit_buf[i+session_data->imnode->n_preedit] = 0;
-            
-            session_data->iccf->keystroke[i/session_data->imnode->n_preedit] = (char)k->keyChar;
-            session_data->iccf->keystroke[i/session_data->imnode->n_preedit+1] = 0;
         }
         session_data->inpinfo = match_keystroke( session_data->cf, session_data->inpinfo, session_data->iccf );
                   
@@ -298,9 +298,9 @@
         }
 
     }
-    else
+    else 
         return False;
-
+    
     preedit_draw(s);
 
 #ifdef  DEBUG
--- iiimf-xcin/src/xcin.c	2004-08-16 16:18:25.000000000 +1000
+++ iiimf-xcin.changed/src/xcin.c	2004-10-15 11:41:16.793719000 +1000
@@ -356,8 +356,8 @@
             name = p->inputstyles->first->name;
         else
             name = p->cf->inp_cname;
-        
-        utf8_to_utf16(name, (char *)p->on_string, strlen(p->cf->inp_cname)); 
+
+        utf8_to_utf16(name, (char *)p->on_string, strlen(name)); 
         debug("FILE: %s, LINE: %d, preconvert on_string name: %s", __FILE__, __LINE__, name);
     }
 
--- iiimf-xcin/src/xmlconf.c	2004-08-16 15:59:02.000000000 +1000
+++ iiimf-xcin.changed/src/xmlconf.c	2004-10-07 14:39:45.000000000 +1000
@@ -140,9 +140,11 @@
 {
     if (inputstyles){
         imnodes *node = inputstyles->first;
+        imnodes *nextnode;
         while( node != inputstyles->last ){
+            nextnode = node->next;
             free(node);
-            node = node->next;
+            node = nextnode;
         }
         free((langim*) inputstyles);
     }
--- iiimf-xcin/xcin.xml.conf	2004-08-16 16:14:15.000000000 +1000
+++ iiimf-xcin.changed/xcin.xml.conf	2004-10-15 14:34:57.315559000 +1000
@@ -19,6 +19,7 @@
       <preeditnum>1</preeditnum>
     </inputmethod>
     <inputmethod lang='zh_TW' name='pinyin0'>
+      <name>無調拼音</name>
       <preeditnum>1</preeditnum>
     </inputmethod>
     <inputmethod lang='zh_TW' name='jyutping0'>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.