Skip to content

Commit bc2cf76

Browse files
committed
Make makeObjectName multibyte aware. Currently, it may produce
incorrect multibyte sequence while truncating too long names.
1 parent 88d7b4a commit bc2cf76

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/parser/analyze.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: analyze.c,v 1.154 2000/08/11 23:45:27 tgl Exp $
9+
* $Id: analyze.c,v 1.155 2000/08/22 12:59:04 ishii Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -30,6 +30,10 @@
3030
#include "utils/relcache.h"
3131
#include "utils/syscache.h"
3232

33+
#ifdef MULTIBYTE
34+
#include "mb/pg_wchar.h"
35+
#endif
36+
3337
void CheckSelectForUpdate(Query *qry); /* no points for style... */
3438

3539
static Query *transformStmt(ParseState *pstate, Node *stmt);
@@ -550,6 +554,13 @@ makeObjectName(char *name1, char *name2, char *typename)
550554
name2chars--;
551555
}
552556

557+
#ifdef MULTIBYTE
558+
if (name1)
559+
name1chars = pg_mbcliplen(name1, name1chars, name1chars);
560+
if (name2)
561+
name2chars = pg_mbcliplen(name2, name2chars, name2chars);
562+
#endif
563+
553564
/* Now construct the string using the chosen lengths */
554565
name = palloc(name1chars + name2chars + overhead + 1);
555566
strncpy(name, name1, name1chars);

0 commit comments

Comments
 (0)