Skip to content

Commit 4589c6a

Browse files
committed
Apply project best practices to switches over enum values.
In the wake of 1f3a021, assorted buildfarm members were warning about "control reaches end of non-void function" or the like. Do what we've done elsewhere: in place of a "default" switch case that will prevent the compiler from warning about unhandled enum values, put a catchall elog() after the switch. And return a dummy value to satisfy compilers that don't know elog() doesn't return.
1 parent 73ce2a0 commit 4589c6a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/backend/utils/adt/jsonapi.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,15 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
10031003
return JSON_EXPECTED_OBJECT_NEXT;
10041004
case JSON_PARSE_OBJECT_COMMA:
10051005
return JSON_EXPECTED_STRING;
1006-
default:
1007-
elog(ERROR, "unexpected json parse state: %d", ctx);
10081006
}
1007+
1008+
/*
1009+
* We don't use a default: case, so that the compiler will warn about
1010+
* unhandled enum values. But this needs to be here anyway to cover the
1011+
* possibility of an incorrect input.
1012+
*/
1013+
elog(ERROR, "unexpected json parse state: %d", (int) ctx);
1014+
return JSON_SUCCESS; /* silence stupider compilers */
10091015
}
10101016

10111017
/*
@@ -1017,7 +1023,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
10171023
switch (error)
10181024
{
10191025
case JSON_SUCCESS:
1020-
elog(ERROR, "internal error in json parser");
1026+
/* fall through to the error code after switch */
10211027
break;
10221028
case JSON_ESCAPING_INVALID:
10231029
return psprintf(_("Escape sequence \"\\%s\" is invalid."),
@@ -1065,6 +1071,14 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
10651071
case JSON_UNICODE_LOW_SURROGATE:
10661072
return _("Unicode low surrogate must follow a high surrogate.");
10671073
}
1074+
1075+
/*
1076+
* We don't use a default: case, so that the compiler will warn about
1077+
* unhandled enum values. But this needs to be here anyway to cover the
1078+
* possibility of an incorrect input.
1079+
*/
1080+
elog(ERROR, "unexpected json parse error type: %d", (int) error);
1081+
return NULL; /* silence stupider compilers */
10681082
}
10691083

10701084
/*

0 commit comments

Comments
 (0)