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

Commit de9c553

Browse files
committed
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.
1 parent c771838 commit de9c553

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/backend/storage/lmgr/lmgr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.58 2003/08/04 02:40:03 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.59 2003/08/17 22:41:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -76,8 +76,10 @@ InitLockTable(int maxBackends)
7676
{
7777
int lockmethod;
7878

79+
/* number of lock modes is lengthof()-1 because of dummy zero */
7980
lockmethod = LockMethodTableInit("LockTable",
80-
LockConflicts, MAX_LOCKMODES - 1,
81+
LockConflicts,
82+
lengthof(LockConflicts) - 1,
8183
maxBackends);
8284
LockTableId = lockmethod;
8385

src/backend/storage/lmgr/lock.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.126 2003/08/04 02:40:03 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.127 2003/08/17 22:41:12 tgl Exp $
1212
*
1313
* NOTES
1414
* Outside modules can create a lock table and acquire/release
@@ -212,8 +212,8 @@ LockMethodInit(LOCKMETHODTABLE *lockMethodTable,
212212
int i;
213213

214214
lockMethodTable->numLockModes = numModes;
215-
numModes++;
216-
for (i = 0; i < numModes; i++, conflictsP++)
215+
/* copies useless zero element as well as the N lockmodes */
216+
for (i = 0; i <= numModes; i++, conflictsP++)
217217
lockMethodTable->conflictTab[i] = *conflictsP;
218218
}
219219

@@ -241,11 +241,8 @@ LockMethodTableInit(char *tabName,
241241
max_table_size;
242242

243243
if (numModes >= MAX_LOCKMODES)
244-
{
245-
elog(WARNING, "too many lock types %d (limit is %d)",
246-
numModes, MAX_LOCKMODES);
247-
return INVALID_LOCKMETHOD;
248-
}
244+
elog(ERROR, "too many lock types %d (limit is %d)",
245+
numModes, MAX_LOCKMODES-1);
249246

250247
/* Compute init/max size to request for lock hashtables */
251248
max_table_size = NLOCKENTS(maxBackends);

0 commit comments

Comments
 (0)