Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9d3b8f

Browse files
committed
Fix uninitialized value in pgstatindex leading to invalid values being
reported in some cases. Report and patch from Tatsuhito Kasahara. Also fix a couple of other bugs I noticed in skimming the surrounding code.
1 parent f6e3313 commit c9d3b8f

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

contrib/pgstattuple/pgstatindex.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ typedef struct BTIndexStat
139139
* Collect statistics of single b-tree leaf page
140140
* -------------------------------------------------
141141
*/
142-
static bool
142+
static void
143143
GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
144144
{
145145
Page page = BufferGetPage(buffer);
@@ -154,14 +154,16 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
154154
stat->max_avail = BLCKSZ - (BLCKSZ - phdr->pd_special + SizeOfPageHeaderData);
155155

156156
stat->dead_items = stat->live_items = 0;
157+
stat->fragments = 0;
157158

158159
stat->page_size = PageGetPageSize(page);
159160

160161
/* page type (flags) */
161162
if (P_ISDELETED(opaque))
162163
{
163164
stat->type = 'd';
164-
return true;
165+
stat->btpo.xact = opaque->btpo.xact;
166+
return;
165167
}
166168
else if (P_IGNORE(opaque))
167169
stat->type = 'e';
@@ -175,10 +177,7 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
175177
/* btpage opaque data */
176178
stat->btpo_prev = opaque->btpo_prev;
177179
stat->btpo_next = opaque->btpo_next;
178-
if (P_ISDELETED(opaque))
179-
stat->btpo.xact = opaque->btpo.xact;
180-
else
181-
stat->btpo.level = opaque->btpo.level;
180+
stat->btpo.level = opaque->btpo.level;
182181
stat->btpo_flags = opaque->btpo_flags;
183182
stat->btpo_cycleid = opaque->btpo_cycleid;
184183

@@ -187,7 +186,6 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
187186
* it means a fragmentation.
188187
*----------------------------------------------
189188
*/
190-
stat->fragments = 0;
191189
if (stat->type == 'l')
192190
{
193191
if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
@@ -216,8 +214,6 @@ GetBTPageStatistics(BlockNumber blkno, Buffer buffer, BTPageStat * stat)
216214
stat->avg_item_size = item_size / (stat->live_items + stat->dead_items);
217215
else
218216
stat->avg_item_size = 0;
219-
220-
return true;
221217
}
222218

223219

@@ -338,8 +334,7 @@ pgstatindex(PG_FUNCTION_ARGS)
338334
int j;
339335
char *values[PGSTATINDEX_NCOLUMNS];
340336

341-
HeapTupleData tupleData;
342-
HeapTuple tuple = &tupleData;
337+
HeapTuple tuple;
343338

344339
tupleDesc = RelationNameGetTupleDesc(PGSTATINDEX_TYPE);
345340

0 commit comments

Comments
 (0)