Initialize HASHCTL differently, to suppress Coverity warning
authorHeikki Linnakangas <[email protected]>
Sun, 11 Aug 2024 17:21:16 +0000 (20:21 +0300)
committerHeikki Linnakangas <[email protected]>
Sun, 11 Aug 2024 17:21:16 +0000 (20:21 +0300)
Coverity complained that the hash_create() call might access
hash_table_ctl->hctl. That's a false alarm, hash_create() only
accesses that field when passed the HASH_SHARED_MEM flag. Try to
silence it by using a plain local variable instead of a const. That's
how the HASHCTL is initialized in all the other hash_create() calls.

src/backend/access/transam/xlogprefetcher.c

index 2dc2fb760a20d3231b3640b3037457239eca1343..ecd794148c516179ceac9ab3d544d54a8a3e4b32 100644 (file)
@@ -362,17 +362,15 @@ XLogPrefetcher *
 XLogPrefetcherAllocate(XLogReaderState *reader)
 {
        XLogPrefetcher *prefetcher;
-       const HASHCTL hash_table_ctl = {
-               .keysize = sizeof(RelFileLocator),
-               .entrysize = sizeof(XLogPrefetcherFilter)
-       };
+       HASHCTL ctl;
 
        prefetcher = palloc0(sizeof(XLogPrefetcher));
-
        prefetcher->reader = reader;
+
+       ctl.keysize = sizeof(RelFileLocator);
+       ctl.entrysize = sizeof(XLogPrefetcherFilter);
        prefetcher->filter_table = hash_create("XLogPrefetcherFilterTable", 1024,
-                                                                                  &hash_table_ctl,
-                                                                                  HASH_ELEM | HASH_BLOBS);
+                                                                                  &ctl, HASH_ELEM | HASH_BLOBS);
        dlist_init(&prefetcher->filter_queue);
 
        SharedStats->wal_distance = 0;