summaryrefslogtreecommitdiff
path: root/src/bin/pgbench/pgbench.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2022-09-06 13:19:44 +1200
committerDavid Rowley <drowley@postgresql.org>2022-09-06 13:19:44 +1200
commit8b26769bc441fffa8aad31dddc484c2f4043d2c9 (patch)
treebde1ddb9831a4e65880f11af9a94a52f9abbbf25 /src/bin/pgbench/pgbench.c
parent6bcda4a72123c3aa29fa3f03d952095675ad4468 (diff)
downloadpostgresql-8b26769bc441fffa8aad31dddc484c2f4043d2c9.tar.gz
Fix an assortment of improper usages of string functions
In a similar effort to f736e188c and 110d81728, fixup various usages of string functions where a more appropriate function is available and more fit for purpose. These changes include: 1. Use cstring_to_text_with_len() instead of cstring_to_text() when working with a StringInfoData and the length can easily be obtained. 2. Use appendStringInfoString() instead of appendStringInfo() when no formatting is required. 3. Use pstrdup(...) instead of psprintf("%s", ...) 4. Use pstrdup(...) instead of psprintf(...) (with no formatting) 5. Use appendPQExpBufferChar() instead of appendPQExpBufferStr() when the length of the string being appended is 1. 6. appendStringInfoChar() instead of appendStringInfo() when no formatting is required and string is 1 char long. 7. Use appendPQExpBufferStr(b, .) instead of appendPQExpBuffer(b, "%s", .) 8. Don't use pstrdup when it's fine to just point to the string constant. I (David) did find other cases of #8 but opted to use #4 instead as I wasn't certain enough that applying #8 was ok (e.g in hba.c) Author: Ranier Vilela, David Rowley Discussion: https://postgr.es/m/CAApHDvo2j2+RJBGhNtUz6BxabWWh2Jx16wMUMWKUjv70Ver1vg@mail.gmail.com
Diffstat (limited to 'src/bin/pgbench/pgbench.c')
-rw-r--r--src/bin/pgbench/pgbench.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 9aadcaad71..098fb43b3c 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3512,10 +3512,9 @@ printVerboseErrorMessages(CState *st, pg_time_usec_t *now, bool is_retry)
resetPQExpBuffer(buf);
printfPQExpBuffer(buf, "client %d ", st->id);
- appendPQExpBuffer(buf, "%s",
- (is_retry ?
- "repeats the transaction after the error" :
- "ends the failed transaction"));
+ appendPQExpBufferStr(buf, (is_retry ?
+ "repeats the transaction after the error" :
+ "ends the failed transaction"));
appendPQExpBuffer(buf, " (try %u", st->tries);
/* Print max_tries if it is not unlimitted. */
@@ -3532,7 +3531,7 @@ printVerboseErrorMessages(CState *st, pg_time_usec_t *now, bool is_retry)
appendPQExpBuffer(buf, ", %.3f%% of the maximum time of tries was used",
(100.0 * (*now - st->txn_scheduled) / latency_limit));
}
- appendPQExpBuffer(buf, ")\n");
+ appendPQExpBufferStr(buf, ")\n");
pg_log_info("%s", buf->data);
}