Fix some compiler warnings in aset.c and generation.c
authorDavid Rowley <[email protected]>
Wed, 4 Jan 2023 23:56:17 +0000 (12:56 +1300)
committerDavid Rowley <[email protected]>
Wed, 4 Jan 2023 23:56:17 +0000 (12:56 +1300)
This fixes a couple of unused variable warnings that could be seen when
compiling with MEMORY_CONTEXT_CHECKING but not USE_ASSERT_CHECKING.
Defining MEMORY_CONTEXT_CHECKING without asserts is a little unusual,
however, we shouldn't be producing any warnings from such a build.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4_D-vgLEh7eO47p=73u1jWO78NWf6Qfv1FndY1kG-Q-jA@mail.gmail.com

src/backend/utils/mmgr/aset.c
src/backend/utils/mmgr/generation.c

index ef10bb1690be8e642aae5881151378405020a8e8..740729b5d08bc4974974d08a6c4852d19479c527 100644 (file)
@@ -1024,10 +1024,8 @@ AllocSetFree(void *pointer)
 
 #ifdef MEMORY_CONTEXT_CHECKING
                {
-                       Size            chunk_size = block->endptr - (char *) pointer;
-
                        /* Test for someone scribbling on unused space in chunk */
-                       Assert(chunk->requested_size < chunk_size);
+                       Assert(chunk->requested_size < (block->endptr - (char *) pointer));
                        if (!sentinel_ok(pointer, chunk->requested_size))
                                elog(WARNING, "detected write past chunk end in %s %p",
                                         set->header.name, chunk);
index 93825265a1b57b071802ab94891c794506459162..ebcb61e9b6a6598e7e0380ecc1ccad26ceda9438 100644 (file)
@@ -629,7 +629,8 @@ GenerationFree(void *pointer)
        MemoryChunk *chunk = PointerGetMemoryChunk(pointer);
        GenerationBlock *block;
        GenerationContext *set;
-#if defined(MEMORY_CONTEXT_CHECKING) || defined(CLOBBER_FREED_MEMORY)
+#if (defined(MEMORY_CONTEXT_CHECKING) && defined(USE_ASSERT_CHECKING)) \
+       || defined(CLOBBER_FREED_MEMORY)
        Size            chunksize;
 #endif
 
@@ -644,7 +645,8 @@ GenerationFree(void *pointer)
                if (!GenerationBlockIsValid(block))
                        elog(ERROR, "could not find block containing chunk %p", chunk);
 
-#if defined(MEMORY_CONTEXT_CHECKING) || defined(CLOBBER_FREED_MEMORY)
+#if (defined(MEMORY_CONTEXT_CHECKING) && defined(USE_ASSERT_CHECKING)) \
+       || defined(CLOBBER_FREED_MEMORY)
                chunksize = block->endptr - (char *) pointer;
 #endif
        }
@@ -659,7 +661,8 @@ GenerationFree(void *pointer)
                 */
                Assert(GenerationBlockIsValid(block));
 
-#if defined(MEMORY_CONTEXT_CHECKING) || defined(CLOBBER_FREED_MEMORY)
+#if (defined(MEMORY_CONTEXT_CHECKING) && defined(USE_ASSERT_CHECKING)) \
+       || defined(CLOBBER_FREED_MEMORY)
                chunksize = MemoryChunkGetValue(chunk);
 #endif
        }