diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-01-27 18:46:30 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-01-27 18:46:30 -0500 |
commit | 4589c6a2a30faba53d0655a8e3a29b54d28bb6f6 (patch) | |
tree | e7de20dcf10ecef6e3b4eb795ddd53db06566e19 | |
parent | 73ce2a03f30b52d6bfb26bc28f1e3e1aa1637577 (diff) | |
download | postgresql-4589c6a2a30faba53d0655a8e3a29b54d28bb6f6.tar.gz postgresql-4589c6a2a30faba53d0655a8e3a29b54d28bb6f6.zip |
Apply project best practices to switches over enum values.
In the wake of 1f3a02173, 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.
-rw-r--r-- | src/backend/utils/adt/jsonapi.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/backend/utils/adt/jsonapi.c b/src/backend/utils/adt/jsonapi.c index 1ac3b7beda8..230a55b1013 100644 --- a/src/backend/utils/adt/jsonapi.c +++ b/src/backend/utils/adt/jsonapi.c @@ -1003,9 +1003,15 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex) return JSON_EXPECTED_OBJECT_NEXT; case JSON_PARSE_OBJECT_COMMA: return JSON_EXPECTED_STRING; - default: - elog(ERROR, "unexpected json parse state: %d", ctx); } + + /* + * We don't use a default: case, so that the compiler will warn about + * unhandled enum values. But this needs to be here anyway to cover the + * possibility of an incorrect input. + */ + elog(ERROR, "unexpected json parse state: %d", (int) ctx); + return JSON_SUCCESS; /* silence stupider compilers */ } /* @@ -1017,7 +1023,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex) switch (error) { case JSON_SUCCESS: - elog(ERROR, "internal error in json parser"); + /* fall through to the error code after switch */ break; case JSON_ESCAPING_INVALID: return psprintf(_("Escape sequence \"\\%s\" is invalid."), @@ -1065,6 +1071,14 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex) case JSON_UNICODE_LOW_SURROGATE: return _("Unicode low surrogate must follow a high surrogate."); } + + /* + * We don't use a default: case, so that the compiler will warn about + * unhandled enum values. But this needs to be here anyway to cover the + * possibility of an incorrect input. + */ + elog(ERROR, "unexpected json parse error type: %d", (int) error); + return NULL; /* silence stupider compilers */ } /* |