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
132
133
134
135
136
137
138
139
140
|
--- leif/freewnn/freewnn.c.orig Sun Mar 20 11:41:29 2005
+++ leif/freewnn/freewnn.c Wed May 18 01:20:56 2005
@@ -59,7 +59,7 @@
#define BUFSIZE 1024
#endif
-#define WNNRCFILE "/etc/FreeWnn/ja/wnnenvrc"
+#define WNNRCFILE "%%LOCALBASE%%" "/lib/wnn/ja_JP/wnnenvrc"
#define CSC_OPEN_LOCALE "csconv_open_locale"
#define CSC_OPEN "csconv_open"
@@ -162,7 +162,7 @@
int count = 0;
if( str == NULL ) return NULL;
- if( *str == '\0' ) return NULL;
+ if( *str == '\0' ) return "";
for(i=0;i<strlen(str);i++) {
count++;
@@ -201,7 +201,7 @@
if( wstr == NULL ) return NULL;
- if( *wstr == 0 ) return NULL;
+ if( *wstr == 0 ) return "";
for(i=0;wstr[i] != 0;i++)
count++;
@@ -388,14 +388,14 @@
UTFCHAR*
UTF8_to_UTFCHAR(unsigned char* str) {
- UTFCHAR *p, *ustr = NULL;
+ UTFCHAR *ustr = NULL;
int len, ulen;
const char *csc_arg_str_ccp; /* For compiler optimization */
char *csc_arg_str_cp; /* For compiler optimization */
if( str == NULL ) return NULL;
- if( *str == '\0' ) return NULL;
+ if( *str == '\0' ) return "";
if( csconv_utf8_cd == NULL ) {
csconv_utf8_cd = csc_open("UTF-16", "UTF-8");
@@ -408,30 +408,34 @@
len = strlen(str);
ulen = sizeof(UTFCHAR)*(len+1);
- p = ustr = (UTFCHAR*)calloc(len+1, sizeof(UTFCHAR));
+ ustr = (UTFCHAR*)malloc(ulen);
+ if (!ustr) return NULL;
+ memset(ustr, 0, ulen);
+ ulen--;
/* Below 2 lines are to prevent gcc's warning and for the sake
of compiler optimization */
csc_arg_str_ccp = (const char*)str;
csc_arg_str_cp = (char*)ustr;
- csc_conv(csconv_utf8_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen);
-
- *ustr = 0;
+ if ((size_t)-1 == csc_conv(csconv_utf8_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen)) {
+ free(ustr);
+ return NULL;
+ }
- return p;
+ return ustr;
}
UTFCHAR*
euc2UTFCHAR(unsigned char* str) {
- UTFCHAR *p, *ustr = NULL;
+ UTFCHAR *ustr = NULL;
int len, ulen;
const char *csc_arg_str_ccp; /* For compiler optimization */
char *csc_arg_str_cp; /* For compiler optimization */
if( str == NULL ) return NULL;
- if( *str == '\0' ) return NULL;
+ if( *str == '\0' ) return "";
if( csconv_cd == NULL ) {
csconv_cd = csc_open_locale("ja_JP.eucJP", "UTF-16", "MultiByte");
@@ -444,18 +448,22 @@
len = strlen(str);
ulen = sizeof(UTFCHAR)*(len+1);
- p = ustr = (UTFCHAR*)calloc(len+1, sizeof(UTFCHAR));
+ ustr = (UTFCHAR*)malloc(ulen);
+ if (!ustr) return NULL;
+ memset(ustr, 0, ulen);
+ ulen--;
/* Below 2 lines are to prevent gcc's warning and for the sake
of compiler optimization */
csc_arg_str_ccp = (const char*)str;
csc_arg_str_cp = (char*)ustr;
- csc_conv(csconv_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen);
-
- *ustr = 0;
+ if ((size_t)-1 == csc_conv(csconv_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen)) {
+ free(ustr);
+ return NULL;
+ }
- return p;
+ return ustr;
}
IMText*
@@ -466,7 +474,10 @@
ustr = UTF8_to_UTFCHAR(str);
p = create_IMText(s, ustrlen(ustr));
- memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
+ if (p && ustr) {
+ memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
+ }
+ if (ustr) free(ustr);
return p;
}
@@ -479,7 +490,10 @@
ustr = euc2UTFCHAR(str);
p = create_IMText(s, ustrlen(ustr));
- memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
+ if (p && ustr) {
+ memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
+ }
+ if (ustr) free(ustr);
return p;
}
|