Skip to content

Commit dae00f3

Browse files
committed
aio: Improve assertions related to io_method
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 <[email protected]> Backpatch-through: 18
1 parent 2d83d72 commit dae00f3

File tree

1 file changed

+4
-1
lines changed
  • src/backend/storage/aio

1 file changed

+4
-1
lines changed

src/backend/storage/aio/aio.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static const IoMethodOps *const pgaio_method_ops_table[] = {
8989
#endif
9090
};
9191

92+
StaticAssertDecl(lengthof(io_method_options) == lengthof(pgaio_method_ops_table) + 1,
93+
"io_method_options out of sync with pgaio_method_ops_table");
94+
9295
/* callbacks for the configured io_method, set by assign_io_method */
9396
const IoMethodOps *pgaio_method_ops;
9497

@@ -1318,8 +1321,8 @@ pgaio_shutdown(int code, Datum arg)
13181321
void
13191322
assign_io_method(int newval, void *extra)
13201323
{
1324+
Assert(newval < lengthof(pgaio_method_ops_table));
13211325
Assert(pgaio_method_ops_table[newval] != NULL);
1322-
Assert(newval < lengthof(io_method_options));
13231326

13241327
pgaio_method_ops = pgaio_method_ops_table[newval];
13251328
}

0 commit comments

Comments
 (0)