Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcc7da8

Browse files
committed
Fix for rearranging encoding id ISO-8859-5 to ISO-8859-8.
Also make the code more robust by searching for target encodingin the internal charset map.Problem reported by Sagi Bashari on 2005/12/21.See "[BUGS] BUG #2120: Crash when doing UTF8<->ISO_8859_8 encoding conversion"on pgsql-bugs list for more details.
1 parentea9b028 commitdcc7da8

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

‎src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.16 2005/11/22 18:17:26 momjian Exp $
9+
* $PostgreSQL: pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.17 2005/12/23 02:11:02 ishii Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -68,15 +68,6 @@ typedef struct
6868
}pg_conv_map;
6969

7070
staticpg_conv_mapmaps[]= {
71-
{PG_SQL_ASCII},/* SQL/ASCII */
72-
{PG_EUC_JP},/* EUC for Japanese */
73-
{PG_EUC_CN},/* EUC for Chinese */
74-
{PG_EUC_KR},/* EUC for Korean */
75-
{PG_EUC_TW},/* EUC for Taiwan */
76-
{PG_JOHAB},/* EUC for Korean JOHAB */
77-
{PG_UTF8},/* Unicode UTF8 */
78-
{PG_MULE_INTERNAL},/* Mule internal code */
79-
{PG_LATIN1},/* ISO-8859-1 Latin 1 */
8071
{PG_LATIN2,LUmapISO8859_2,ULmapISO8859_2,
8172
sizeof(LUmapISO8859_2) /sizeof(pg_local_to_utf),
8273
sizeof(ULmapISO8859_2) /sizeof(pg_utf_to_local)},/* ISO-8859-2 Latin 2 */
@@ -104,12 +95,6 @@ static pg_conv_map maps[] = {
10495
{PG_LATIN10,LUmapISO8859_16,ULmapISO8859_16,
10596
sizeof(LUmapISO8859_16) /sizeof(pg_local_to_utf),
10697
sizeof(ULmapISO8859_16) /sizeof(pg_utf_to_local)},/* ISO-8859-16 Latin 10 */
107-
{PG_WIN1256},/* windows-1256 */
108-
{PG_WIN1258},/* Windows-1258 */
109-
{PG_WIN874},/* windows-874 */
110-
{PG_KOI8R},/* KOI8-R */
111-
{PG_WIN1251},/* windows-1251 */
112-
{PG_WIN866},/* (MS-DOS CP866) */
11398
{PG_ISO_8859_5,LUmapISO8859_5,ULmapISO8859_5,
11499
sizeof(LUmapISO8859_5) /sizeof(pg_local_to_utf),
115100
sizeof(ULmapISO8859_5) /sizeof(pg_utf_to_local)},/* ISO-8859-5 */
@@ -131,11 +116,23 @@ iso8859_to_utf8(PG_FUNCTION_ARGS)
131116
unsignedchar*src= (unsignedchar*)PG_GETARG_CSTRING(2);
132117
unsignedchar*dest= (unsignedchar*)PG_GETARG_CSTRING(3);
133118
intlen=PG_GETARG_INT32(4);
119+
inti;
134120

135121
Assert(PG_GETARG_INT32(1)==PG_UTF8);
136122
Assert(len >=0);
137123

138-
LocalToUtf(src,dest,maps[encoding].map1,maps[encoding].size1,encoding,len);
124+
for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
125+
{
126+
if (encoding==maps[i].encoding)
127+
{
128+
LocalToUtf(src,dest,maps[i].map1,maps[i].size1,encoding,len);
129+
PG_RETURN_VOID();
130+
}
131+
}
132+
133+
ereport(ERROR,
134+
(errcode(ERRCODE_INTERNAL_ERROR),
135+
errmsg("unexpected encoding id %d for ISO-8859 charsets",encoding)));
139136

140137
PG_RETURN_VOID();
141138
}
@@ -147,11 +144,23 @@ utf8_to_iso8859(PG_FUNCTION_ARGS)
147144
unsignedchar*src= (unsignedchar*)PG_GETARG_CSTRING(2);
148145
unsignedchar*dest= (unsignedchar*)PG_GETARG_CSTRING(3);
149146
intlen=PG_GETARG_INT32(4);
147+
inti;
150148

151149
Assert(PG_GETARG_INT32(0)==PG_UTF8);
152150
Assert(len >=0);
153151

154-
UtfToLocal(src,dest,maps[encoding].map2,maps[encoding].size2,len);
152+
for (i=0;i<sizeof(maps)/sizeof(pg_conv_map);i++)
153+
{
154+
if (encoding==maps[i].encoding)
155+
{
156+
UtfToLocal(src,dest,maps[i].map2,maps[i].size2,len);
157+
PG_RETURN_VOID();
158+
}
159+
}
160+
161+
ereport(ERROR,
162+
(errcode(ERRCODE_INTERNAL_ERROR),
163+
errmsg("unexpected encoding id %d for ISO-8859 charsets",encoding)));
155164

156165
PG_RETURN_VOID();
157166
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp