Skip to content

Commit dc77922

Browse files
committed
Fix for inserting/copying longer multibyte strings into bpchar data
types.
1 parent ca1c7e6 commit dc77922

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/backend/utils/adt/varchar.c

Lines changed: 20 additions & 2 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.70 2000/11/21 21:16:02 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.71 2000/11/26 11:35:23 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -79,7 +79,17 @@ bpcharin(PG_FUNCTION_ARGS)
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 = (BpChar *) palloc(atttypmod);
8595
VARATT_SIZEP(result) = atttypmod;
@@ -96,7 +106,11 @@ bpcharin(PG_FUNCTION_ARGS)
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

102116
PG_RETURN_BPCHAR_P(result);
@@ -329,7 +343,11 @@ varcharin(PG_FUNCTION_ARGS)
329343

330344
len = strlen(s) + VARHDRSZ;
331345
if (atttypmod >= (int32) VARHDRSZ && len > atttypmod)
346+
#ifdef MULTIBYTE
347+
len = pg_mbcliplen(s, len - VARHDRSZ, atttypmod - VARHDRSZ) + VARHDRSZ;
348+
#else
332349
len = atttypmod; /* clip the string at max length */
350+
#endif
333351

334352
result = (VarChar *) palloc(len);
335353
VARATT_SIZEP(result) = len;
@@ -383,7 +401,7 @@ varchar(PG_FUNCTION_ARGS)
383401
#ifdef MULTIBYTE
384402

385403
/*
386-
* truncate multi-byte string in a way not to break multi-byte
404+
* truncate multi-byte string preserving multi-byte
387405
* boundary
388406
*/
389407
len = pg_mbcliplen(VARDATA(s), slen - VARHDRSZ, slen - VARHDRSZ);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy