1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-17 06:41:24 +03:00

Replace argument-checking Asserts with regular test-and-elog checks in all

encoding conversion functions.  These are not can't-happen cases because
it's possible to create a conversion with the wrong conversion function
for the specified encoding pair.  That would lead to an Assert crash in
an Assert-enabled build, or incorrect conversion otherwise, neither of
which is desirable.  This would be a DOS issue if production databases
were customarily built with asserts enabled, but fortunately that's not so.
Per an observation by Heikki.

Back-patch to all supported branches.
This commit is contained in:
Tom Lane 2009-01-29 19:25:15 +00:00
parent d8b324ebd8
commit 20112509bc
28 changed files with 170 additions and 296 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c,v 1.6 2003/08/04 02:40:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/ascii_and_mic/ascii_and_mic.c,v 1.6.4.1 2009/01/29 19:25:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -39,9 +39,7 @@ ascii_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII); CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
pg_ascii2mic(src, dest, len); pg_ascii2mic(src, dest, len);
@ -55,9 +53,7 @@ mic_to_ascii(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_SQL_ASCII);
Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
Assert(len >= 0);
pg_mic2ascii(src, dest, len); pg_mic2ascii(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.6.4.2 2008/03/20 10:52:57 heikki Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/cyrillic_and_mic/cyrillic_and_mic.c,v 1.6.4.3 2009/01/29 19:25:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -86,9 +86,7 @@ koi8r_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_KOI8R); CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
koi8r2mic(src, dest, len); koi8r2mic(src, dest, len);
@ -102,9 +100,7 @@ mic_to_koi8r(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len >= 0);
mic2koi8r(src, dest, len); mic2koi8r(src, dest, len);
@ -118,9 +114,7 @@ iso_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5); CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
iso2mic(src, dest, len); iso2mic(src, dest, len);
@ -134,9 +128,7 @@ mic_to_iso(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_ISO_8859_5);
Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
Assert(len >= 0);
mic2iso(src, dest, len); mic2iso(src, dest, len);
@ -150,9 +142,7 @@ win1251_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1251); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
win12512mic(src, dest, len); win12512mic(src, dest, len);
@ -166,9 +156,7 @@ mic_to_win1251(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len >= 0);
mic2win1251(src, dest, len); mic2win1251(src, dest, len);
@ -182,9 +170,7 @@ alt_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_ALT); CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
alt2mic(src, dest, len); alt2mic(src, dest, len);
@ -198,9 +184,7 @@ mic_to_alt(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len >= 0);
mic2alt(src, dest, len); mic2alt(src, dest, len);
@ -215,9 +199,7 @@ koi8r_to_win1251(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_KOI8R); CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
koi8r2mic(src, buf, len); koi8r2mic(src, buf, len);
@ -235,9 +217,7 @@ win1251_to_koi8r(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_WIN1251); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
win12512mic(src, buf, len); win12512mic(src, buf, len);
@ -255,9 +235,7 @@ koi8r_to_alt(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_KOI8R); CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
koi8r2mic(src, buf, len); koi8r2mic(src, buf, len);
@ -275,9 +253,7 @@ alt_to_koi8r(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ALT); CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
alt2mic(src, buf, len); alt2mic(src, buf, len);
@ -295,9 +271,7 @@ alt_to_win1251(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ALT); CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len >= 0);
/* /*
* Note: There are a few characters like the "Numero" sign that exist in * Note: There are a few characters like the "Numero" sign that exist in
@ -321,9 +295,7 @@ win1251_to_alt(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_WIN1251); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len >= 0);
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */ /* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
@ -342,9 +314,7 @@ iso_to_koi8r(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5); CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
iso2mic(src, buf, len); iso2mic(src, buf, len);
@ -362,9 +332,7 @@ koi8r_to_iso(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_KOI8R); CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_ISO_8859_5);
Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
koi8r2mic(src, buf, len); koi8r2mic(src, buf, len);
@ -382,9 +350,7 @@ iso_to_win1251(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5); CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len >= 0);
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */ /* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
@ -403,9 +369,7 @@ win1251_to_iso(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_WIN1251); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_ISO_8859_5);
Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
Assert(len >= 0);
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */ /* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
@ -424,9 +388,7 @@ iso_to_alt(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ISO_8859_5); CHECK_ENCODING_CONVERSION_ARGS(PG_ISO_8859_5, PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len >= 0);
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */ /* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
@ -445,9 +407,7 @@ alt_to_iso(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_ALT); CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_ISO_8859_5);
Assert(PG_GETARG_INT32(1) == PG_ISO_8859_5);
Assert(len >= 0);
/* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */ /* Use mic/KOI8R as intermediary, see comment in alt_to_win1251() */
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_cn_and_mic/euc_cn_and_mic.c,v 1.6.4.2 2009/01/29 19:25:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -42,9 +42,7 @@ euc_cn_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_CN); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_CN, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
euc_cn2mic(src, dest, len); euc_cn2mic(src, dest, len);
@ -58,9 +56,7 @@ mic_to_euc_cn(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_CN);
Assert(PG_GETARG_INT32(1) == PG_EUC_CN);
Assert(len >= 0);
mic2euc_cn(src, dest, len); mic2euc_cn(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.6.4.3 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_jp_and_sjis/euc_jp_and_sjis.c,v 1.6.4.4 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -67,9 +67,7 @@ euc_jp_to_sjis(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_EUC_JP); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_SJIS);
Assert(PG_GETARG_INT32(1) == PG_SJIS);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
euc_jp2mic(src, buf, len); euc_jp2mic(src, buf, len);
@ -87,9 +85,7 @@ sjis_to_euc_jp(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_SJIS); CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_EUC_JP);
Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
sjis2mic(src, buf, len); sjis2mic(src, buf, len);
@ -106,9 +102,7 @@ euc_jp_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_JP); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
euc_jp2mic(src, dest, len); euc_jp2mic(src, dest, len);
@ -122,9 +116,7 @@ mic_to_euc_jp(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_JP);
Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
Assert(len >= 0);
mic2euc_jp(src, dest, len); mic2euc_jp(src, dest, len);
@ -138,9 +130,7 @@ sjis_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_SJIS); CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
sjis2mic(src, dest, len); sjis2mic(src, dest, len);
@ -154,9 +144,7 @@ mic_to_sjis(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_SJIS);
Assert(PG_GETARG_INT32(1) == PG_SJIS);
Assert(len >= 0);
mic2sjis(src, dest, len); mic2sjis(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_kr_and_mic/euc_kr_and_mic.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -42,9 +42,7 @@ euc_kr_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_KR); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_KR, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
euc_kr2mic(src, dest, len); euc_kr2mic(src, dest, len);
@ -58,9 +56,7 @@ mic_to_euc_kr(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_KR);
Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
Assert(len >= 0);
mic2euc_kr(src, dest, len); mic2euc_kr(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -55,9 +55,7 @@ euc_tw_to_big5(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_EUC_TW); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_BIG5);
Assert(PG_GETARG_INT32(1) == PG_BIG5);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
euc_tw2mic(src, buf, len); euc_tw2mic(src, buf, len);
@ -75,9 +73,7 @@ big5_to_euc_tw(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_BIG5); CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_EUC_TW);
Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
big52mic(src, buf, len); big52mic(src, buf, len);
@ -94,9 +90,7 @@ euc_tw_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_TW); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
euc_tw2mic(src, dest, len); euc_tw2mic(src, dest, len);
@ -110,9 +104,7 @@ mic_to_euc_tw(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_EUC_TW);
Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
Assert(len >= 0);
mic2euc_tw(src, dest, len); mic2euc_tw(src, dest, len);
@ -126,9 +118,7 @@ big5_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_BIG5); CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
big52mic(src, dest, len); big52mic(src, dest, len);
@ -142,9 +132,7 @@ mic_to_big5(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_BIG5);
Assert(PG_GETARG_INT32(1) == PG_BIG5);
Assert(len >= 0);
mic2big5(src, dest, len); mic2big5(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin2_and_win1250/latin2_and_win1250.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -54,9 +54,7 @@ latin2_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN2); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
latin22mic(src, dest, len); latin22mic(src, dest, len);
@ -70,9 +68,7 @@ mic_to_latin2(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN2);
Assert(PG_GETARG_INT32(1) == PG_LATIN2);
Assert(len >= 0);
mic2latin2(src, dest, len); mic2latin2(src, dest, len);
@ -86,9 +82,7 @@ win1250_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1250); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
win12502mic(src, dest, len); win12502mic(src, dest, len);
@ -102,9 +96,7 @@ mic_to_win1250(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len >= 0);
mic2win1250(src, dest, len); mic2win1250(src, dest, len);
@ -119,9 +111,7 @@ latin2_to_win1250(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_LATIN2); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN2, PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
latin22mic(src, buf, len); latin22mic(src, buf, len);
@ -139,9 +129,7 @@ win1250_to_latin2(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned char *buf; unsigned char *buf;
Assert(PG_GETARG_INT32(0) == PG_WIN1250); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_LATIN2);
Assert(PG_GETARG_INT32(1) == PG_LATIN2);
Assert(len >= 0);
buf = palloc(len * ENCODING_GROWTH_RATE); buf = palloc(len * ENCODING_GROWTH_RATE);
win12502mic(src, buf, len); win12502mic(src, buf, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/latin_and_mic/latin_and_mic.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -54,9 +54,7 @@ latin1_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN1); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
latin12mic(src, dest, len); latin12mic(src, dest, len);
@ -70,9 +68,7 @@ mic_to_latin1(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN1);
Assert(PG_GETARG_INT32(1) == PG_LATIN1);
Assert(len >= 0);
mic2latin1(src, dest, len); mic2latin1(src, dest, len);
@ -86,9 +82,7 @@ latin3_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN3); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN3, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
latin32mic(src, dest, len); latin32mic(src, dest, len);
@ -102,9 +96,7 @@ mic_to_latin3(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN3);
Assert(PG_GETARG_INT32(1) == PG_LATIN3);
Assert(len >= 0);
mic2latin3(src, dest, len); mic2latin3(src, dest, len);
@ -118,9 +110,7 @@ latin4_to_mic(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_LATIN4); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN4, PG_MULE_INTERNAL);
Assert(PG_GETARG_INT32(1) == PG_MULE_INTERNAL);
Assert(len >= 0);
latin42mic(src, dest, len); latin42mic(src, dest, len);
@ -134,9 +124,7 @@ mic_to_latin4(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_MULE_INTERNAL); CHECK_ENCODING_CONVERSION_ARGS(PG_MULE_INTERNAL, PG_LATIN4);
Assert(PG_GETARG_INT32(1) == PG_LATIN4);
Assert(len >= 0);
mic2latin4(src, dest, len); mic2latin4(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_ascii/utf8_and_ascii.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -39,9 +39,7 @@ ascii_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_SQL_ASCII); CHECK_ENCODING_CONVERSION_ARGS(PG_SQL_ASCII, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
/* this looks wrong, but basically we're just rejecting high-bit-set */ /* this looks wrong, but basically we're just rejecting high-bit-set */
pg_ascii2mic(src, dest, len); pg_ascii2mic(src, dest, len);
@ -56,9 +54,7 @@ utf8_to_ascii(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SQL_ASCII);
Assert(PG_GETARG_INT32(1) == PG_SQL_ASCII);
Assert(len >= 0);
/* this looks wrong, but basically we're just rejecting high-bit-set */ /* this looks wrong, but basically we're just rejecting high-bit-set */
pg_mic2ascii(src, dest, len); pg_mic2ascii(src, dest, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_big5/utf8_and_big5.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ big5_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_BIG5); CHECK_ENCODING_CONVERSION_ARGS(PG_BIG5, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapBIG5, LocalToUtf(src, dest, LUmapBIG5,
sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len); sizeof(LUmapBIG5) / sizeof(pg_local_to_utf), PG_BIG5, len);
@ -57,9 +55,7 @@ utf8_to_big5(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_BIG5);
Assert(PG_GETARG_INT32(1) == PG_BIG5);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapBIG5, UtfToLocal(src, dest, ULmapBIG5,
sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), PG_BIG5, len); sizeof(ULmapBIG5) / sizeof(pg_utf_to_local), PG_BIG5, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -53,9 +53,7 @@ utf8_to_koi8r(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_KOI8R);
Assert(PG_GETARG_INT32(1) == PG_KOI8R);
Assert(len >= 0);
UtfToLocal(src, dest, ULmap_KOI8R, UtfToLocal(src, dest, ULmap_KOI8R,
sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), PG_KOI8R, len); sizeof(ULmap_KOI8R) / sizeof(pg_utf_to_local), PG_KOI8R, len);
@ -70,9 +68,7 @@ koi8r_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_KOI8R); CHECK_ENCODING_CONVERSION_ARGS(PG_KOI8R, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapKOI8R, LocalToUtf(src, dest, LUmapKOI8R,
sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len); sizeof(LUmapKOI8R) / sizeof(pg_local_to_utf), PG_KOI8R, len);
@ -87,9 +83,7 @@ utf8_to_win1251(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1251);
Assert(PG_GETARG_INT32(1) == PG_WIN1251);
Assert(len >= 0);
UtfToLocal(src, dest, ULmap_WIN1251, UtfToLocal(src, dest, ULmap_WIN1251,
sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), PG_WIN1251, len); sizeof(ULmap_WIN1251) / sizeof(pg_utf_to_local), PG_WIN1251, len);
@ -104,9 +98,7 @@ win1251_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1251); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1251, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapWIN1251, LocalToUtf(src, dest, LUmapWIN1251,
sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len); sizeof(LUmapWIN1251) / sizeof(pg_local_to_utf), PG_WIN1251, len);
@ -121,9 +113,7 @@ utf8_to_alt(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_ALT);
Assert(PG_GETARG_INT32(1) == PG_ALT);
Assert(len >= 0);
UtfToLocal(src, dest, ULmap_ALT, UtfToLocal(src, dest, ULmap_ALT,
sizeof(ULmap_ALT) / sizeof(pg_utf_to_local), PG_ALT, len); sizeof(ULmap_ALT) / sizeof(pg_utf_to_local), PG_ALT, len);
@ -138,9 +128,7 @@ alt_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_ALT); CHECK_ENCODING_CONVERSION_ARGS(PG_ALT, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapALT, LocalToUtf(src, dest, LUmapALT,
sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len); sizeof(LUmapALT) / sizeof(pg_local_to_utf), PG_ALT, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_cn/utf8_and_euc_cn.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ euc_cn_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_CN); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_CN, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapEUC_CN, LocalToUtf(src, dest, LUmapEUC_CN,
sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len); sizeof(LUmapEUC_CN) / sizeof(pg_local_to_utf), PG_EUC_CN, len);
@ -57,9 +55,7 @@ utf8_to_euc_cn(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_CN);
Assert(PG_GETARG_INT32(1) == PG_EUC_CN);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapEUC_CN, UtfToLocal(src, dest, ULmapEUC_CN,
sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), PG_EUC_CN, len); sizeof(ULmapEUC_CN) / sizeof(pg_utf_to_local), PG_EUC_CN, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_jp/utf8_and_euc_jp.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ euc_jp_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_JP); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_JP, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapEUC_JP, LocalToUtf(src, dest, LUmapEUC_JP,
sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len); sizeof(LUmapEUC_JP) / sizeof(pg_local_to_utf), PG_EUC_JP, len);
@ -57,9 +55,7 @@ utf8_to_euc_jp(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_JP);
Assert(PG_GETARG_INT32(1) == PG_EUC_JP);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapEUC_JP, UtfToLocal(src, dest, ULmapEUC_JP,
sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), PG_EUC_JP, len); sizeof(ULmapEUC_JP) / sizeof(pg_utf_to_local), PG_EUC_JP, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_kr/utf8_and_euc_kr.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ euc_kr_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_KR); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_KR, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapEUC_KR, LocalToUtf(src, dest, LUmapEUC_KR,
sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len); sizeof(LUmapEUC_KR) / sizeof(pg_local_to_utf), PG_EUC_KR, len);
@ -57,9 +55,7 @@ utf8_to_euc_kr(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_KR);
Assert(PG_GETARG_INT32(1) == PG_EUC_KR);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapEUC_KR, UtfToLocal(src, dest, ULmapEUC_KR,
sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), PG_EUC_KR, len); sizeof(ULmapEUC_KR) / sizeof(pg_utf_to_local), PG_EUC_KR, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.6.4.1 2006/05/21 20:06:44 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_euc_tw/utf8_and_euc_tw.c,v 1.6.4.2 2009/01/29 19:25:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ euc_tw_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_EUC_TW); CHECK_ENCODING_CONVERSION_ARGS(PG_EUC_TW, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapEUC_TW, LocalToUtf(src, dest, LUmapEUC_TW,
sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len); sizeof(LUmapEUC_TW) / sizeof(pg_local_to_utf), PG_EUC_TW, len);
@ -57,9 +55,7 @@ utf8_to_euc_tw(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_EUC_TW);
Assert(PG_GETARG_INT32(1) == PG_EUC_TW);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapEUC_TW, UtfToLocal(src, dest, ULmapEUC_TW,
sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), PG_EUC_TW, len); sizeof(ULmapEUC_TW) / sizeof(pg_utf_to_local), PG_EUC_TW, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c,v 1.6.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ gb18030_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_GB18030); CHECK_ENCODING_CONVERSION_ARGS(PG_GB18030, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapGB18030, LocalToUtf(src, dest, LUmapGB18030,
sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), PG_GB18030, len); sizeof(LUmapGB18030) / sizeof(pg_local_to_utf), PG_GB18030, len);
@ -57,9 +55,7 @@ utf8_to_gb18030(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_GB18030);
Assert(PG_GETARG_INT32(1) == PG_GB18030);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapGB18030, UtfToLocal(src, dest, ULmapGB18030,
sizeof(ULmapGB18030) / sizeof(pg_utf_to_local), PG_GB18030, len); sizeof(ULmapGB18030) / sizeof(pg_utf_to_local), PG_GB18030, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gbk/utf8_and_gbk.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_gbk/utf8_and_gbk.c,v 1.6.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ gbk_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_GBK); CHECK_ENCODING_CONVERSION_ARGS(PG_GBK, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapGBK, LocalToUtf(src, dest, LUmapGBK,
sizeof(LUmapGBK) / sizeof(pg_local_to_utf), PG_GBK, len); sizeof(LUmapGBK) / sizeof(pg_local_to_utf), PG_GBK, len);
@ -57,9 +55,7 @@ utf8_to_gbk(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_GBK);
Assert(PG_GETARG_INT32(1) == PG_GBK);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapGBK, UtfToLocal(src, dest, ULmapGBK,
sizeof(ULmapGBK) / sizeof(pg_utf_to_local), PG_GBK, len); sizeof(ULmapGBK) / sizeof(pg_utf_to_local), PG_GBK, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.7.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c,v 1.7.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -132,8 +132,7 @@ iso8859_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(1) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(-1, PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, maps[encoding].map1, maps[encoding].size1, encoding, len); LocalToUtf(src, dest, maps[encoding].map1, maps[encoding].size1, encoding, len);
@ -148,8 +147,7 @@ utf8_to_iso8859(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, -1);
Assert(len >= 0);
UtfToLocal(src, dest, maps[encoding].map2, maps[encoding].size2, encoding, len); UtfToLocal(src, dest, maps[encoding].map2, maps[encoding].size2, encoding, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.7.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c,v 1.7.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ iso8859_1_to_utf8(PG_FUNCTION_ARGS)
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
unsigned short c; unsigned short c;
Assert(PG_GETARG_INT32(0) == PG_LATIN1); CHECK_ENCODING_CONVERSION_ARGS(PG_LATIN1, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
while (len > 0) while (len > 0)
{ {
@ -73,9 +71,7 @@ utf8_to_iso8859_1(PG_FUNCTION_ARGS)
unsigned short c, unsigned short c,
c1; c1;
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_LATIN1);
Assert(PG_GETARG_INT32(1) == PG_LATIN1);
Assert(len >= 0);
while (len > 0) while (len > 0)
{ {

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_johab/utf8_and_johab.c,v 1.6.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ johab_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_JOHAB); CHECK_ENCODING_CONVERSION_ARGS(PG_JOHAB, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapJOHAB, LocalToUtf(src, dest, LUmapJOHAB,
sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), PG_JOHAB, len); sizeof(LUmapJOHAB) / sizeof(pg_local_to_utf), PG_JOHAB, len);
@ -57,9 +55,7 @@ utf8_to_johab(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_JOHAB);
Assert(PG_GETARG_INT32(1) == PG_JOHAB);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapJOHAB, UtfToLocal(src, dest, ULmapJOHAB,
sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), PG_JOHAB, len); sizeof(ULmapJOHAB) / sizeof(pg_utf_to_local), PG_JOHAB, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_sjis/utf8_and_sjis.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_sjis/utf8_and_sjis.c,v 1.6.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ sjis_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_SJIS); CHECK_ENCODING_CONVERSION_ARGS(PG_SJIS, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapSJIS, LocalToUtf(src, dest, LUmapSJIS,
sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len); sizeof(LUmapSJIS) / sizeof(pg_local_to_utf), PG_SJIS, len);
@ -57,9 +55,7 @@ utf8_to_sjis(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_SJIS);
Assert(PG_GETARG_INT32(1) == PG_SJIS);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapSJIS, UtfToLocal(src, dest, ULmapSJIS,
sizeof(ULmapSJIS) / sizeof(pg_utf_to_local), PG_SJIS, len); sizeof(ULmapSJIS) / sizeof(pg_utf_to_local), PG_SJIS, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_tcvn/Attic/utf8_and_tcvn.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_tcvn/Attic/utf8_and_tcvn.c,v 1.6.4.2 2009/01/29 19:25:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ tcvn_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_TCVN); CHECK_ENCODING_CONVERSION_ARGS(PG_TCVN, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapTCVN, LocalToUtf(src, dest, LUmapTCVN,
sizeof(LUmapTCVN) / sizeof(pg_local_to_utf), PG_TCVN, len); sizeof(LUmapTCVN) / sizeof(pg_local_to_utf), PG_TCVN, len);
@ -57,9 +55,7 @@ utf8_to_tcvn(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_TCVN);
Assert(PG_GETARG_INT32(1) == PG_TCVN);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapTCVN, UtfToLocal(src, dest, ULmapTCVN,
sizeof(ULmapTCVN) / sizeof(pg_utf_to_local), PG_TCVN, len); sizeof(ULmapTCVN) / sizeof(pg_utf_to_local), PG_TCVN, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_uhc/utf8_and_uhc.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_uhc/utf8_and_uhc.c,v 1.6.4.2 2009/01/29 19:25:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,9 +40,7 @@ uhc_to_utf8(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UHC); CHECK_ENCODING_CONVERSION_ARGS(PG_UHC, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapUHC, LocalToUtf(src, dest, LUmapUHC,
sizeof(LUmapUHC) / sizeof(pg_local_to_utf), PG_UHC, len); sizeof(LUmapUHC) / sizeof(pg_local_to_utf), PG_UHC, len);
@ -57,9 +55,7 @@ utf8_to_uhc(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_UHC);
Assert(PG_GETARG_INT32(1) == PG_UHC);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapUHC, UtfToLocal(src, dest, ULmapUHC,
sizeof(ULmapUHC) / sizeof(pg_utf_to_local), PG_UHC, len); sizeof(ULmapUHC) / sizeof(pg_utf_to_local), PG_UHC, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1250/Attic/utf8_and_win1250.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1250/Attic/utf8_and_win1250.c,v 1.6.4.2 2009/01/29 19:25:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,9 +41,7 @@ utf_to_win1250(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1250);
Assert(PG_GETARG_INT32(1) == PG_WIN1250);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapWIN1250, UtfToLocal(src, dest, ULmapWIN1250,
sizeof(ULmapWIN1250) / sizeof(pg_utf_to_local), PG_WIN1250, len); sizeof(ULmapWIN1250) / sizeof(pg_utf_to_local), PG_WIN1250, len);
@ -58,9 +56,7 @@ win1250_to_utf(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1250); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1250, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapWIN1250, LocalToUtf(src, dest, LUmapWIN1250,
sizeof(LUmapWIN1250) / sizeof(pg_local_to_utf), PG_WIN1250, len); sizeof(LUmapWIN1250) / sizeof(pg_local_to_utf), PG_WIN1250, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1256/Attic/utf8_and_win1256.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win1256/Attic/utf8_and_win1256.c,v 1.6.4.2 2009/01/29 19:25:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,9 +41,7 @@ utf_to_win1256(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN1256);
Assert(PG_GETARG_INT32(1) == PG_WIN1256);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapWIN1256, UtfToLocal(src, dest, ULmapWIN1256,
sizeof(ULmapWIN1256) / sizeof(pg_utf_to_local), PG_WIN1256, len); sizeof(ULmapWIN1256) / sizeof(pg_utf_to_local), PG_WIN1256, len);
@ -58,9 +56,7 @@ win1256_to_utf(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN1256); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN1256, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapWIN1256, LocalToUtf(src, dest, LUmapWIN1256,
sizeof(LUmapWIN1256) / sizeof(pg_local_to_utf), PG_WIN1256, len); sizeof(LUmapWIN1256) / sizeof(pg_local_to_utf), PG_WIN1256, len);

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win874/Attic/utf8_and_win874.c,v 1.6.4.1 2006/05/21 20:06:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mb/conversion_procs/utf8_and_win874/Attic/utf8_and_win874.c,v 1.6.4.2 2009/01/29 19:25:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,9 +41,7 @@ utf_to_win874(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_UTF8); CHECK_ENCODING_CONVERSION_ARGS(PG_UTF8, PG_WIN874);
Assert(PG_GETARG_INT32(1) == PG_WIN874);
Assert(len >= 0);
UtfToLocal(src, dest, ULmapWIN874, UtfToLocal(src, dest, ULmapWIN874,
sizeof(ULmapWIN874) / sizeof(pg_utf_to_local), PG_WIN874, len); sizeof(ULmapWIN874) / sizeof(pg_utf_to_local), PG_WIN874, len);
@ -58,9 +56,7 @@ win874_to_utf(PG_FUNCTION_ARGS)
unsigned char *dest = PG_GETARG_CSTRING(3); unsigned char *dest = PG_GETARG_CSTRING(3);
int len = PG_GETARG_INT32(4); int len = PG_GETARG_INT32(4);
Assert(PG_GETARG_INT32(0) == PG_WIN874); CHECK_ENCODING_CONVERSION_ARGS(PG_WIN874, PG_UTF8);
Assert(PG_GETARG_INT32(1) == PG_UTF8);
Assert(len >= 0);
LocalToUtf(src, dest, LUmapWIN874, LocalToUtf(src, dest, LUmapWIN874,
sizeof(LUmapWIN874) / sizeof(pg_local_to_utf), PG_WIN874, len); sizeof(LUmapWIN874) / sizeof(pg_local_to_utf), PG_WIN874, len);

