On Thu, Feb 22, 2024 at 05:30:08PM +1100, Peter Smith wrote:
> Oops. Perhaps I meant more like below -- in any case, the point was
> the same -- to ensure RS_INVAL_NONE is what returns if something
> unexpected happens.

You are right that this could be a bit confusing, even if we should
never reach this state.  How about avoiding to return the index of the
loop as result, as of the attached?  Would you find that cleaner?
--
Michael
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 233652b479..eb1ada2f9f 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -2313,6 +2313,7 @@ ReplicationSlotInvalidationCause
 GetSlotInvalidationCause(const char *conflict_reason)
 {
 	ReplicationSlotInvalidationCause cause;
+	ReplicationSlotInvalidationCause result = RS_INVAL_NONE;
 	bool		found PG_USED_FOR_ASSERTS_ONLY = false;
 
 	Assert(conflict_reason);
@@ -2322,10 +2323,11 @@ GetSlotInvalidationCause(const char *conflict_reason)
 		if (strcmp(SlotInvalidationCauses[cause], conflict_reason) == 0)
 		{
 			found = true;
+			result = cause;
 			break;
 		}
 	}
 
 	Assert(found);
-	return cause;
+	return result;
 }

Attachment: signature.asc
Description: PGP signature

Reply via email to