8000 Fix for inserting/copying longer multibyte strings into bpchar data · percona/postgres@75413f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75413f7

Browse files
committed
Fix for inserting/copying longer multibyte strings into bpchar data
types.
1 parent 6779723 commit 75413f7

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/backend/utils/adt/varchar.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.1 2000/07/07 21:29:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.60.2.2 2000/11/02 05:11:42 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -79,7 +79,17 @@ bpcharin(char *s, int dummy, int32 atttypmod)
7979
atttypmod = len + VARHDRSZ;
8080
}
8181
else
82+
#ifdef MULTIBYTE
83+
{
84+
/*
85+
* truncate multi-byte string preserving multi-byte
86+
* boundary
87+
*/
88+
len = pg_mbcliplen(s, atttypmod - VARHDRSZ, atttypmod - VARHDRSZ);
89+
}
90+
#else
8291
len = atttypmod - VARHDRSZ;
92+
#endif
8393

8494
result = (char *) palloc(atttypmod);
8595
VARSIZE(result) = atttypmod;
@@ -96,7 +106,11 @@ bpcharin(char *s, int dummy, int32 atttypmod)
96106
#endif
97107

98108
/* blank pad the string if necessary */
109+
#ifdef MULTIBYTE
110+
for (; i < atttypmod - VARHDRSZ; i++)
111+
#else
99112
for (; i < len; i++)
113+
#endif
100114
*r++ = ' ';
101115
return result;
102116
}
@@ -161,7 +175,7 @@ bpchar(char *s, int32 len)
161175
#ifdef MULTIBYTE
162176

163177
/*
164-
* truncate multi-byte string in a way not to break multi-byte
178+
* truncate multi-byte string preserving multi-byte
165179
* boundary
166180
*/
167181
if (VARSIZE(s) > len)
@@ -326,7 +340,14 @@ varcharin(char *s, int dummy, int32 atttypmod)
326340

327341
len = strlen(s) + VARHDRSZ;
328342
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
329-
len = atttypmod; /* clip the string at max length */
343+
{
344+
/* clip the string at max length */
345+
#ifdef MULTIBYTE
346+
len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ;
347+
#else
348+
len = atttypmod;
349+
#endif
350+
}
330351

331352
result = (char *) palloc(len);
332353
VARSIZE(result) = len;
@@ -388,7 +409,7 @@ varchar(char *s, int32 slen)
388409
#ifdef MULTIBYTE
389410

390411
/*
391-
* truncate multi-byte string in a way not to break multi-byte
412+
* truncate multi-byte string preserving the multi-byte
392413
* boundary
393414
*/
394415
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);

0 commit comments

Comments
 (0)
0