Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aca9920

Browse files
committed
Update some more ObjectType switch statements to not have default
This allows the compiler to complain if a case has been missed. In these instances, the tradeoff of having to list a few unneeded cases to silence the compiler seems better than the risk of actually missing one. Discussion: https://www.postgresql.org/message-id/flat/fce5c98a-45da-19e7-dad0-21096bccd66e%40enterprisedb.com
1 parent adaf342 commit aca9920

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ ObjectAddress
960960
get_object_address(ObjectType objtype, Node *object,
961961
Relation *relp, LOCKMODE lockmode, bool missing_ok)
962962
{
963-
ObjectAddress address;
963+
ObjectAddress address = {InvalidOid, InvalidOid, 0};
964964
ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
965965
Relation relation = NULL;
966966
uint64 inval_count;
@@ -991,6 +991,7 @@ get_object_address(ObjectType objtype, Node *object,
991991
&relation, lockmode,
992992
missing_ok);
993993
break;
994+
case OBJECT_ATTRIBUTE:
994995
case OBJECT_COLUMN:
995996
address =
996997
get_object_address_attribute(objtype, castNode(List, object),
@@ -1163,14 +1164,12 @@ get_object_address(ObjectType objtype, Node *object,
11631164
missing_ok);
11641165
address.objectSubId = 0;
11651166
break;
1166-
default:
1167-
elog(ERROR, "unrecognized object type: %d", (int) objtype);
1168-
/* placate compiler, in case it thinks elog might return */
1169-
address.classId = InvalidOid;
1170-
address.objectId = InvalidOid;
1171-
address.objectSubId = 0;
1167+
/* no default, to let compiler warn about missing case */
11721168
}
11731169

1170+
if (!address.classId)
1171+
elog(ERROR, "unrecognized object type: %d", (int) objtype);
1172+
11741173
/*
11751174
* If we could not find the supplied object, return without locking.
11761175
*/
@@ -2571,9 +2570,16 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
25712570
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
25722571
errmsg("must be superuser")));
25732572
break;
2574-
default:
2575-
elog(ERROR, "unrecognized object type: %d",
2576-
(int) objtype);
2573+
case OBJECT_AMOP:
2574+
case OBJECT_AMPROC:
2575+
case OBJECT_DEFAULT:
2576+
case OBJECT_DEFACL:
2577+
case OBJECT_PUBLICATION_NAMESPACE:
2578+
case OBJECT_PUBLICATION_REL:
2579+
case OBJECT_USER_MAPPING:
2580+
/* These are currently not supported or don't make sense here. */
2581+
elog(ERROR, "unsupported object type: %d", (int) objtype);
2582+
break;
25772583
}
25782584
}
25792585

src/backend/commands/dropcmds.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,45 @@ does_not_exist_skipping(ObjectType objtype, Node *object)
481481
msg = gettext_noop("publication \"%s\" does not exist, skipping");
482482
name = strVal(object);
483483
break;
484-
default:
485-
elog(ERROR, "unrecognized object type: %d", (int) objtype);
484+
485+
case OBJECT_COLUMN:
486+
case OBJECT_DATABASE:
487+
case OBJECT_FOREIGN_TABLE:
488+
case OBJECT_INDEX:
489+
case OBJECT_MATVIEW:
490+
case OBJECT_ROLE:
491+
case OBJECT_SEQUENCE:
492+
case OBJECT_SUBSCRIPTION:
493+
case OBJECT_TABLE:
494+
case OBJECT_TABLESPACE:
495+
case OBJECT_VIEW:
496+
/*
497+
* These are handled elsewhere, so if someone gets here the code
498+
* is probably wrong or should be revisited.
499+
*/
500+
elog(ERROR, "unsupported object type: %d", (int) objtype);
501+
break;
502+
503+
case OBJECT_AMOP:
504+
case OBJECT_AMPROC:
505+
case OBJECT_ATTRIBUTE:
506+
case OBJECT_DEFAULT:
507+
case OBJECT_DEFACL:
508+
case OBJECT_DOMCONSTRAINT:
509+
case OBJECT_LARGEOBJECT:
510+
case OBJECT_PARAMETER_ACL:
511+
case OBJECT_PUBLICATION_NAMESPACE:
512+
case OBJECT_PUBLICATION_REL:
513+
case OBJECT_TABCONSTRAINT:
514+
case OBJECT_USER_MAPPING:
515+
/* These are currently not used or needed. */
516+
elog(ERROR, "unsupported object type: %d", (int) objtype);
486517
break;
518+
519+
/* no default, to let compiler warn about missing case */
487520
}
521+
if (!msg)
522+
elog(ERROR, "unrecognized object type: %d", (int) objtype);
488523

489524
if (!args)
490525
ereport(NOTICE, (errmsg(msg, name)));

0 commit comments

Comments
 (0)