Fix incorrect encoding-aware name truncation in makeArrayTypeName().
truncate_identifier won't do anything if the passed-in strlen is already less than NAMEDATALEN, which it always would be given the strlcpy usage. This has been broken since the arrays-of-composite-types code went in. Arguably truncate_identifier is suffering from excessive optimization and should always process the string, but for the moment I'll take the more localized patch. Per bug #4987.
This commit is contained in:
parent
08d1d61769
commit
ef75f74f4c
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.126 2009/06/11 14:48:55 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.126.2.1 2009/08/16 18:14:39 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -686,23 +686,27 @@ RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
|
|||||||
char *
|
char *
|
||||||
makeArrayTypeName(const char *typeName, Oid typeNamespace)
|
makeArrayTypeName(const char *typeName, Oid typeNamespace)
|
||||||
{
|
{
|
||||||
char *arr;
|
char *arr = (char *) palloc(NAMEDATALEN);
|
||||||
int i;
|
int namelen = strlen(typeName);
|
||||||
Relation pg_type_desc;
|
Relation pg_type_desc;
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The idea is to prepend underscores as needed until we make a name that
|
* The idea is to prepend underscores as needed until we make a name that
|
||||||
* doesn't collide with anything...
|
* doesn't collide with anything...
|
||||||
*/
|
*/
|
||||||
arr = palloc(NAMEDATALEN);
|
|
||||||
|
|
||||||
pg_type_desc = heap_open(TypeRelationId, AccessShareLock);
|
pg_type_desc = heap_open(TypeRelationId, AccessShareLock);
|
||||||
|
|
||||||
for (i = 1; i < NAMEDATALEN - 1; i++)
|
for (i = 1; i < NAMEDATALEN - 1; i++)
|
||||||
{
|
{
|
||||||
arr[i - 1] = '_';
|
arr[i - 1] = '_';
|
||||||
strlcpy(arr + i, typeName, NAMEDATALEN - i);
|
if (i + namelen < NAMEDATALEN)
|
||||||
truncate_identifier(arr, strlen(arr), false);
|
strcpy(arr + i, typeName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(arr + i, typeName, NAMEDATALEN - i);
|
||||||
|
truncate_identifier(arr, NAMEDATALEN, false);
|
||||||
|
}
|
||||||
if (!SearchSysCacheExists(TYPENAMENSP,
|
if (!SearchSysCacheExists(TYPENAMENSP,
|
||||||
CStringGetDatum(arr),
|
CStringGetDatum(arr),
|
||||||
ObjectIdGetDatum(typeNamespace),
|
ObjectIdGetDatum(typeNamespace),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user