From b71852ab29f9787cb97de31f2f0bdb51697abe65 Mon Sep 17 00:00:00 2001 From: Robert Moore Date: Wed, 13 Jun 2012 13:50:52 -0700 Subject: [PATCH] AcpiSrc: Prevent two possible div-by-zero conditions. Ensure statistics display does not divide-by-zero. --- source/tools/acpisrc/asmain.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/tools/acpisrc/asmain.c b/source/tools/acpisrc/asmain.c index eb76be76f..fbb5937d1 100644 --- a/source/tools/acpisrc/asmain.c +++ b/source/tools/acpisrc/asmain.c @@ -317,10 +317,18 @@ AsDisplayStats ( printf ("%8u Lines of non-comment whitespace\n", Gbl_WhiteLines); printf ("%8u Lines of comments\n", Gbl_CommentLines); printf ("%8u Long lines found\n", Gbl_LongLines); - printf ("%8.1f Ratio of code to whitespace\n", - ((float) Gbl_SourceLines / (float) Gbl_WhiteLines)); - printf ("%8.1f Ratio of code to comments\n", - ((float) Gbl_SourceLines / (float) (Gbl_CommentLines + Gbl_NonAnsiComments))); + + if (Gbl_WhiteLines > 0) + { + printf ("%8.1f Ratio of code to whitespace\n", + ((float) Gbl_SourceLines / (float) Gbl_WhiteLines)); + } + + if ((Gbl_CommentLines + Gbl_NonAnsiComments) > 0) + { + printf ("%8.1f Ratio of code to comments\n", + ((float) Gbl_SourceLines / (float) (Gbl_CommentLines + Gbl_NonAnsiComments))); + } if (!Gbl_TotalLines) {