From 953176ae5738758105860868e134858644dfac6c Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 14 Jan 2020 13:00:26 -0800
Subject: [PATCH v3 05/10] copy: Use appendBinaryStringInfoNT() for sending
 binary data

Maintaining the trailing byte is useless overhead.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20200603015559.qc7ry5jqmoxlpu4y@alap3.anarazel.de
---
 src/backend/commands/copyto.c                              | 4 ++--
 src/test/modules/test_copy_callbacks/test_copy_callbacks.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index b7f8b04ed8d..5857532f54e 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -175,13 +175,13 @@ SendCopyEnd(CopyToState cstate)
 static void
 CopySendData(CopyToState cstate, const void *databuf, int datasize)
 {
-	appendBinaryStringInfo(cstate->fe_msgbuf, databuf, datasize);
+	appendBinaryStringInfoNT(cstate->fe_msgbuf, databuf, datasize);
 }
 
 static void
 CopySendString(CopyToState cstate, const char *str)
 {
-	appendBinaryStringInfo(cstate->fe_msgbuf, str, strlen(str));
+	appendBinaryStringInfoNT(cstate->fe_msgbuf, str, strlen(str));
 }
 
 static void
diff --git a/src/test/modules/test_copy_callbacks/test_copy_callbacks.c b/src/test/modules/test_copy_callbacks/test_copy_callbacks.c
index 0bbd2aa6bb9..1ba205675af 100644
--- a/src/test/modules/test_copy_callbacks/test_copy_callbacks.c
+++ b/src/test/modules/test_copy_callbacks/test_copy_callbacks.c
@@ -25,8 +25,8 @@ static void
 to_cb(void *data, int len)
 {
 	ereport(NOTICE,
-			(errmsg("COPY TO callback called with data \"%s\" and length %d",
-					(char *) data, len)));
+			(errmsg("COPY TO callback called with data \"%.*s\" and length %d",
+					len, (char *) data, len)));
 }
 
 PG_FUNCTION_INFO_V1(test_copy_to_callback);
-- 
2.38.0

