aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/basebackup.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-10-27 13:20:40 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-10-27 13:20:40 -0300
commit80ae841f2f0c51ea766a75f4abe73c0c48e4ab0c (patch)
treec55111e6ab2187d0874c30048b35b8c750b6804f /src/backend/replication/basebackup.c
parent44390e30f8531906ed142336f84f172b93073038 (diff)
downloadpostgresql-80ae841f2f0c51ea766a75f4abe73c0c48e4ab0c.tar.gz
postgresql-80ae841f2f0c51ea766a75f4abe73c0c48e4ab0c.zip
Measure string lengths only once
Bernd Helmle complained that CreateReplicationSlot() was assigning the same value to the same variable twice, so we could remove one of them. Code inspection reveals that we can actually remove both assignments: according to the author the assignment was there for beauty of the strlen line only, and another possible fix to that is to put the strlen in its own line, so do that. To be consistent within the file, refactor all duplicated strlen() calls, which is what we do elsewhere in the backend anyway. In basebackup.c, snprintf already returns the right length; no need for strlen afterwards. Backpatch to 9.4, where replication slots were introduced, to keep code identical. Some of this is older, but the patch doesn't apply cleanly and it's only of cosmetic value anyway. Discussion: http://www.postgresql.org/message-id/BE2FD71DEA35A2287EA5F018@eje.credativ.lan
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r--src/backend/replication/basebackup.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 1e86e4c57b6..1af011ee6e0 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -698,10 +698,15 @@ SendBackupHeader(List *tablespaces)
}
else
{
- pq_sendint(&buf, strlen(ti->oid), 4); /* length */
- pq_sendbytes(&buf, ti->oid, strlen(ti->oid));
- pq_sendint(&buf, strlen(ti->path), 4); /* length */
- pq_sendbytes(&buf, ti->path, strlen(ti->path));
+ Size len;
+
+ len = strlen(ti->oid);
+ pq_sendint(&buf, len, 4);
+ pq_sendbytes(&buf, ti->oid, len);
+
+ len = strlen(ti->path);
+ pq_sendint(&buf, len, 4);
+ pq_sendbytes(&buf, ti->path, len);
}
if (ti->size >= 0)
send_int8_string(&buf, ti->size / 1024);
@@ -724,6 +729,7 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
{
StringInfoData buf;
char str[MAXFNAMELEN];
+ Size len;
pq_beginmessage(&buf, 'T'); /* RowDescription */
pq_sendint(&buf, 2, 2); /* 2 fields */
@@ -742,7 +748,7 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
pq_sendint(&buf, 0, 2); /* attnum */
/*
- * int8 may seem like a surprising data type for this, but in thory int4
+ * int8 may seem like a surprising data type for this, but in theory int4
* would not be wide enough for this, as TimeLineID is unsigned.
*/
pq_sendint(&buf, INT8OID, 4); /* type oid */
@@ -755,13 +761,15 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
pq_beginmessage(&buf, 'D');
pq_sendint(&buf, 2, 2); /* number of columns */
- snprintf(str, sizeof(str), "%X/%X", (uint32) (ptr >> 32), (uint32) ptr);
- pq_sendint(&buf, strlen(str), 4); /* length */
- pq_sendbytes(&buf, str, strlen(str));
+ len = snprintf(str, sizeof(str),
+ "%X/%X", (uint32) (ptr >> 32), (uint32) ptr);
+ pq_sendint(&buf, len, 4);
+ pq_sendbytes(&buf, str, len);
+
+ len = snprintf(str, sizeof(str), "%u", tli);
+ pq_sendint(&buf, len, 4);
+ pq_sendbytes(&buf, str, len);
- snprintf(str, sizeof(str), "%u", tli);
- pq_sendint(&buf, strlen(str), 4); /* length */
- pq_sendbytes(&buf, str, strlen(str));
pq_endmessage(&buf);
/* Send a CommandComplete message */