From 88c96b19715a074ca00e2e3c7b05c60e60d40577 Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Thu, 16 Oct 2025 10:18:44 -0700
Subject: [PATCH] Make some use of anonymous unions [libpq-oauth]

Make some use of anonymous unions, which are allowed as of C11, as
examples and encouragement for future code, and to test compilers.

This commit changes the json_field struct.

Reviewed-by:
Discussion:
---
 src/interfaces/libpq-oauth/oauth-curl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/interfaces/libpq-oauth/oauth-curl.c b/src/interfaces/libpq-oauth/oauth-curl.c
index aa50b00d053..1287e30b86c 100644
--- a/src/interfaces/libpq-oauth/oauth-curl.c
+++ b/src/interfaces/libpq-oauth/oauth-curl.c
@@ -439,7 +439,7 @@ struct json_field
 	{
 		char	  **scalar;		/* for all scalar types */
 		struct curl_slist **array;	/* for type == JSON_TOKEN_ARRAY_START */
-	}			target;
+	};
 
 	bool		required;		/* REQUIRED field, or just OPTIONAL? */
 };
@@ -561,8 +561,8 @@ oauth_json_object_field_start(void *state, char *name, bool isnull)
 		{
 			field = ctx->active;
 
-			if ((field->type == JSON_TOKEN_ARRAY_START && *field->target.array)
-				|| (field->type != JSON_TOKEN_ARRAY_START && *field->target.scalar))
+			if ((field->type == JSON_TOKEN_ARRAY_START && *field->array)
+				|| (field->type != JSON_TOKEN_ARRAY_START && *field->scalar))
 			{
 				oauth_parse_set_error(ctx, "field \"%s\" is duplicated",
 									  field->name);
@@ -706,7 +706,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 			}
 
 			/* ...and that a result has not already been set. */
-			if (*field->target.scalar)
+			if (*field->scalar)
 			{
 				Assert(false);
 				oauth_parse_set_error(ctx,
@@ -715,8 +715,8 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 				return JSON_SEM_ACTION_FAILED;
 			}
 
-			*field->target.scalar = strdup(token);
-			if (!*field->target.scalar)
+			*field->scalar = strdup(token);
+			if (!*field->scalar)
 				return JSON_OUT_OF_MEMORY;
 
 			ctx->active = NULL;
@@ -738,11 +738,11 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
 			}
 
 			/* Note that curl_slist_append() makes a copy of the token. */
-			temp = curl_slist_append(*field->target.array, token);
+			temp = curl_slist_append(*field->array, token);
 			if (!temp)
 				return JSON_OUT_OF_MEMORY;
 
-			*field->target.array = temp;
+			*field->array = temp;
 		}
 	}
 	else
@@ -878,8 +878,8 @@ parse_oauth_json(struct async_ctx *actx, const struct json_field *fields)
 	while (fields->name)
 	{
 		if (fields->required
-			&& !*fields->target.scalar
-			&& !*fields->target.array)
+			&& !*fields->scalar
+			&& !*fields->array)
 		{
 			actx_error(actx, "field \"%s\" is missing", fields->name);
 			goto cleanup;
-- 
2.34.1

