From: Tatsuo Ishii Date: Thu, 2 Nov 2000 05:11:42 +0000 (+0000) Subject: Fix for inserting/copying longer multibyte strings into bpchar data X-Git-Tag: REL7_0_3~7 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=75413f7af95ec6532199db7ccabff5debc3d82c3;p=postgresql.git Fix for inserting/copying longer multibyte strings into bpchar data types. --- diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index dcb1503d42f..98b0cbbdc33 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.1 2000/07/07 21:29:57 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.2 2000/11/02 05:11:42 ishii Exp $ * *------------------------------------------------------------------------- */ @@ -79,7 +79,17 @@ bpcharin(char *s, int dummy, int32 atttypmod) atttypmod = len + VARHDRSZ; } else +#ifdef MULTIBYTE + { + /* + * truncate multi-byte string preserving multi-byte + * boundary + */ + len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ); + } +#else len = atttypmod - VARHDRSZ; +#endif result = (char *) palloc(atttypmod); VARSIZE(result) = atttypmod; @@ -96,7 +106,11 @@ bpcharin(char *s, int dummy, int32 atttypmod) #endif /* blank pad the string if necessary */ +#ifdef MULTIBYTE + for (; i < atttypmod - VARHDRSZ; i++) +#else for (; i < len; i++) +#endif *r++ = ' '; return result; } @@ -161,7 +175,7 @@ bpchar(char *s, int32 len) #ifdef MULTIBYTE /* - * truncate multi-byte string in a way not to break multi-byte + * truncate multi-byte string preserving multi-byte * boundary */ if (VARSIZE(s) > len) @@ -326,7 +340,14 @@ varcharin(char *s, int dummy, int32 atttypmod) len = strlen(s) + VARHDRSZ; if (atttypmod >= (int32) VARHDRSZ && len > atttypmod) - len = atttypmod; /* clip the string at max length */ + { + /* clip the string at max length */ +#ifdef MULTIBYTE + len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ; +#else + len = atttypmod; +#endif + } result = (char *) palloc(len); VARSIZE(result) = len; @@ -388,7 +409,7 @@ varchar(char *s, int32 slen) #ifdef MULTIBYTE /* - * truncate multi-byte string in a way not to break multi-byte + * truncate multi-byte string preserving the multi-byte * boundary */ len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);