From 667d5ed206942aa21c3e41919fa8f0cce98599e6 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 25 Jul 2000 20:17:02 +0000
Subject: [PATCH] Fix confusion between sizeof(long) and sizeof(long*), as well
 as failure to MAXALIGN the start of shmem allocable space.  No reports of
 trouble here, just compulsive tidiness.

---
 src/backend/storage/ipc/shmem.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 4c590a2774b..0fa6c54256a 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.52 2000/06/28 03:31:57 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.53 2000/07/25 20:17:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -171,17 +171,18 @@ InitShmem(unsigned int key, unsigned int size)
 	/* get pointers to the dimensions of shared memory */
 	ShmemBase = (unsigned long) sharedRegion;
 	ShmemEnd = (unsigned long) sharedRegion + ShmemSize;
-	currFreeSpace = 0;
 
-	/* First long in shared memory is the count of available space */
+	/* First long in shared memory is the available-space pointer */
 	ShmemFreeStart = (unsigned long *) ShmemBase;
 	/* next is a shmem pointer to the shmem index */
 	ShmemIndexOffset = ShmemFreeStart + 1;
 	/* next is ShmemVariableCache */
 	ShmemVariableCache = (VariableCache) (ShmemIndexOffset + 1);
 
-	currFreeSpace += sizeof(ShmemFreeStart) + sizeof(ShmemIndexOffset) +
-		LONGALIGN(sizeof(VariableCacheData));
+	/* here is where to start dynamic allocation */
+	currFreeSpace = MAXALIGN(sizeof(*ShmemFreeStart) +
+							 sizeof(*ShmemIndexOffset) +
+							 sizeof(*ShmemVariableCache));
 
 	/*
 	 * bootstrap initialize spin locks so we can start to use the
@@ -510,7 +511,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr)
 		}
 		else
 		{
-			Assert(ShmemIndexOffset);
+			Assert(*ShmemIndexOffset);
 
 			*foundPtr = TRUE;
 			return (void *) MAKE_PTR(*ShmemIndexOffset);
-- 
GitLab