Skip to content

Commit a928484

Browse files
committed
Clean up some stuff in new contrib/bloom module.
Coverity complained about implicit sign-extension in the BloomPageGetFreeSpace macro, probably because sizeOfBloomTuple isn't wide enough for size calculations. No overflow is really possible as long as maxoff and sizeOfBloomTuple are small enough to represent a realistic situation, but it seems like a good idea to declare sizeOfBloomTuple as Size not int32. Add missing check on BloomPageAddItem() result, again from Coverity. Avoid core dump due to not allocating so->sign array when scan->numberOfKeys is zero. Also thanks to Coverity. Use FLEXIBLE_ARRAY_MEMBER rather than declaring an array as size 1 when it isn't necessarily. Very minor beautification of related code. Unfortunately, none of the Coverity-detected mistakes look like they could account for the remaining buildfarm unhappiness with this module. It's barely possible that the FLEXIBLE_ARRAY_MEMBER mistake does account for that, if it's enabling bogus compiler optimizations; but I'm not terribly optimistic. We probably still have bugs to find here.
1 parent 3e4b7d8 commit a928484

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

contrib/bloom/blinsert.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ bloomBuildCallback(Relation index, HeapTuple htup, Datum *values,
9696

9797
initCachedPage(buildstate);
9898

99-
if (BloomPageAddItem(&buildstate->blstate, buildstate->data, itup) == false)
99+
if (!BloomPageAddItem(&buildstate->blstate, buildstate->data, itup))
100100
{
101101
/* We shouldn't be here since we're inserting to the empty page */
102-
elog(ERROR, "can not add new tuple");
102+
elog(ERROR, "could not add new bloom tuple to empty page");
103103
}
104104
}
105105

@@ -298,7 +298,12 @@ blinsert(Relation index, Datum *values, bool *isnull,
298298
metaData = BloomPageGetMeta(metaPage);
299299
page = GenericXLogRegister(state, buffer, true);
300300
BloomInitPage(page, 0);
301-
BloomPageAddItem(&blstate, page, itup);
301+
302+
if (!BloomPageAddItem(&blstate, page, itup))
303+
{
304+
/* We shouldn't be here since we're inserting to the empty page */
305+
elog(ERROR, "could not add new bloom tuple to empty page");
306+
}
302307

303308
metaData->nStart = 0;
304309
metaData->nEnd = 1;

contrib/bloom/bloom.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ typedef struct BloomState
118118
* sizeOfBloomTuple is index's specific, and it depends on reloptions, so
119119
* precompute it
120120
*/
121-
int32 sizeOfBloomTuple;
121+
Size sizeOfBloomTuple;
122122
} BloomState;
123123

124124
#define BloomPageGetFreeSpace(state, page) \
@@ -134,7 +134,7 @@ typedef uint16 SignType;
134134
typedef struct BloomTuple
135135
{
136136
ItemPointerData heapPtr;
137-
SignType sign[1];
137+
SignType sign[FLEXIBLE_ARRAY_MEMBER];
138138
} BloomTuple;
139139

140140
#define BLOOMTUPLEHDRSZ offsetof(BloomTuple, sign)

contrib/bloom/blscan.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
9494
BufferAccessStrategy bas;
9595
BloomScanOpaque so = (BloomScanOpaque) scan->opaque;
9696

97-
if (so->sign == NULL && scan->numberOfKeys > 0)
97+
if (so->sign == NULL)
9898
{
9999
/* New search: have to calculate search signature */
100100
ScanKey skey = scan->keyData;
@@ -151,10 +151,13 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
151151
bool res = true;
152152

153153
/* Check index signature with scan signature */
154-
for (i = 0; res && i < so->state.opts->bloomLength; i++)
154+
for (i = 0; i < so->state.opts->bloomLength; i++)
155155
{
156156
if ((itup->sign[i] & so->sign[i]) != so->sign[i])
157+
{
157158
res = false;
159+
break;
160+
}
158161
}
159162

160163
/* Add matching tuples to bitmap */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy