Add some assertions to view reloption macros

In these macros, the rd_options pointer is cast to ViewOption *.  Add
some assertions that the passed-in relation is actually a view before
doing that.

Author: Nikolay Shaplov <dhyan@nataraj.su>
Discussion: https://www.postgresql.org/message-id/flat/3634983.eHpMQ1mJnI@x200m
This commit is contained in:
Peter Eisentraut 2019-11-01 13:16:21 +01:00
parent 604bd36711
commit 3967737624
1 changed files with 10 additions and 6 deletions

View File

@ -351,9 +351,10 @@ typedef struct ViewOptions
* Returns whether the relation is security view, or not. Note multiple
* eval of argument!
*/
#define RelationIsSecurityView(relation) \
((relation)->rd_options ? \
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
#define RelationIsSecurityView(relation) \
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options ? \
((ViewOptions *) (relation)->rd_options)->security_barrier : false)
/*
* RelationHasCheckOption
@ -361,7 +362,8 @@ typedef struct ViewOptions
* or the cascaded check option. Note multiple eval of argument!
*/
#define RelationHasCheckOption(relation) \
((relation)->rd_options && \
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option != \
VIEW_OPTION_CHECK_OPTION_NOT_SET)
@ -371,7 +373,8 @@ typedef struct ViewOptions
* option. Note multiple eval of argument!
*/
#define RelationHasLocalCheckOption(relation) \
((relation)->rd_options && \
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option == \
VIEW_OPTION_CHECK_OPTION_LOCAL)
@ -381,7 +384,8 @@ typedef struct ViewOptions
* option. Note multiple eval of argument!
*/
#define RelationHasCascadedCheckOption(relation) \
((relation)->rd_options && \
(AssertMacro(relation->rd_rel->relkind == RELKIND_VIEW), \
(relation)->rd_options && \
((ViewOptions *) (relation)->rd_options)->check_option == \
VIEW_OPTION_CHECK_OPTION_CASCADED)