1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +03:00

Add more use of psprintf()

This commit is contained in:
Peter Eisentraut
2014-01-06 21:30:26 -05:00
parent 10a82cda67
commit edc43458d7
15 changed files with 52 additions and 119 deletions

View File

@@ -2757,8 +2757,7 @@ pg_get_multixact_members(PG_FUNCTION_ARGS)
HeapTuple tuple;
char *values[2];
values[0] = palloc(32);
sprintf(values[0], "%u", multi->members[multi->iter].xid);
values[0] = psprintf("%u", multi->members[multi->iter].xid);
values[1] = mxstatus_to_string(multi->members[multi->iter].status);
tuple = BuildTupleFromCStrings(funccxt->attinmeta, values);

View File

@@ -56,12 +56,7 @@ defGetString(DefElem *def)
switch (nodeTag(def->arg))
{
case T_Integer:
{
char *str = palloc(32);
snprintf(str, 32, "%ld", (long) intVal(def->arg));
return str;
}
return psprintf("%ld", (long) intVal(def->arg));
case T_Float:
/*

View File

@@ -778,10 +778,7 @@ build_subplan(PlannerInfo *root, Plan *plan, PlannerInfo *subroot,
sprintf(splan->plan_name + offset, ")");
}
else
{
splan->plan_name = palloc(32);
sprintf(splan->plan_name, "SubPlan %d", splan->plan_id);
}
splan->plan_name = psprintf("SubPlan %d", splan->plan_id);
/* Lastly, fill in the cost estimates for use later */
cost_subplan(root, splan, plan);
@@ -2600,8 +2597,7 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
node->setParam = list_make1_int(prm->paramid);
/* Label the subplan for EXPLAIN purposes */
node->plan_name = palloc(64);
sprintf(node->plan_name, "InitPlan %d (returns $%d)",
node->plan_name = psprintf("InitPlan %d (returns $%d)",
node->plan_id, prm->paramid);
return prm;

View File

@@ -313,8 +313,7 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
if (IsA(&ac->val, Integer))
{
cstr = (char *) palloc(32);
snprintf(cstr, 32, "%ld", (long) ac->val.val.ival);
cstr = psprintf("%ld", (long) ac->val.val.ival);
}
else if (IsA(&ac->val, Float) ||
IsA(&ac->val, String))

View File

@@ -1649,9 +1649,7 @@ _mdfd_segpath(SMgrRelation reln, ForkNumber forknum, BlockNumber segno)
if (segno > 0)
{
/* be sure we have enough space for the '.segno' */
fullpath = (char *) palloc(strlen(path) + 12);
sprintf(fullpath, "%s.%u", path, segno);
fullpath = psprintf("%s.%u", path, segno);
pfree(path);
}
else

View File

@@ -91,14 +91,12 @@ anytime_typmodin(bool istz, ArrayType *ta)
static char *
anytime_typmodout(bool istz, int32 typmod)
{
char *res = (char *) palloc(64);
const char *tz = istz ? " with time zone" : " without time zone";
if (typmod >= 0)
snprintf(res, 64, "(%d)%s", (int) typmod, tz);
return psprintf("(%d)%s", (int) typmod, tz);
else
snprintf(res, 64, "%s", tz);
return res;
return psprintf("%s", tz);
}

View File

@@ -116,15 +116,12 @@ anytimestamp_typmodin(bool istz, ArrayType *ta)
static char *
anytimestamp_typmodout(bool istz, int32 typmod)
{
char *res = (char *) palloc(64);
const char *tz = istz ? " with time zone" : " without time zone";
if (typmod >= 0)
snprintf(res, 64, "(%d)%s", (int) typmod, tz);
return psprintf("(%d)%s", (int) typmod, tz);
else
snprintf(res, 64, "%s", tz);
return res;
return psprintf("%s", tz);
}

View File

@@ -1205,8 +1205,7 @@ build_function_result_tupdesc_d(Datum proallargtypes,
if (pname == NULL || pname[0] == '\0')
{
/* Parameter is not named, so gin up a column name */
pname = (char *) palloc(32);
snprintf(pname, 32, "column%d", numoutargs + 1);
pname = psprintf("column%d", numoutargs + 1);
}
outargnames[numoutargs] = pname;
numoutargs++;

View File

@@ -269,15 +269,11 @@ widget_in(char *str)
char *
widget_out(WIDGET * widget)
{
char *result;
if (widget == NULL)
return NULL;
result = (char *) palloc(60);
sprintf(result, "(%g,%g,%g)",
return psprintf("(%g,%g,%g)",
widget->center.x, widget->center.y, widget->radius);
return result;
}
PG_FUNCTION_INFO_V1(pt_in_widget);

View File

@@ -73,8 +73,7 @@ complex_out(PG_FUNCTION_ARGS)
Complex *complex = (Complex *) PG_GETARG_POINTER(0);
char *result;
result = (char *) palloc(100);
snprintf(result, 100, "(%g,%g)", complex->x, complex->y);
result = psprintf("(%g,%g)", complex->x, complex->y);
PG_RETURN_CSTRING(result);
}