]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
aio: Improve assertions related to io_method
authorAndres Freund <andres@anarazel.de>
Wed, 5 Nov 2025 00:23:13 +0000 (19:23 -0500)
committerAndres Freund <andres@anarazel.de>
Wed, 5 Nov 2025 01:03:53 +0000 (20:03 -0500)
First, the assertions in assign_io_method() were the wrong way round. Second,
the lengthof() assertion checked the length of io_method_options, which is the
wrong array to check and is always longer than pgaio_method_ops_table.

While add it, add a static assert to ensure pgaio_method_ops_table and
io_method_options stay in sync.

Per coverity and Tom Lane.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 18

src/backend/storage/aio/aio.c

index 87d7136a936477baf34c2f19fec5d101f6790694..dcc47069757a7f6e6ea52602694d91e65deef0dc 100644 (file)
@@ -89,6 +89,9 @@ static const IoMethodOps *const pgaio_method_ops_table[] = {
 #endif
 };
 
+StaticAssertDecl(lengthof(io_method_options) == lengthof(pgaio_method_ops_table) + 1,
+                                "io_method_options out of sync with pgaio_method_ops_table");
+
 /* callbacks for the configured io_method, set by assign_io_method */
 const IoMethodOps *pgaio_method_ops;
 
@@ -1318,8 +1321,8 @@ pgaio_shutdown(int code, Datum arg)
 void
 assign_io_method(int newval, void *extra)
 {
+       Assert(newval < lengthof(pgaio_method_ops_table));
        Assert(pgaio_method_ops_table[newval] != NULL);
-       Assert(newval < lengthof(io_method_options));
 
        pgaio_method_ops = pgaio_method_ops_table[newval];
 }