Skip to content

Commit f1881c7

Browse files
committed
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: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://postgr.es/m/CAOYmi%2BnV25oC5uXFgWodydGrHkfWMDCLUcjbAreM3mNX%3DF2JWw%40mail.gmail.com
1 parent bc32a12 commit f1881c7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/interfaces/libpq-oauth/oauth-curl.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ struct json_field
439439
{
440440
char **scalar;/* for all scalar types */
441441
struct curl_slist **array;/* for type == JSON_TOKEN_ARRAY_START */
442-
}target;
442+
};
443443

444444
boolrequired;/* REQUIRED field, or just OPTIONAL? */
445445
};
@@ -561,8 +561,8 @@ oauth_json_object_field_start(void *state, char *name, bool isnull)
561561
{
562562
field = ctx->active;
563563

564-
if ((field->type == JSON_TOKEN_ARRAY_START && *field->target.array)
565-
|| (field->type != JSON_TOKEN_ARRAY_START && *field->target.scalar))
564+
if ((field->type == JSON_TOKEN_ARRAY_START && *field->array)
565+
|| (field->type != JSON_TOKEN_ARRAY_START && *field->scalar))
566566
{
567567
oauth_parse_set_error(ctx, "field \"%s\" is duplicated",
568568
field->name);
@@ -706,7 +706,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
706706
}
707707

708708
/* ...and that a result has not already been set. */
709-
if (*field->target.scalar)
709+
if (*field->scalar)
710710
{
711711
Assert(false);
712712
oauth_parse_set_error(ctx,
@@ -715,8 +715,8 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
715715
return JSON_SEM_ACTION_FAILED;
716716
}
717717

718-
*field->target.scalar = strdup(token);
719-
if (!*field->target.scalar)
718+
*field->scalar = strdup(token);
719+
if (!*field->scalar)
720720
return JSON_OUT_OF_MEMORY;
721721

722722
ctx->active = NULL;
@@ -738,11 +738,11 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
738738
}
739739

740740
/* Note that curl_slist_append() makes a copy of the token. */
741-
temp = curl_slist_append(*field->target.array, token);
741+
temp = curl_slist_append(*field->array, token);
742742
if (!temp)
743743
return JSON_OUT_OF_MEMORY;
744744

745-
*field->target.array = temp;
745+
*field->array = temp;
746746
}
747747
}
748748
else
@@ -878,8 +878,8 @@ parse_oauth_json(struct async_ctx *actx, const struct json_field *fields)
878878
while (fields->name)
879879
{
880880
if (fields->required
881-
&& !*fields->target.scalar
882-
&& !*fields->target.array)
881+
&& !*fields->scalar
882+
&& !*fields->array)
883883
{
884884
actx_error(actx, "field \"%s\" is missing", fields->name);
885885
goto cleanup;

0 commit comments

Comments
 (0)