Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4589c6a

Browse files
committed
Apply project best practices to switches over enum values.
In the wake of1f3a021, assorted buildfarm members were warning about"control reaches end of non-void function" or the like. Do what we'vedone elsewhere: in place of a "default" switch case that will preventthe compiler from warning about unhandled enum values, put a catchallelog() after the switch. And return a dummy value to satisfy compilersthat don't know elog() doesn't return.
1 parent73ce2a0 commit4589c6a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

‎src/backend/utils/adt/jsonapi.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,15 @@ report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
10031003
returnJSON_EXPECTED_OBJECT_NEXT;
10041004
caseJSON_PARSE_OBJECT_COMMA:
10051005
returnJSON_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+
returnJSON_SUCCESS;/* silence stupider compilers */
10091015
}
10101016

10111017
/*
@@ -1017,7 +1023,7 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
10171023
switch (error)
10181024
{
10191025
caseJSON_SUCCESS:
1020-
elog(ERROR,"internalerrorin json parser");
1026+
/* fall through to theerrorcode after switch */
10211027
break;
10221028
caseJSON_ESCAPING_INVALID:
10231029
returnpsprintf(_("Escape sequence \"\\%s\" is invalid."),
@@ -1065,6 +1071,14 @@ json_errdetail(JsonParseErrorType error, JsonLexContext *lex)
10651071
caseJSON_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+
returnNULL;/* silence stupider compilers */
10681082
}
10691083

10701084
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp