aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/misc.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2013-10-13 00:09:18 -0400
committerPeter Eisentraut <peter_e@gmx.net>2013-10-13 00:09:18 -0400
commit5b6d08cd2992922b667564a49f19580f11676050 (patch)
tree4104a4255eeb88e78da71477b5f7b129f9a1b599 /src/backend/utils/adt/misc.c
parenta53dee43fe585e673658b01e7354892dcede957e (diff)
downloadpostgresql-5b6d08cd2992922b667564a49f19580f11676050.tar.gz
postgresql-5b6d08cd2992922b667564a49f19580f11676050.zip
Add use of asprintf()
Add asprintf(), pg_asprintf(), and psprintf() to simplify string allocation and composition. Replacement implementations taken from NetBSD. Reviewed-by: Álvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Asif Naeem <anaeem.it@gmail.com>
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r--src/backend/utils/adt/misc.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index aecdcd056cd..63a991631de 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -242,11 +242,6 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
fctx = palloc(sizeof(ts_db_fctx));
- /*
- * size = tablespace dirname length + dir sep char + oid + terminator
- */
- fctx->location = (char *) palloc(9 + 1 + OIDCHARS + 1 +
- strlen(TABLESPACE_VERSION_DIRECTORY) + 1);
if (tablespaceOid == GLOBALTABLESPACE_OID)
{
fctx->dirdesc = NULL;
@@ -256,9 +251,9 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
else
{
if (tablespaceOid == DEFAULTTABLESPACE_OID)
- sprintf(fctx->location, "base");
+ fctx->location = psprintf("base");
else
- sprintf(fctx->location, "pg_tblspc/%u/%s", tablespaceOid,
+ fctx->location = psprintf("pg_tblspc/%u/%s", tablespaceOid,
TABLESPACE_VERSION_DIRECTORY);
fctx->dirdesc = AllocateDir(fctx->location);
@@ -297,9 +292,7 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
/* if database subdir is empty, don't report tablespace as used */
- /* size = path length + dir sep char + file name + terminator */
- subdir = palloc(strlen(fctx->location) + 1 + strlen(de->d_name) + 1);
- sprintf(subdir, "%s/%s", fctx->location, de->d_name);
+ subdir = psprintf("%s/%s", fctx->location, de->d_name);
dirdesc = AllocateDir(subdir);
while ((de = ReadDir(dirdesc, subdir)) != NULL)
{