File: 0011-winime-64bit-fix.patch

package info (click to toggle)
zhcon 1%3A0.2.6-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,756 kB
  • sloc: cpp: 10,942; sh: 2,998; ansic: 1,628; makefile: 56
file content (131 lines) | stat: -rw-r--r-- 4,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Forwarded: not-needed
Description: Fix zhcon crash with built-in input methods on 64-bit platform
 Md82 fixed a zhcon crash when the user tries to type after enabling
 the built-in Chinese input method.  The fix was posted to the LinuxDev
 board on SMTH BBS on 2008-10-11, accessible through this URL:
 .
     http://www.newsmth.net/nForum/#!article/LinuxDev/29280
 .
 ==============================================================================
 发信人: Md82 (我是KCN的一条狗啊), 信区: LinuxDev
 标  题: 一上午时间终于把zhcon的输入法在x86-64调通
 发信站: 水木社区 (Sat Oct 11 09:36:29 2008), 站内
 .
 zhcon0.2.6的输入法不能在 x86-64上运行,一输入字符就报告段错误
 fedora9和fedora10打包的两个binary rpm也一样的问题
 .
 阅读代码后发现原作者假设所有机器都是32位指针,所以直接把码表文件(每单元4bytes)
 映射到char**数组。在x86-64中,一个char*占了8字节,结果变成由两个码表的偏移量数
 值错位32后或出来,明显会超界。
 .
 解决办法是把几个数组从char**改成int *,以及修改了相关的偏移量计算代码。现在终
 于可以在console灌水了。
 .
 具体修改的文件是src/winime.cpp和src/winime.h。
 --
 .
 自由对于笨人是极端痛苦的事情,不亚于把他们投入真空。
 对于聪明人则不然。
 .
 .
 ※ 修改:·Md82 于 Oct 11 09:38:01 2008 修改本文·[FROM: 115.130.13.*]
 ※ 来源:·水木社区 http://newsmth.net·[FROM: 115.130.13.*]
 .
 .
 附件(8.7KB) winime.cpp (http://att.newsmth.net/nForum/att/LinuxDev/29280/839)
 附件(2.8KB) winime.h   (http://att.newsmth.net/nForum/att/LinuxDev/29280/9818)
 ==============================================================================

Author: Md82@bbs.newsmth.net
Origin: other
Bug-Debian: https://bugs.debian.org/501912, https://bugs.debian.org/805544
Reviewed-by: Yu Guanghui <ygh@debian.org>, Anthony Fok <foka@debian.org>
Last-Update: 2018-08-06
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/winime.cpp
+++ b/src/winime.cpp
@@ -56,10 +56,10 @@
 
     memcpy(&mHead, mpBuf, sizeof(mHead));
     int len = strlen(mHead.mCodeSet);
-    mpIndex1 = (char **) (mpBuf + sizeof(mHead));
-    mpIndex2 = (char **) (mpBuf + sizeof(mHead) + len * sizeof(char *));
-    mpText = mpBuf + sizeof(mHead) + len * sizeof(char *) +
-                len * len * sizeof(char *);
+    mpIndex1 = (int *) (mpBuf + sizeof(mHead));
+    mpIndex2 = (int *) (mpBuf + sizeof(mHead) + len * sizeof(int));
+    mpText = mpBuf + sizeof(mHead) + len * sizeof(int) +
+                len * len * sizeof(int);
 }
 
 WinIme::~WinIme() {
@@ -231,6 +231,9 @@
     char *p = NULL;
     bool found = true;
     mInput[mNum] = c;
+
+
+
     if (mNum == 0) {
         //1st level index
         //maybe prevent wildchar in 1st index is a good ideal
@@ -246,7 +249,9 @@
             //                p = *t;
         }
         else
-            p = mpIndex1[Index(c)];
+	{
+            p = (char *)mpIndex1[Index(c)];
+	}
 
         if (p == (char *) 0xffffffff)
             found = false;
@@ -257,20 +262,21 @@
         if (c == mHead.mWildChar) {
             char **t;
             t =
-                find_if(mpIndex2 + Index(mInput[0]) * l,
-                        mpIndex2 + (Index(mInput[0]) + 1) * l,
+                find_if((char **)(mpIndex2 + Index(mInput[0]) * l),
+                        (char **)(mpIndex2 + (Index(mInput[0]) + 1) * l),
                         bind2nd(not_equal_to < char *>(),
                                 (char *) 0xffffffff));
-            if (t == mpIndex2 + (Index(mInput[0]) + 1) * l)
+            if (t == ((char **)mpIndex2) + (Index(mInput[0]) + 1) * l)
+	    {
                 p = (char *) 0xffffffff;
+	    }
             else
                 p = *t;
         } else
-            p = mpIndex2[Index(mInput[0]) * l + Index(c)];
+            p = (char *)(mpIndex2[Index(mInput[0]) * l + Index(c)]);
 
         if (p == (char *) 0xffffffff)
             found = false;
-
         p = (unsigned long) p + mpText;
     } else if (mNum < mHead.mMaxCodes) {
         p = mpOffset[mNum - 1];
--- a/src/winime.h
+++ b/src/winime.h
@@ -80,15 +80,15 @@
         char mInput[12 + 1];
         bool mGBKOut;
         Candilist* mpList;
-        char* mpOffset[12];
+        char * mpOffset[12];
         int mFd;
         char* mpBuf;
-        char** mpIndex1;
-        char** mpIndex2;
+        int *mpIndex1;
+        int *mpIndex2;
         char* mpText;
         char* mpCur;                  //current search position
         unsigned int mBufSize;
         unsigned int mCandilistBufLen;
         WinImeHead mHead;
 };
 #endif