mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +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:
@@ -466,8 +466,7 @@ report_two_error_messages(Step * step1, Step * step2)
|
||||
{
|
||||
char *prefix;
|
||||
|
||||
prefix = malloc(strlen(step1->name) + strlen(step2->name) + 2);
|
||||
sprintf(prefix, "%s %s", step1->name, step2->name);
|
||||
pg_asprintf(&prefix, "%s %s", step1->name, step2->name);
|
||||
|
||||
if (step1->errormsg)
|
||||
{
|
||||
@@ -795,12 +794,9 @@ try_complete_step(Step * step, int flags)
|
||||
PG_DIAG_MESSAGE_PRIMARY);
|
||||
|
||||
if (sev && msg)
|
||||
{
|
||||
step->errormsg = malloc(5 + strlen(sev) + strlen(msg));
|
||||
sprintf(step->errormsg, "%s: %s", sev, msg);
|
||||
}
|
||||
pg_asprintf(&step->errormsg, "%s: %s", sev, msg);
|
||||
else
|
||||
step->errormsg = strdup(PQresultErrorMessage(res));
|
||||
step->errormsg = pg_strdup(PQresultErrorMessage(res));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user