From 5b6d08cd2992922b667564a49f19580f11676050 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 13 Oct 2013 00:09:18 -0400 Subject: Add use of asprintf() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add asprintf(), pg_asprintf(), and psprintf() to simplify string allocation and composition. Replacement implementations taken from NetBSD. Reviewed-by: Álvaro Herrera Reviewed-by: Asif Naeem --- src/bin/psql/common.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/bin/psql/common.c') diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 3dea92c7d8f..71f0c8a95a8 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -594,9 +594,7 @@ StoreQueryTuple(const PGresult *result) char *value; /* concate prefix and column name */ - varname = pg_malloc(strlen(pset.gset_prefix) + strlen(colname) + 1); - strcpy(varname, pset.gset_prefix); - strcat(varname, colname); + pg_asprintf(&varname, "%s%s", pset.gset_prefix, colname); if (!PQgetisnull(result, 0, i)) value = PQgetvalue(result, 0, i); @@ -1687,10 +1685,7 @@ expand_tilde(char **filename) { char *newfn; - newfn = pg_malloc(strlen(home) + strlen(p) + 1); - strcpy(newfn, home); - strcat(newfn, p); - + pg_asprintf(&newfn, "%s%s", home, p); free(fn); *filename = newfn; } -- cgit v1.2.3