Skip to content

Commit 33b2a2c

Browse files
committed
Fix statically allocated struct with FLEXIBLE_ARRAY_MEMBER member.
clang complains about this, not unreasonably, so define another struct that's explicitly for a WordEntryPos with exactly one element. While at it, get rid of pretty dubious use of a static variable for more than one purpose --- if it were being treated as const maybe I'd be okay with this, but it isn't.
1 parent 33a3b03 commit 33b2a2c

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/backend/utils/adt/tsrank.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,12 @@ SortAndUniqItems(TSQuery q, int *size)
195195
return res;
196196
}
197197

198-
/* A dummy WordEntryPos array to use when haspos is false */
199-
static WordEntryPosVector POSNULL = {
200-
1, /* Number of elements that follow */
201-
{0}
202-
};
203-
204198
static float
205199
calc_rank_and(const float *w, TSVector t, TSQuery q)
206200
{
207201
WordEntryPosVector **pos;
202+
WordEntryPosVector1 posnull;
203+
WordEntryPosVector *POSNULL;
208204
int i,
209205
k,
210206
l,
@@ -228,7 +224,12 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
228224
return calc_rank_or(w, t, q);
229225
}
230226
pos = (WordEntryPosVector **) palloc0(sizeof(WordEntryPosVector *) * q->size);
231-
WEP_SETPOS(POSNULL.pos[0], MAXENTRYPOS - 1);
227+
228+
/* A dummy WordEntryPos array to use when haspos is false */
229+
posnull.npos = 1;
230+
posnull.pos[0] = 0;
231+
WEP_SETPOS(posnull.pos[0], MAXENTRYPOS - 1);
232+
POSNULL = (WordEntryPosVector *) &posnull;
232233

233234
for (i = 0; i < size; i++)
234235
{
@@ -241,7 +242,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
241242
if (entry->haspos)
242243
pos[i] = _POSVECPTR(t, entry);
243244
else
244-
pos[i] = &POSNULL;
245+
pos[i] = POSNULL;
245246

246247
dimt = pos[i]->npos;
247248
post = pos[i]->pos;
@@ -256,7 +257,7 @@ calc_rank_and(const float *w, TSVector t, TSQuery q)
256257
for (p = 0; p < lenct; p++)
257258
{
258259
dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
259-
if (dist || (dist == 0 && (pos[i] == &POSNULL || pos[k] == &POSNULL)))
260+
if (dist || (dist == 0 && (pos[i] == POSNULL || pos[k] == POSNULL)))
260261
{
261262
float curw;
262263

@@ -282,6 +283,7 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
282283
{
283284
WordEntry *entry,
284285
*firstentry;
286+
WordEntryPosVector1 posnull;
285287
WordEntryPos *post;
286288
int32 dimt,
287289
j,
@@ -291,6 +293,10 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
291293
QueryOperand **item;
292294
int size = q->size;
293295

296+
/* A dummy WordEntryPos array to use when haspos is false */
297+
posnull.npos = 1;
298+
posnull.pos[0] = 0;
299+
294300
item = SortAndUniqItems(q, &size);
295301

296302
for (i = 0; i < size; i++)
@@ -312,8 +318,8 @@ calc_rank_or(const float *w, TSVector t, TSQuery q)
312318
}
313319
else
314320
{
315-
dimt = POSNULL.npos;
316-
post = POSNULL.pos;
321+
dimt = posnull.npos;
322+
post = posnull.pos;
317323
}
318324

319325
resj = 0.0;

src/include/tsearch/ts_type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ typedef struct
6666
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER];
6767
} WordEntryPosVector;
6868

69+
/* WordEntryPosVector with exactly 1 entry */
70+
typedef struct
71+
{
72+
uint16 npos;
73+
WordEntryPos pos[1];
74+
} WordEntryPosVector1;
75+
6976

7077
#define WEP_GETWEIGHT(x) ( (x) >> 14 )
7178
#define WEP_GETPOS(x) ( (x) & 0x3fff )

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