summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-03-04 10:56:33 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-03-04 10:56:33 +0200
commit85d94c575302644e7ddb4392c3bda572f981ec34 (patch)
treeace0ed44da69ac4f9a7f0bbd0ea06dec7c11e1c9
parent3174d69fb96a66173224e60ec7053b988d5ed4d9 (diff)
Avoid extra newline in errors received in FE protocol version 2.
Contrary to what the comment said, the postmaster does in fact end all its messages in a newline, since server version 7.2. Be tidy and don't add an extra newline if the error message already has one. Discussion: https://www.postgresql.org/message-id/CAFBsxsEdgMXc%2BtGfEy9Y41i%3D5pMMjKeH8t8vSAypR3ZnAoQnHg%40mail.gmail.com
-rw-r--r--src/interfaces/libpq/fe-connect.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index c16a7bd9f22..f83af03d0a7 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -3277,10 +3277,15 @@ keep_going: /* We will come back to here until there is
conn->inStart = conn->inCursor;
/*
- * The postmaster typically won't end its message with a
- * newline, so add one to conform to libpq conventions.
+ * Before 7.2, the postmaster didn't always end its
+ * messages with a newline, so add one if needed to
+ * conform to libpq conventions.
*/
- appendPQExpBufferChar(&conn->errorMessage, '\n');
+ if (conn->errorMessage.len == 0 ||
+ conn->errorMessage.data[conn->errorMessage.len - 1] != '\n')
+ {
+ appendPQExpBufferChar(&conn->errorMessage, '\n');
+ }
goto error_return;
}