summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorPeter Eisentraut2013-10-13 04:09:18 +0000
committerPeter Eisentraut2013-10-13 04:09:18 +0000
commit5b6d08cd2992922b667564a49f19580f11676050 (patch)
tree4104a4255eeb88e78da71477b5f7b129f9a1b599 /src/backend/parser
parenta53dee43fe585e673658b01e7354892dcede957e (diff)
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/parser')
-rw-r--r--src/backend/parser/gram.y33
1 files changed, 4 insertions, 29 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 0efe1705e2..363c603848 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -1450,10 +1450,7 @@ set_rest_more: /* Generic SET syntaxes: */
var_name: ColId { $$ = $1; }
| var_name '.' ColId
- {
- $$ = palloc(strlen($1) + strlen($3) + 2);
- sprintf($$, "%s.%s", $1, $3);
- }
+ { $$ = psprintf("%s.%s", $1, $3); }
;
var_list: var_value { $$ = list_make1($1); }
@@ -10327,15 +10324,7 @@ ConstCharacter: CharacterWithLength
CharacterWithLength: character '(' Iconst ')' opt_charset
{
if (($5 != NULL) && (strcmp($5, "sql_text") != 0))
- {
- char *type;
-
- type = palloc(strlen($1) + 1 + strlen($5) + 1);
- strcpy(type, $1);
- strcat(type, "_");
- strcat(type, $5);
- $1 = type;
- }
+ $1 = psprintf("%s_%s", $1, $5);
$$ = SystemTypeName($1);
$$->typmods = list_make1(makeIntConst($3, @3));
@@ -10346,15 +10335,7 @@ CharacterWithLength: character '(' Iconst ')' opt_charset
CharacterWithoutLength: character opt_charset
{
if (($2 != NULL) && (strcmp($2, "sql_text") != 0))
- {
- char *type;
-
- type = palloc(strlen($1) + 1 + strlen($2) + 1);
- strcpy(type, $1);
- strcat(type, "_");
- strcat(type, $2);
- $1 = type;
- }
+ $1 = psprintf("%s_%s", $1, $2);
$$ = SystemTypeName($1);
@@ -13339,13 +13320,7 @@ doNegateFloat(Value *v)
if (*oldval == '-')
v->val.str = oldval+1; /* just strip the '-' */
else
- {
- char *newval = (char *) palloc(strlen(oldval) + 2);
-
- *newval = '-';
- strcpy(newval+1, oldval);
- v->val.str = newval;
- }
+ v->val.str = psprintf("-%s", oldval);
}
static Node *