@@ -220,31 +220,17 @@ bt_page_stats(PG_FUNCTION_ARGS)
220220 elog (ERROR , "return type must be a row type" );
221221
222222 j = 0 ;
223- values [j ] = palloc (32 );
224- snprintf (values [j ++ ], 32 , "%d" , stat .blkno );
225- values [j ] = palloc (32 );
226- snprintf (values [j ++ ], 32 , "%c" , stat .type );
227- values [j ] = palloc (32 );
228- snprintf (values [j ++ ], 32 , "%d" , stat .live_items );
229- values [j ] = palloc (32 );
230- snprintf (values [j ++ ], 32 , "%d" , stat .dead_items );
231- values [j ] = palloc (32 );
232- snprintf (values [j ++ ], 32 , "%d" , stat .avg_item_size );
233- values [j ] = palloc (32 );
234- snprintf (values [j ++ ], 32 , "%d" , stat .page_size );
235- values [j ] = palloc (32 );
236- snprintf (values [j ++ ], 32 , "%d" , stat .free_size );
237- values [j ] = palloc (32 );
238- snprintf (values [j ++ ], 32 , "%d" , stat .btpo_prev );
239- values [j ] = palloc (32 );
240- snprintf (values [j ++ ], 32 , "%d" , stat .btpo_next );
241- values [j ] = palloc (32 );
242- if (stat .type == 'd' )
243- snprintf (values [j ++ ], 32 , "%d" , stat .btpo .xact );
244- else
245- snprintf (values [j ++ ], 32 , "%d" , stat .btpo .level );
246- values [j ] = palloc (32 );
247- snprintf (values [j ++ ], 32 , "%d" , stat .btpo_flags );
223+ values [j ++ ] = psprintf ("%d" , stat .blkno );
224+ values [j ++ ] = psprintf ("%c" , stat .type );
225+ values [j ++ ] = psprintf ("%d" , stat .live_items );
226+ values [j ++ ] = psprintf ("%d" , stat .dead_items );
227+ values [j ++ ] = psprintf ("%d" , stat .avg_item_size );
228+ values [j ++ ] = psprintf ("%d" , stat .page_size );
229+ values [j ++ ] = psprintf ("%d" , stat .free_size );
230+ values [j ++ ] = psprintf ("%d" , stat .btpo_prev );
231+ values [j ++ ] = psprintf ("%d" , stat .btpo_next );
232+ values [j ++ ] = psprintf ("%d" , (stat .type == 'd' ) ? stat .btpo .xact : stat .btpo .level );
233+ values [j ++ ] = psprintf ("%d" , stat .btpo_flags );
248234
249235 tuple = BuildTupleFromCStrings (TupleDescGetAttInMetadata (tupleDesc ),
250236 values );
@@ -380,18 +366,13 @@ bt_page_items(PG_FUNCTION_ARGS)
380366 itup = (IndexTuple ) PageGetItem (uargs -> page , id );
381367
382368 j = 0 ;
383- values [j ] = palloc (32 );
384- snprintf (values [j ++ ], 32 , "%d" , uargs -> offset );
385- values [j ] = palloc (32 );
386- snprintf (values [j ++ ], 32 , "(%u,%u)" ,
387- BlockIdGetBlockNumber (& (itup -> t_tid .ip_blkid )),
388- itup -> t_tid .ip_posid );
389- values [j ] = palloc (32 );
390- snprintf (values [j ++ ], 32 , "%d" , (int ) IndexTupleSize (itup ));
391- values [j ] = palloc (32 );
392- snprintf (values [j ++ ], 32 , "%c" , IndexTupleHasNulls (itup ) ? 't' : 'f' );
393- values [j ] = palloc (32 );
394- snprintf (values [j ++ ], 32 , "%c" , IndexTupleHasVarwidths (itup ) ? 't' : 'f' );
369+ values [j ++ ] = psprintf ("%d" , uargs -> offset );
370+ values [j ++ ] = psprintf ("(%u,%u)" ,
371+ BlockIdGetBlockNumber (& (itup -> t_tid .ip_blkid )),
372+ itup -> t_tid .ip_posid );
373+ values [j ++ ] = psprintf ("%d" , (int ) IndexTupleSize (itup ));
374+ values [j ++ ] = psprintf ("%c" , IndexTupleHasNulls (itup ) ? 't' : 'f' );
375+ values [j ++ ] = psprintf ("%c" , IndexTupleHasVarwidths (itup ) ? 't' : 'f' );
395376
396377 ptr = (char * ) itup + IndexInfoFindDataOffset (itup -> t_info );
397378 dlen = IndexTupleSize (itup ) - IndexInfoFindDataOffset (itup -> t_info );
@@ -477,18 +458,12 @@ bt_metap(PG_FUNCTION_ARGS)
477458 elog (ERROR , "return type must be a row type" );
478459
479460 j = 0 ;
480- values [j ] = palloc (32 );
481- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_magic );
482- values [j ] = palloc (32 );
483- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_version );
484- values [j ] = palloc (32 );
485- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_root );
486- values [j ] = palloc (32 );
487- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_level );
488- values [j ] = palloc (32 );
489- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_fastroot );
490- values [j ] = palloc (32 );
491- snprintf (values [j ++ ], 32 , "%d" , metad -> btm_fastlevel );
461+ values [j ++ ] = psprintf ("%d" , metad -> btm_magic );
462+ values [j ++ ] = psprintf ("%d" , metad -> btm_version );
463+ values [j ++ ] = psprintf ("%d" , metad -> btm_root );
464+ values [j ++ ] = psprintf ("%d" , metad -> btm_level );
465+ values [j ++ ] = psprintf ("%d" , metad -> btm_fastroot );
466+ values [j ++ ] = psprintf ("%d" , metad -> btm_fastlevel );
492467
493468 tuple = BuildTupleFromCStrings (TupleDescGetAttInMetadata (tupleDesc ),
494469 values );
0 commit comments