mirror of
https://github.com/postgres/postgres.git
synced 2025-11-21 00:42:43 +03:00
Static assertions cleanup
Because we added StaticAssertStmt() first before StaticAssertDecl(), some uses as well as the instructions in c.h are now a bit backwards from the "native" way static assertions are meant to be used in C. This updates the guidance and moves some static assertions to better places. Specifically, since the addition of StaticAssertDecl(), we can put static assertions at the file level. This moves a number of static assertions out of function bodies, where they might have been stuck out of necessity, to perhaps better places at the file level or in header files. Also, when the static assertion appears in a position where a declaration is allowed, then using StaticAssertDecl() is more native than StaticAssertStmt(). Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/941a04e7-dd6f-c0e4-8cdf-a33b3338cbda%40enterprisedb.com
This commit is contained in:
@@ -1443,7 +1443,7 @@ scram_mock_salt(const char *username)
|
||||
* not larger than the SHA256 digest length. If the salt is smaller, the
|
||||
* caller will just ignore the extra data.)
|
||||
*/
|
||||
StaticAssertStmt(PG_SHA256_DIGEST_LENGTH >= SCRAM_DEFAULT_SALT_LEN,
|
||||
StaticAssertDecl(PG_SHA256_DIGEST_LENGTH >= SCRAM_DEFAULT_SALT_LEN,
|
||||
"salt length greater than SHA256 digest length");
|
||||
|
||||
ctx = pg_cryptohash_create(PG_SHA256);
|
||||
|
||||
@@ -127,6 +127,12 @@ static const char *const UserAuthName[] =
|
||||
"peer"
|
||||
};
|
||||
|
||||
/*
|
||||
* Make sure UserAuthName[] tracks additions to the UserAuth enum
|
||||
*/
|
||||
StaticAssertDecl(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
|
||||
"UserAuthName[] must match the UserAuth enum");
|
||||
|
||||
|
||||
static List *tokenize_expand_file(List *tokens, const char *outer_filename,
|
||||
const char *inc_filename, int elevel,
|
||||
@@ -3117,11 +3123,5 @@ hba_getauthmethod(hbaPort *port)
|
||||
const char *
|
||||
hba_authname(UserAuth auth_method)
|
||||
{
|
||||
/*
|
||||
* Make sure UserAuthName[] tracks additions to the UserAuth enum
|
||||
*/
|
||||
StaticAssertStmt(lengthof(UserAuthName) == USER_AUTH_LAST + 1,
|
||||
"UserAuthName[] must match the UserAuth enum");
|
||||
|
||||
return UserAuthName[auth_method];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user