Commit de9c553f authored by Tom Lane's avatar Tom Lane

Clean up locktable init code per recent gripe from Kurt Roeckx.

No change in behavior, but old code would have failed to detect
overrun of MAX_LOCKMODES.
parent c7718381
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.58 2003/08/04 02:40:03 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.59 2003/08/17 22:41:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -76,8 +76,10 @@ InitLockTable(int maxBackends) ...@@ -76,8 +76,10 @@ InitLockTable(int maxBackends)
{ {
int lockmethod; int lockmethod;
/* number of lock modes is lengthof()-1 because of dummy zero */
lockmethod = LockMethodTableInit("LockTable", lockmethod = LockMethodTableInit("LockTable",
LockConflicts, MAX_LOCKMODES - 1, LockConflicts,
lengthof(LockConflicts) - 1,
maxBackends); maxBackends);
LockTableId = lockmethod; LockTableId = lockmethod;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.126 2003/08/04 02:40:03 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.127 2003/08/17 22:41:12 tgl Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -212,8 +212,8 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable, ...@@ -212,8 +212,8 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable,
int i; int i;
lockMethodTable->numLockModes = numModes; lockMethodTable->numLockModes = numModes;
numModes++; /* copies useless zero element as well as the N lockmodes */
for (i = 0; i < numModes; i++, conflictsP++) for (i = 0; i <= numModes; i++, conflictsP++)
lockMethodTable->conflictTab[i] = *conflictsP; lockMethodTable->conflictTab[i] = *conflictsP;
} }
...@@ -241,11 +241,8 @@ LockMethodTableInit(char *tabName, ...@@ -241,11 +241,8 @@ LockMethodTableInit(char *tabName,
max_table_size; max_table_size;
if (numModes >= MAX_LOCKMODES) if (numModes >= MAX_LOCKMODES)
{ elog(ERROR, "too many lock types %d (limit is %d)",
elog(WARNING, "too many lock types %d (limit is %d)", numModes, MAX_LOCKMODES-1);
numModes, MAX_LOCKMODES);
return INVALID_LOCKMETHOD;
}
/* Compute init/max size to request for lock hashtables */ /* Compute init/max size to request for lock hashtables */
max_table_size = NLOCKENTS(maxBackends); max_table_size = NLOCKENTS(maxBackends);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment