1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-15 19:21:59 +03:00

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>
This commit is contained in:
Peter Eisentraut
2013-10-13 00:09:18 -04:00
parent a53dee43fe
commit 5b6d08cd29
47 changed files with 253 additions and 363 deletions

View File

@ -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 *