From 28ffc13ceab70b9e05aa3563b0b8b37e209a349e Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Thu, 25 Nov 2021 22:47:41 -0600
Subject: [PATCH 4/6] move beentry++ away from the middle of the loop body

This was more reasonable when the "if" block was shorter; but, now it's
large, and the variable increment is easy to miss, as happened during
patch development:
https://www.postgresql.org/message-id/20211202040653.GM17618@telsasoft.com
---
 src/backend/utils/activity/backend_status.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index 1146a6c33cd..1cf2bc58410 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -842,7 +842,6 @@ pgstat_read_current_status(void)
 			CHECK_FOR_INTERRUPTS();
 		}
 
-		beentry++;
 		/* Only valid entries get included into the local array */
 		if (localentry->backendStatus.st_procpid > 0)
 		{
@@ -869,6 +868,8 @@ pgstat_read_current_status(void)
 #endif
 			localNumBackends++;
 		}
+
+		beentry++;
 	}
 
 	/* Set the pointer only after completion of a valid table */
-- 
2.25.1

