Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85d94c5

Browse files
committed
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
1 parent 3174d69 commit 85d94c5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/interfaces/libpq/fe-connect.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -3277,10 +3277,15 @@ PQconnectPoll(PGconn *conn)
32773277
conn->inStart = conn->inCursor;
32783278

32793279
/*
3280-
* The postmaster typically won't end its message with a
3281-
* newline, so add one to conform to libpq conventions.
3280+
* Before 7.2, the postmaster didn't always end its
3281+
* messages with a newline, so add one if needed to
3282+
* conform to libpq conventions.
32823283
*/
3283-
appendPQExpBufferChar(&conn->errorMessage, '\n');
3284+
if (conn->errorMessage.len == 0 ||
3285+
conn->errorMessage.data[conn->errorMessage.len - 1] != '\n')
3286+
{
3287+
appendPQExpBufferChar(&conn->errorMessage, '\n');
3288+
}
32843289

32853290
goto error_return;
32863291
}

0 commit comments

Comments
 (0)