Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: buildroot@busybox.net
Subject: [Buildroot] potential divide by zero in support/scripts/size-stats
Date: Mon, 27 Nov 2017 22:08:49 +0100	[thread overview]
Message-ID: <20171127220849.5f62e6fc@windsurf.home> (raw)
In-Reply-To: <CAAkeqgUXF5eVOjQEUkM0OARw+cvMxGG-REv2rw-3BRu9y-yz0A@mail.gmail.com>

Hello,

On Sat, 11 Nov 2017 18:17:36 -0800, Andrey Yurovsky wrote:
> I see a divide by zero exception in support/scripts/size-stats when I
> use the graph-size target, the package of size zero causing this is
> skeleton-init-systemd which I worked out by catching the exception. Is
> this package erroneously of size zero or should that be OK?

Thanks for reporting this bug and proposing a fix! I have some comments
on the implementation, but first about the format: the commit log
should contain a Signed-off-by line with your name and e-mail, and the
commit log should not be formatted as a personal message, but rather as
a description of what is being changed/fixed. Also the first line
should look like: "support/scripts/size-stats: ..."

> diff --git a/support/scripts/size-stats b/support/scripts/size-stats
> index af45000..3cd6838 100755
> --- a/support/scripts/size-stats
> +++ b/support/scripts/size-stats
> @@ -178,9 +178,12 @@ def gen_files_csv(filesdict, pkgsizes, outputf):
>                       "File size in system (%)"])
>          for f, (pkgname, filesize) in filesdict.items():
>              pkgsize = pkgsizes[pkgname]
> -            wr.writerow([f, pkgname, filesize, pkgsize,
> -                         "%.1f" % (float(filesize) / pkgsize * 100),
> -                         "%.1f" % (float(filesize) / total * 100)])
> +            try:
> +                wr.writerow([f, pkgname, filesize, pkgsize,
> +                        "%.1f" % (float(filesize) / pkgsize * 100),
> +                        "%.1f" % (float(filesize) / total * 100)])
> +            except ZeroDivisionError:
> +                print('WARNING: \"%s\" is size 0!' % pkgname)

I don't think we want to skip files from zero-sized packages: we want
to see them in the CSV. So perhaps something like:

		if pkgsize != 0:
			percent_pkg = float(filesize) / pkgsize * 100
		else:
			percent_pkg = 0

		percent_total = float(filesize) / total * 100

		wr.writerow([f, pkgname, filesize, pkgsize,
			     "%.1f" % percent_pkg,
			     "%.1f" % percent_total])

Could you test it, and resubmit as a new patch, with your Signed-off-by?

Thanks a lot!

Thomas Petazzoni
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  reply	other threads:[~2017-11-27 21:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-12  2:17 [Buildroot] potential divide by zero in support/scripts/size-stats Andrey Yurovsky
2017-11-27 21:08 ` Thomas Petazzoni [this message]
2017-11-28  3:37   ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
2017-11-28 10:09     ` Yann E. MORIN
2017-11-29 20:36     ` Thomas Petazzoni
2017-12-20 20:52     ` Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171127220849.5f62e6fc@windsurf.home \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox