summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/cash.c22
-rw-r--r--src/backend/utils/adt/dbsize.c28
-rw-r--r--src/backend/utils/adt/misc.c13
3 files changed, 19 insertions, 44 deletions
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index 82551c5f30e..015875875be 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -377,18 +377,16 @@ cash_out(PG_FUNCTION_ARGS)
* from the value.
*----------
*/
- result = palloc(strlen(bufptr) + strlen(csymbol) + strlen(signsymbol) + 4);
-
switch (sign_posn)
{
case 0:
if (cs_precedes)
- sprintf(result, "(%s%s%s)",
+ result = psprintf("(%s%s%s)",
csymbol,
(sep_by_space == 1) ? " " : "",
bufptr);
else
- sprintf(result, "(%s%s%s)",
+ result = psprintf("(%s%s%s)",
bufptr,
(sep_by_space == 1) ? " " : "",
csymbol);
@@ -396,14 +394,14 @@ cash_out(PG_FUNCTION_ARGS)
case 1:
default:
if (cs_precedes)
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
signsymbol,
(sep_by_space == 2) ? " " : "",
csymbol,
(sep_by_space == 1) ? " " : "",
bufptr);
else
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
signsymbol,
(sep_by_space == 2) ? " " : "",
bufptr,
@@ -412,14 +410,14 @@ cash_out(PG_FUNCTION_ARGS)
break;
case 2:
if (cs_precedes)
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
csymbol,
(sep_by_space == 1) ? " " : "",
bufptr,
(sep_by_space == 2) ? " " : "",
signsymbol);
else
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
bufptr,
(sep_by_space == 1) ? " " : "",
csymbol,
@@ -428,14 +426,14 @@ cash_out(PG_FUNCTION_ARGS)
break;
case 3:
if (cs_precedes)
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
signsymbol,
(sep_by_space == 2) ? " " : "",
csymbol,
(sep_by_space == 1) ? " " : "",
bufptr);
else
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
bufptr,
(sep_by_space == 1) ? " " : "",
signsymbol,
@@ -444,14 +442,14 @@ cash_out(PG_FUNCTION_ARGS)
break;
case 4:
if (cs_precedes)
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
csymbol,
(sep_by_space == 2) ? " " : "",
signsymbol,
(sep_by_space == 1) ? " " : "",
bufptr);
else
- sprintf(result, "%s%s%s%s%s",
+ result = psprintf("%s%s%s%s%s",
bufptr,
(sep_by_space == 1) ? " " : "",
csymbol,
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 868474680df..08ea4570017 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -627,18 +627,14 @@ pg_size_pretty_numeric(PG_FUNCTION_ARGS)
Numeric size = PG_GETARG_NUMERIC(0);
Numeric limit,
limit2;
- char *buf,
- *result;
+ char *result;
limit = int64_to_numeric(10 * 1024);
limit2 = int64_to_numeric(10 * 1024 * 2 - 1);
if (numeric_is_less(size, limit))
{
- buf = numeric_to_cstring(size);
- result = palloc(strlen(buf) + 7);
- strcpy(result, buf);
- strcat(result, " bytes");
+ result = psprintf("%s bytes", numeric_to_cstring(size));
}
else
{
@@ -650,10 +646,7 @@ pg_size_pretty_numeric(PG_FUNCTION_ARGS)
{
/* size = (size + 1) / 2 */
size = numeric_plus_one_over_two(size);
- buf = numeric_to_cstring(size);
- result = palloc(strlen(buf) + 4);
- strcpy(result, buf);
- strcat(result, " kB");
+ result = psprintf("%s kB", numeric_to_cstring(size));
}
else
{
@@ -663,10 +656,7 @@ pg_size_pretty_numeric(PG_FUNCTION_ARGS)
{
/* size = (size + 1) / 2 */
size = numeric_plus_one_over_two(size);
- buf = numeric_to_cstring(size);
- result = palloc(strlen(buf) + 4);
- strcpy(result, buf);
- strcat(result, " MB");
+ result = psprintf("%s MB", numeric_to_cstring(size));
}
else
{
@@ -677,10 +667,7 @@ pg_size_pretty_numeric(PG_FUNCTION_ARGS)
{
/* size = (size + 1) / 2 */
size = numeric_plus_one_over_two(size);
- buf = numeric_to_cstring(size);
- result = palloc(strlen(buf) + 4);
- strcpy(result, buf);
- strcat(result, " GB");
+ result = psprintf("%s GB", numeric_to_cstring(size));
}
else
{
@@ -688,10 +675,7 @@ pg_size_pretty_numeric(PG_FUNCTION_ARGS)
size = numeric_shift_right(size, 10);
/* size = (size + 1) / 2 */
size = numeric_plus_one_over_two(size);
- buf = numeric_to_cstring(size);
- result = palloc(strlen(buf) + 4);
- strcpy(result, buf);
- strcat(result, " TB");
+ result = psprintf("%s TB", numeric_to_cstring(size));
}
}
}
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)
{