Skip to content

Commit 55c3391

Browse files
committed
Be pickier about converting between Name and Datum.
We were misapplying NameGetDatum() to plain C strings in some places. This worked, because it was just a pointer cast anyway, but it's a type cheat in some sense. Use CStringGetDatum instead, and modify the NameGetDatum macro so it won't compile if applied to something that's not a pointer to NameData. This should result in no changes to generated code, but it is logically cleaner. Mark Dilger, tweaked a bit by me Discussion: <EFD8AC94-4C1F-40C1-A5EA-304080089C1B@gmail.com>
1 parent fdc79e1 commit 55c3391

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/backend/commands/dbcommands.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ movedb(const char *dbname, const char *tblspcname)
12601260
ScanKeyInit(&scankey,
12611261
Anum_pg_database_datname,
12621262
BTEqualStrategyNumber, F_NAMEEQ,
1263-
NameGetDatum(dbname));
1263+
CStringGetDatum(dbname));
12641264
sysscan = systable_beginscan(pgdbrel, DatabaseNameIndexId, true,
12651265
NULL, 1, &scankey);
12661266
oldtuple = systable_getnext(sysscan);
@@ -1486,7 +1486,7 @@ AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
14861486
ScanKeyInit(&scankey,
14871487
Anum_pg_database_datname,
14881488
BTEqualStrategyNumber, F_NAMEEQ,
1489-
NameGetDatum(stmt->dbname));
1489+
CStringGetDatum(stmt->dbname));
14901490
scan = systable_beginscan(rel, DatabaseNameIndexId, true,
14911491
NULL, 1, &scankey);
14921492
tuple = systable_getnext(scan);
@@ -1603,7 +1603,7 @@ AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
16031603
ScanKeyInit(&scankey,
16041604
Anum_pg_database_datname,
16051605
BTEqualStrategyNumber, F_NAMEEQ,
1606-
NameGetDatum(dbname));
1606+
CStringGetDatum(dbname));
16071607
scan = systable_beginscan(rel, DatabaseNameIndexId, true,
16081608
NULL, 1, &scankey);
16091609
tuple = systable_getnext(scan);
@@ -1743,7 +1743,7 @@ get_db_info(const char *name, LOCKMODE lockmode,
17431743
ScanKeyInit(&scanKey,
17441744
Anum_pg_database_datname,
17451745
BTEqualStrategyNumber, F_NAMEEQ,
1746-
NameGetDatum(name));
1746+
CStringGetDatum(name));
17471747

17481748
scan = systable_beginscan(relation, DatabaseNameIndexId, true,
17491749
NULL, 1, &scanKey);

src/backend/commands/proclang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ find_language_template(const char *languageName)
463463
ScanKeyInit(&key,
464464
Anum_pg_pltemplate_tmplname,
465465
BTEqualStrategyNumber, F_NAMEEQ,
466-
NameGetDatum(languageName));
466+
CStringGetDatum(languageName));
467467
scan = systable_beginscan(rel, PLTemplateNameIndexId, true,
468468
NULL, 1, &key);
469469

src/backend/commands/typecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,7 @@ AlterTypeNamespaceInternal(Oid typeOid, Oid nspOid,
35033503

35043504
/* check for duplicate name (more friendly than unique-index failure) */
35053505
if (SearchSysCacheExists2(TYPENAMENSP,
3506-
CStringGetDatum(NameStr(typform->typname)),
3506+
NameGetDatum(&typform->typname),
35073507
ObjectIdGetDatum(nspOid)))
35083508
ereport(ERROR,
35093509
(errcode(ERRCODE_DUPLICATE_OBJECT),

src/include/postgres.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ typedef Datum *DatumPtr;
600600
* value has adequate lifetime.
601601
*/
602602

603-
#define NameGetDatum(X) PointerGetDatum(X)
603+
#define NameGetDatum(X) CStringGetDatum(NameStr(*(X)))
604604

605605
/*
606606
* DatumGetInt64

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