summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/isolation/isolationtester.c10
-rw-r--r--src/test/regress/pg_regress.c37
2 files changed, 16 insertions, 31 deletions
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index f62565046c3..7a3572f0c17 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -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:
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index b632326e08d..e51d08878da 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -654,9 +654,9 @@ get_expectfile(const char *testname, const char *file)
static void
doputenv(const char *var, const char *val)
{
- char *s = malloc(strlen(var) + strlen(val) + 2);
+ char *s;
- sprintf(s, "%s=%s", var, val);
+ pg_asprintf(&s, "%s=%s", var, val);
putenv(s);
}
@@ -671,16 +671,11 @@ add_to_path(const char *pathname, char separator, const char *addval)
char *newval;
if (!oldval || !oldval[0])
- {
/* no previous value */
- newval = malloc(strlen(pathname) + strlen(addval) + 2);
- sprintf(newval, "%s=%s", pathname, addval);
- }
+ pg_asprintf(&newval, "%s=%s", pathname, addval);
else
- {
- newval = malloc(strlen(pathname) + strlen(addval) + strlen(oldval) + 3);
- sprintf(newval, "%s=%s%c%s", pathname, addval, separator, oldval);
- }
+ pg_asprintf(&newval, "%s=%s%c%s", pathname, addval, separator, oldval);
+
putenv(newval);
}
@@ -747,8 +742,7 @@ initialize_environment(void)
if (!old_pgoptions)
old_pgoptions = "";
- new_pgoptions = malloc(strlen(old_pgoptions) + strlen(my_pgoptions) + 12);
- sprintf(new_pgoptions, "PGOPTIONS=%s %s", old_pgoptions, my_pgoptions);
+ pg_asprintf(&new_pgoptions, "PGOPTIONS=%s %s", old_pgoptions, my_pgoptions);
putenv(new_pgoptions);
}
@@ -798,16 +792,13 @@ initialize_environment(void)
/*
* Adjust path variables to point into the temp-install tree
*/
- tmp = malloc(strlen(temp_install) + 32 + strlen(bindir));
- sprintf(tmp, "%s/install/%s", temp_install, bindir);
+ pg_asprintf(&tmp, "%s/install/%s", temp_install, bindir);
bindir = tmp;
- tmp = malloc(strlen(temp_install) + 32 + strlen(libdir));
- sprintf(tmp, "%s/install/%s", temp_install, libdir);
+ pg_asprintf(&tmp, "%s/install/%s", temp_install, libdir);
libdir = tmp;
- tmp = malloc(strlen(temp_install) + 32 + strlen(datadir));
- sprintf(tmp, "%s/install/%s", temp_install, datadir);
+ pg_asprintf(&tmp, "%s/install/%s", temp_install, datadir);
datadir = tmp;
/* psql will be installed into temp-install bindir */
@@ -961,9 +952,9 @@ spawn_process(const char *cmdline)
* "exec" the command too. This saves two useless processes per
* parallel test case.
*/
- char *cmdline2 = malloc(strlen(cmdline) + 6);
+ char *cmdline2;
- sprintf(cmdline2, "exec %s", cmdline);
+ pg_asprintf(&cmdline2, "exec %s", cmdline);
execl(shellprog, shellprog, "-c", cmdline2, (char *) NULL);
fprintf(stderr, _("%s: could not exec \"%s\": %s\n"),
progname, shellprog, strerror(errno));
@@ -1040,8 +1031,7 @@ spawn_process(const char *cmdline)
exit(2);
}
- cmdline2 = malloc(strlen(cmdline) + 8);
- sprintf(cmdline2, "cmd /c %s", cmdline);
+ pg_asprintf(&cmdline2, "cmd /c %s", cmdline);
#ifndef __CYGWIN__
AddUserToTokenDacl(restrictedToken);
@@ -1862,8 +1852,7 @@ make_absolute_path(const char *in)
}
}
- result = malloc(strlen(cwdbuf) + strlen(in) + 2);
- sprintf(result, "%s/%s", cwdbuf, in);
+ pg_asprintf(&result, "%s/%s", cwdbuf, in);
}
canonicalize_path(result);