All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero
Date: Tue, 28 Nov 2017 11:09:59 +0100	[thread overview]
Message-ID: <20171128100959.GD2889@scaer> (raw)
In-Reply-To: <20171128033707.15072-1-yurovsky@gmail.com>

Andrey, Thomas, All,

On 2017-11-27 19:37 -0800, Andrey Yurovsky spake thusly:
> Some packages (ex: skeleton-init-systemd) have a zero size so we cannot
> divide by the package size. In that case make their percent zero
> explicitly and avoid a ZeroDivisionError exception.
> 
> Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>

Acked-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Regards,
Yann E. MORIN.

> ---
>  support/scripts/size-stats | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/support/scripts/size-stats b/support/scripts/size-stats
> index af45000359..3ff2a1ce18 100755
> --- a/support/scripts/size-stats
> +++ b/support/scripts/size-stats
> @@ -178,9 +178,17 @@ def gen_files_csv(filesdict, pkgsizes, outputf):
>                       "File size in system (%)"])
>          for f, (pkgname, filesize) in filesdict.items():
>              pkgsize = pkgsizes[pkgname]
> +
> +            if pkgsize == 0:
> +                percent_pkg = 0
> +            else:
> +                percent_pkg = float(filesize) / pkgsize * 100
> +
> +            percent_total = float(filesize) / total * 100
> +
>              wr.writerow([f, pkgname, filesize, pkgsize,
> -                         "%.1f" % (float(filesize) / pkgsize * 100),
> -                         "%.1f" % (float(filesize) / total * 100)])
> +                         "%.1f" % percent_pkg,
> +                         "%.1f" % percent_total])
>  
>  
>  #
> -- 
> 2.14.3
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  reply	other threads:[~2017-11-28 10:09 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
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 [this message]
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=20171128100959.GD2889@scaer \
    --to=yann.morin.1998@free.fr \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.