Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9fe1d9a

Browse files
committed
Fix possible division by zero in pg_xlogdump.
When displaying stats it was possible that a floating point division byzero occured when no FPIs were issued for a type of record.Author: Abhijit Menon-SenDiscussion: 20150417091811.GA14008@toroid.org
1 parentcac7658 commit9fe1d9a

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

‎src/bin/pg_xlogdump/pg_xlogdump.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,18 +489,36 @@ XLogDumpDisplayRecord(XLogDumpConfig *config, XLogReaderState *record)
489489
*/
490490
staticvoid
491491
XLogDumpStatsRow(constchar*name,
492-
uint64n,doublen_pct,
493-
uint64rec_len,doublerec_len_pct,
494-
uint64fpi_len,doublefpi_len_pct,
495-
uint64total_len,doubletotal_len_pct)
492+
uint64n,uint64total_count,
493+
uint64rec_len,uint64total_rec_len,
494+
uint64fpi_len,uint64total_fpi_len,
495+
uint64tot_len,uint64total_len)
496496
{
497+
doublen_pct,rec_len_pct,fpi_len_pct,tot_len_pct;
498+
499+
n_pct=0;
500+
if (total_count!=0)
501+
n_pct=100* (double)n /total_count;
502+
503+
rec_len_pct=0;
504+
if (total_rec_len!=0)
505+
rec_len_pct=100* (double)rec_len /total_rec_len;
506+
507+
fpi_len_pct=0;
508+
if (total_fpi_len!=0)
509+
fpi_len_pct=100* (double)fpi_len /total_fpi_len;
510+
511+
tot_len_pct=0;
512+
if (total_len!=0)
513+
tot_len_pct=100* (double)tot_len /total_len;
514+
497515
printf("%-27s "
498516
"%20"INT64_MODIFIER"u (%6.02f) "
499517
"%20"INT64_MODIFIER"u (%6.02f) "
500518
"%20"INT64_MODIFIER"u (%6.02f) "
501519
"%20"INT64_MODIFIER"u (%6.02f)\n",
502520
name,n,n_pct,rec_len,rec_len_pct,fpi_len,fpi_len_pct,
503-
total_len,total_len_pct);
521+
tot_len,tot_len_pct);
504522
}
505523

506524

@@ -515,6 +533,7 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogDumpStats *stats)
515533
uint64total_rec_len=0;
516534
uint64total_fpi_len=0;
517535
uint64total_len=0;
536+
doublerec_len_pct,fpi_len_pct;
518537

519538
/* ---
520539
* Make a first pass to calculate column totals:
@@ -557,10 +576,8 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogDumpStats *stats)
557576
tot_len=rec_len+fpi_len;
558577

559578
XLogDumpStatsRow(desc->rm_name,
560-
count,100* (double)count /total_count,
561-
rec_len,100* (double)rec_len /total_rec_len,
562-
fpi_len,100* (double)fpi_len /total_fpi_len,
563-
tot_len,100* (double)tot_len /total_len);
579+
count,total_count,rec_len,total_rec_len,
580+
fpi_len,total_fpi_len,tot_len,total_len);
564581
}
565582
else
566583
{
@@ -583,10 +600,8 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogDumpStats *stats)
583600
id=psprintf("UNKNOWN (%x)",rj <<4);
584601

585602
XLogDumpStatsRow(psprintf("%s/%s",desc->rm_name,id),
586-
count,100* (double)count /total_count,
587-
rec_len,100* (double)rec_len /total_rec_len,
588-
fpi_len,100* (double)fpi_len /total_fpi_len,
589-
tot_len,100* (double)tot_len /total_len);
603+
count,total_count,rec_len,total_rec_len,
604+
fpi_len,total_fpi_len,tot_len,total_len);
590605
}
591606
}
592607
}
@@ -601,14 +616,22 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogDumpStats *stats)
601616
* them from the earlier ones, and are thus up to 9 characters long.
602617
*/
603618

619+
rec_len_pct=0;
620+
if (total_len!=0)
621+
rec_len_pct=100* (double)total_rec_len /total_len;
622+
623+
fpi_len_pct=0;
624+
if (total_len!=0)
625+
fpi_len_pct=100* (double)total_fpi_len /total_len;
626+
604627
printf("%-27s "
605628
"%20"INT64_MODIFIER"u %-9s"
606629
"%20"INT64_MODIFIER"u %-9s"
607630
"%20"INT64_MODIFIER"u %-9s"
608631
"%20"INT64_MODIFIER"u %-6s\n",
609632
"Total",stats->count,"",
610-
total_rec_len,psprintf("[%.02f%%]",100* (double)total_rec_len /total_len),
611-
total_fpi_len,psprintf("[%.02f%%]",100* (double)total_fpi_len /total_len),
633+
total_rec_len,psprintf("[%.02f%%]",rec_len_pct),
634+
total_fpi_len,psprintf("[%.02f%%]",fpi_len_pct),
612635
total_len,"[100%]");
613636
}
614637

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp