Skip to content

Commit 620dbc9

Browse files
committed
make namein multibyte aware
1 parent 9310caf commit 620dbc9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/backend/utils/adt/name.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.36 2002/06/11 13:40:52 wieck Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.37 2002/06/13 06:19:45 ishii Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -23,7 +23,7 @@
2323
#include "utils/array.h"
2424
#include "utils/builtins.h"
2525
#include "utils/lsyscache.h"
26-
26+
#include "mb/pg_wchar.h"
2727

2828
/*****************************************************************************
2929
* USER I/O ROUTINES (none) *
@@ -43,16 +43,20 @@ namein(PG_FUNCTION_ARGS)
4343
char *s = PG_GETARG_CSTRING(0);
4444
NameData *result;
4545
int len;
46+
char *ermsg;
47+
48+
/* veryfy encoding */
49+
len = strlen(s);
50+
if ((ermsg = pg_verifymbstr(s, len)))
51+
elog(ERROR, "%s", ermsg);
52+
53+
len = pg_mbcliplen(s, len, NAMEDATALEN-1);
4654

4755
result = (NameData *) palloc(NAMEDATALEN);
4856
/* always keep it null-padded */
49-
StrNCpy(NameStr(*result), s, NAMEDATALEN);
50-
len = strlen(NameStr(*result));
51-
while (len < NAMEDATALEN)
52-
{
53-
*(NameStr(*result) + len) = '\0';
54-
len++;
55-
}
57+
memset(result, 0, NAMEDATALEN);
58+
memcpy(NameStr(*result), s, len);
59+
5660
PG_RETURN_NAME(result);
5761
}
5862

0 commit comments

Comments
 (0)