aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/cash.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/cash.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/cash.c')
-rw-r--r--src/backend/utils/adt/cash.c22
1 files changed, 10 insertions, 12 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,