From d0dabb152633447bdef788bb1c579031801160ad Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Mon, 7 Sep 2015 22:24:29 +0900
Subject: [PATCH 2/2] Remove dead code of libpq protocol 3

getRowDescriptions and getAnotherTuple contained a code path that could
be used to stop message parsing which is visibly a copy/paste of the
equivalent code if protocol 2, however it has never been used.
---
 src/interfaces/libpq/fe-protocol3.c | 46 +++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 20b6b13..5da47cc 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -44,9 +44,9 @@
 
 
 static void handleSyncLoss(PGconn *conn, char id, int msgLength);
-static int	getRowDescriptions(PGconn *conn, int msgLength);
+static void getRowDescriptions(PGconn *conn, int msgLength);
 static int	getParamDescriptions(PGconn *conn, int msgLength);
-static int	getAnotherTuple(PGconn *conn, int msgLength);
+static void getAnotherTuple(PGconn *conn, int msgLength);
 static int	getParameterStatus(PGconn *conn);
 static int	getNotify(PGconn *conn);
 static int	getCopyStart(PGconn *conn,
@@ -284,8 +284,7 @@ pqParseInput3(PGconn *conn)
 						conn->queryclass == PGQUERY_DESCRIBE)
 					{
 						/* First 'T' in a query sequence */
-						if (getRowDescriptions(conn, msgLength))
-							return;
+						getRowDescriptions(conn, msgLength);
 						/* getRowDescriptions() moves inStart itself */
 						continue;
 					}
@@ -347,8 +346,7 @@ pqParseInput3(PGconn *conn)
 						conn->result->resultStatus == PGRES_TUPLES_OK)
 					{
 						/* Read another tuple of a normal query response */
-						if (getAnotherTuple(conn, msgLength))
-							return;
+						getAnotherTuple(conn, msgLength);
 						/* getAnotherTuple() moves inStart itself */
 						continue;
 					}
@@ -495,11 +493,10 @@ handleSyncLoss(PGconn *conn, char id, int msgLength)
  * parseInput subroutine to read a 'T' (row descriptions) message.
  * We'll build a new PGresult structure (unless called for a Describe
  * command for a prepared statement) containing the attribute data.
- * Returns: 0 if processed message successfully, EOF to suspend parsing
- * (the latter case is not actually used currently).
- * In either case, conn->inStart has been advanced past the message.
+ * This routine assumes that message is always processed successfully
+ * and conn->inStart is advanced past the message.
  */
-static int
+static void
 getRowDescriptions(PGconn *conn, int msgLength)
 {
 	PGresult   *result;
@@ -622,7 +619,7 @@ getRowDescriptions(PGconn *conn, int msgLength)
 	if (conn->queryclass == PGQUERY_DESCRIBE)
 	{
 		conn->asyncStatus = PGASYNC_READY;
-		return 0;
+		return;
 	}
 
 	/*
@@ -631,7 +628,7 @@ getRowDescriptions(PGconn *conn, int msgLength)
 	 */
 
 	/* And we're done. */
-	return 0;
+	return;
 
 advance_and_error:
 	/* Discard unsaved result, if any */
@@ -660,11 +657,11 @@ advance_and_error:
 	pqSaveErrorResult(conn);
 
 	/*
-	 * Return zero to allow input parsing to continue.  Subsequent "D"
-	 * messages will be ignored until we get to end of data, since an error
-	 * result is already set up.
+	 * Return to allow input parsing to continue.  Subsequent "D" messages
+	 * will be ignored until we get to end of data, since an error result
+	 * is already set up.
 	 */
-	return 0;
+	return;
 }
 
 /*
@@ -766,11 +763,10 @@ advance_and_error:
 /*
  * parseInput subroutine to read a 'D' (row data) message.
  * We fill rowbuf with column pointers and then call the row processor.
- * Returns: 0 if processed message successfully, EOF to suspend parsing
- * (the latter case is not actually used currently).
- * In either case, conn->inStart has been advanced past the message.
+ * This routine always considers that the message has been processed
+ * successfully, and conn->inStart is advanced past the message.
  */
-static int
+static void
 getAnotherTuple(PGconn *conn, int msgLength)
 {
 	PGresult   *result = conn->result;
@@ -854,7 +850,7 @@ getAnotherTuple(PGconn *conn, int msgLength)
 	/* Process the collected row */
 	errmsg = NULL;
 	if (pqRowProcessor(conn, &errmsg))
-		return 0;				/* normal, successful exit */
+		return;				/* normal, successful exit */
 
 	goto set_error_result;		/* pqRowProcessor failed, report it */
 
@@ -883,11 +879,11 @@ set_error_result:
 	pqSaveErrorResult(conn);
 
 	/*
-	 * Return zero to allow input parsing to continue.  Subsequent "D"
-	 * messages will be ignored until we get to end of data, since an error
-	 * result is already set up.
+	 * Return to allow input parsing to continue.  Subsequent "D" messages
+	 * will be ignored until we get to end of data, since an error result
+	 * is already set up.
 	 */
-	return 0;
+	return;
 }
 
 
-- 
2.5.1

