有人在linuxsir发了个patch

1 view
Skip to first unread message

dgod

unread,
Jul 22, 2007, 3:28:49 AM7/22/07
to fcit...@googlegroups.com
作者是cjacker
全文复制过来

主要是修改二笔、晚风问题,顺带准备看一下下面有同志提的五笔3码上屏的问题时,发现问题没有了。
char *strTemp=NULL其实是无所谓了,不过,改了也就改了,这么用毕竟好一点。

--- fcitx-3.5n/src/table.c 2007-07-21 19:24:56.000000000 +0800
+++ fcitx-3.5fix/src/table.c 2007-07-22 02:58:14.000000000 +0800
@@ -880,7 +880,7 @@
retVal = IRV_DISPLAY_LAST;
}
else {
- char *strTemp;
+ char *strTemp=NULL;

retVal = TableGetCandWords (SM_FIRST);
strTemp = GetPunc (strCodeInput[0]);
@@ -1834,7 +1834,12 @@
i = 0;
else {
while (strCodeInput[0] != recordIndex[i].cCode)
+ {
i++;
+ //Is it the reason cause crash when I press ,.; in erbi or wanfeng
+ if(recordIndex[i].record == NULL)
+ return -1;
+ }
}
currentRecord = recordIndex[i].record;
if (!currentRecord)

仍然希望yuking即使不想管了,也可以作个contributor.


qxty

unread,
Jul 22, 2007, 5:53:52 AM7/22/07
to fcitx-dev
880这个补丁无关紧要,保证这类指针的内容不出问题主要依赖2个编程习惯:
1、保证定义时赋值,可能情况下,尽量保持变量声明和赋值函数之间不要夹杂其它语句:
char *pSource = NULL;
pSource = GetSourcePoint();
现在的C编译器不再限制变量定义必须在函数头部,这种实现是可能的。比较忌讳的是,在变量声明和赋值之间隔上10几条语句,这种情况下,以后修改的时候
就比较难避免出现未赋值而使用的情况。

2、在函数中保证指针被赋值,注意检查return的时候只返回变量pResult:
char* GetSourcePoint( )
{
char* pResult = NULL;
...
return pResult;
}
要注意不能图方便,return一个其它的变量,常量好一点,但是最好是这样:
pResult = NULL;
return pResult;

qxty

unread,
Jul 22, 2007, 6:22:31 AM7/22/07
to fcitx-dev
while (strCodeInput[0] != recordIndex[i].cCode) {
if (!recordIndex[i].cCode)
break;
i++;
}

recordIndex的大小是固定的在这
recordIndex = (RECORD_INDEX *) malloc ((strlen
(table[iTableIMIndex].strInputCode) + 26) * sizeof (RECORD_INDEX));

如果加变量:
int g_recordIndexCount = strlen (table[iTableIMIndex].strInputCode) +
26;
那么下面的匹配程序可以改成这样:
Bool bFind = False;
for (i = 0; i < g_recordIndexCount ; i++)
{
if (!recordIndex[i].cCode) // 最好再检查一下cCode是不是unsigned char
break;
if (!recordIndex[i].record == NULL)
break;

if (strCodeInput[0] == recordIndex[i].cCode)
{
bFind = True;
break;
}
}

if (!bFind)
return -1;

......
在这段程序中使用了隐含规则,就是recordIndex的最后一个记录的record或者cCode等于0,也就是说最后一条记录有双重身份。
recordIndex的赋值,隔的很远,可能后来修改的时候,忘了这条隐含规则。

Lee Duhem

unread,
Jul 22, 2007, 9:41:17 AM7/22/07
to fcit...@googlegroups.com
On Sun, Jul 22, 2007 at 03:28:49PM +0800, dgod wrote:
> 作者是**cjacker* <http://www.linuxsir.org/bbs/member.php?u=2770>
> *全文复制过来
>

最好能让 cjacker 加入这个邮件列表,在论坛上贴 patch 可不太好。

lee

windrosecn

unread,
Jul 23, 2007, 3:58:34 AM7/23/07
to fcitx-dev
cjacker也算是个人物,主持过magiclinux的开发,现在似乎在红旗。

Lee Duhem

unread,
Jul 23, 2007, 7:20:03 AM7/23/07
to fcit...@googlegroups.com
On Mon, Jul 23, 2007 at 07:58:34AM -0000, windrosecn wrote:
> cjacker也算是个人物,主持过magiclinux的开发,现在似乎在红旗。
>

这不正好嘛。

lee

Sutra Zhou

unread,
Jul 26, 2007, 10:47:13 AM7/26/07
to fcit...@googlegroups.com
这个patch的第一个修改可以merge,但是第二个修改和现在的源码已经大相径庭没法merge了。

在07-7-22,dgod <dgod...@gmail.com> 写道:

Lee Duhem

unread,
Jul 27, 2007, 7:43:36 AM7/27/07
to fcit...@googlegroups.com
所以说,不加入本邮件列表就直接修改原码实在不是什么好主意 :-)

lee

在 07-7-26,Sutra Zhou<zhous...@gmail.com> 写道:

Sutra Zhou

unread,
Jul 28, 2007, 1:29:48 PM7/28/07
to fcit...@googlegroups.com
Dear cjacker and all,

I've committed the patch: http://trac.redv.com/fcitx/changeset/110.

Thanks, cjacker and all.

Sutra
2007-07-29 01:28
Reply all
Reply to author
Forward
0 new messages