~alpine/devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[alpine-devel] [PATCH] abuild: avoid division by zero when calculating human size for packages

Christian Kampka <christian@kampka.net>
Details
Message ID
<1445089798-14998-1-git-send-email-christian@kampka.net>
Sender timestamp
1445089798
DKIM signature
missing
Download raw message
Patch: +6 -3
---
 abuild.in | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/abuild.in b/abuild.in
index 3b6fe04..2642fdf 100644
--- a/abuild.in
+++ b/abuild.in
@@ -1253,8 +1253,12 @@ scan_pkgconfig_depends() {
# read size in bytes from stdin and show as human readable
human_size() {
	awk '{  split("B KB MB GB TB PB", type)
		for(i=5; y < 1; i--)
			y = $1 / (2**(10*i))
		if($1 == 0)
			# avoid division by zero
			y = 0
		else
			for(i=5; y < 1; i--)
				y = $1 / (2**(10*i))
		printf("%.1f %s\n", y, type[i+2]) }'
}

@@ -2209,4 +2213,3 @@ for i in $install_after; do
done

cleanup

-- 
2.6.1



---
Unsubscribe:  alpine-devel+unsubscribe@lists.alpinelinux.org
Help:         alpine-devel+help@lists.alpinelinux.org
---
Natanael Copa <ncopa@alpinelinux.org>
Details
Message ID
<20151028153217.37de3c91@ncopa-desktop.alpinelinux.org>
In-Reply-To
<1445089798-14998-1-git-send-email-christian@kampka.net> (view parent)
Sender timestamp
1446042737
DKIM signature
missing
Download raw message
On Sat, 17 Oct 2015 15:49:58 +0200
Christian Kampka <christian@kampka.net> wrote:

> ---
>  abuild.in | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/abuild.in b/abuild.in
> index 3b6fe04..2642fdf 100644
> --- a/abuild.in
> +++ b/abuild.in
> @@ -1253,8 +1253,12 @@ scan_pkgconfig_depends() {
>  # read size in bytes from stdin and show as human readable
>  human_size() {
>  	awk '{  split("B KB MB GB TB PB", type)
> -		for(i=5; y < 1; i--)
> -			y = $1 / (2**(10*i))
> +		if($1 == 0)
> +			# avoid division by zero
> +			y = 0
> +		else
> +			for(i=5; y < 1; i--)
> +				y = $1 / (2**(10*i))
>  		printf("%.1f %s\n", y, type[i+2]) }'
>  }
>  
> @@ -2209,4 +2213,3 @@ for i in $install_after; do
>  done
>  
>  cleanup
> -

Applied the simplified version as discussed on irc:

@@ -1253,7 +1253,7 @@ scan_pkgconfig_depends() {
 # read size in bytes from stdin and show as human readable
 human_size() {
 	awk '{  split("B KB MB GB TB PB", type)
-		for(i=5; y < 1; i--)
+		for(i=5; y < 1 && $1 > 0; i--)
 			y = $1 / (2**(10*i))
 		printf("%.1f %s\n", y, type[i+2]) }'
 }

Thanks!

-nc



---
Unsubscribe:  alpine-devel+unsubscribe@lists.alpinelinux.org
Help:         alpine-devel+help@lists.alpinelinux.org
---
Reply to thread Export thread (mbox)