View File

@ -1,7 +1,7 @@
/* /*
* conversion functions between pg_wchar and multibyte streams. * conversion functions between pg_wchar and multibyte streams.
* Tatsuo Ishii * Tatsuo Ishii
* $Id: wchar.c,v 1.34.2.5 2008/10/27 19:37:56 tgl Exp $ * $Id: wchar.c,v 1.34.2.6 2009/01/29 19:25:14 tgl Exp $
* *
* WIN1250 client encoding updated by Pavel Behal * WIN1250 client encoding updated by Pavel Behal
* *
@ -1110,6 +1110,39 @@ pg_verify_mbstr(int encoding, const char *mbstr, int len, bool noError)
return true; return true;
} }
/*
* check_encoding_conversion_args: check arguments of a conversion function
*
* "expected" arguments can be either an encoding ID or -1 to indicate that
* the caller will check whether it accepts the ID.
*
* Note: the errors here are not really user-facing, so elog instead of
* ereport seems sufficient. Also, we trust that the "expected" encoding
* arguments are valid encoding IDs, but we don't trust the actuals.
*/
void
check_encoding_conversion_args(int src_encoding,
int dest_encoding,
int len,
int expected_src_encoding,
int expected_dest_encoding)
{
if (!PG_VALID_ENCODING(src_encoding))
elog(ERROR, "invalid source encoding ID: %d", src_encoding);
if (src_encoding != expected_src_encoding && expected_src_encoding >= 0)
elog(ERROR, "expected source encoding \"%s\", but got \"%s\"",
pg_enc2name_tbl[expected_src_encoding].name,
pg_enc2name_tbl[src_encoding].name);
if (!PG_VALID_ENCODING(dest_encoding))
elog(ERROR, "invalid destination encoding ID: %d", dest_encoding);
if (dest_encoding != expected_dest_encoding && expected_dest_encoding >= 0)
elog(ERROR, "expected destination encoding \"%s\", but got \"%s\"",
pg_enc2name_tbl[expected_dest_encoding].name,
pg_enc2name_tbl[dest_encoding].name);
if (len < 0)
elog(ERROR, "encoding conversion length must not be negative");
}
/* /*
* report_invalid_encoding: complain about invalid multibyte character * report_invalid_encoding: complain about invalid multibyte character
* *

View File

@ -1,4 +1,4 @@
/* $Id: pg_wchar.h,v 1.48.4.1 2006/05/21 20:06:45 tgl Exp $ */ /* $Id: pg_wchar.h,v 1.48.4.2 2009/01/29 19:25:14 tgl Exp $ */
#ifndef PG_WCHAR_H #ifndef PG_WCHAR_H
#define PG_WCHAR_H #define PG_WCHAR_H
@ -285,6 +285,19 @@ typedef struct
unsigned int utf; /* UTF-8 */ unsigned int utf; /* UTF-8 */
} pg_local_to_utf; } pg_local_to_utf;
/*
* Support macro for encoding conversion functions to validate their
* arguments. (This could be made more compact if we included fmgr.h
* here, but we don't want to do that because this header file is also
* used by frontends.)
*/
#define CHECK_ENCODING_CONVERSION_ARGS(srcencoding,destencoding) \
check_encoding_conversion_args(PG_GETARG_INT32(0), \
PG_GETARG_INT32(1), \
PG_GETARG_INT32(4), \
(srcencoding), \
(destencoding))
extern int pg_mb2wchar(const unsigned char *from, pg_wchar *to); extern int pg_mb2wchar(const unsigned char *from, pg_wchar *to);
extern int pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len); extern int pg_mb2wchar_with_len(const unsigned char *from, pg_wchar *to, int len);
extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2); extern int pg_char_and_wchar_strcmp(const char *s1, const pg_wchar *s2);
@ -337,6 +350,12 @@ extern bool pg_verifymbstr(const char *mbstr, int len, bool noError);
extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len, extern bool pg_verify_mbstr(int encoding, const char *mbstr, int len,
bool noError); bool noError);
extern void check_encoding_conversion_args(int src_encoding,
int dest_encoding,
int len,
int expected_src_encoding,
int expected_dest_encoding);
extern void report_invalid_encoding(int encoding, const char *mbstr, int len); extern void report_invalid_encoding(int encoding, const char *mbstr, int len);
extern void report_untranslatable_char(int src_encoding, int dest_encoding, extern void report_untranslatable_char(int src_encoding, int dest_encoding,
const char *mbstr, int len); const char *mbstr, int len);