From: Jim Nasby <Jim.Nasby@BlueTreble.com>
To: Robert Haas <robertmhaas@gmail.com>
To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: object_classes array is broken, again
Date: Fri, 26 Jun 2015 17:22:55 -0500
Message-ID: <558DD0BF.1000407@BlueTreble.com> (raw)
In-Reply-To: <CA+Tgmoa6SgDaxW_n_7SEhwBAc=mniYga+obUj5fmw4rU9_mLvA@mail.gmail.com>
References: <CA+Tgmoa6SgDaxW_n_7SEhwBAc=mniYga+obUj5fmw4rU9_mLvA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 6/24/15 2:11 PM, Robert Haas wrote:
> Fixing this is easy, but ISTM that we need to insert some sort of a
> guard to prevent people from continuing to forget this, because it's
> apparently quite easy to do. Perhaps add_object_address should
> Assert(OidIsValid(object_classes[oclass])), plus a (static?) assert
> someplace checking that OidIsValid(object_classes[MAX_OCLASS - 1])?
I tried doing this and I'm getting a "static_assert expression is not an
integral constant expression" error, even when I reduce it to a simple
constant comparison. Maybe I'm just doing something dumb...
If I replace the StaticAssert with
Assert(OidIsValid(object_classes[MAX_OCLASS - 1])) it works find and
initdb will fail if that assert trips.
I've attached the broken StaticAssert version. Also added a warning
comment to the enum.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:oclass_broken.patch (text/plain, 1.2K) downloaddiff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.cindex c1212e9..7adc216 100644--- a/src/backend/catalog/dependency.c+++ b/src/backend/catalog/dependency.c@@ -2037,6 +2037,15 @@ add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
{
ObjectAddress *item;
+ /*+ * Ensure object_classes is properly sized. Can't use OidIsValid here+ * because it's not marked as static (nor should it be).+ */+ StaticAssertStmt(object_classes[MAX_OCLASS - 1] != 0,+ "last OID in object_classes[] is invalid (did you forget to add a new entry to it?)");++ Assert(OidIsValid(object_classes[oclass]));+
/* enlarge array if needed */
if (addrs->numrefs >= addrs->maxrefs)
{
diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.hindex 5da18c2..515417d 100644--- a/src/include/catalog/dependency.h+++ b/src/include/catalog/dependency.h@@ -149,6 +149,8 @@ typedef enum ObjectClass
OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
OCLASS_POLICY, /* pg_policy */
OCLASS_TRANSFORM, /* pg_transform */
+ + /* New classes need to be added to object_classes[] too. */
MAX_OCLASS /* MUST BE LAST */
} ObjectClass;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: Jim.Nasby@BlueTreble.com, robertmhaas@gmail.com
Subject: Re: object_classes array is broken, again
In-Reply-To: <558DD0BF.1000407@BlueTreble.com>
References: <CA+Tgmoa6SgDaxW_n_7SEhwBAc=mniYga+obUj5fmw4rU9_mLvA@mail.gmail.com> <558DD0BF.1000407@BlueTreble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox