From: Stephen Hemminger <stephen@networkplumber.org>
To: Maks Mishin <maks.mishinfz@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] maketable: Add check for ZERO for variable sigma2
Date: Mon, 8 Jan 2024 09:27:33 -0800 [thread overview]
Message-ID: <20240108092733.5bc8d980@hermes.local> (raw)
In-Reply-To: <20240106211422.33967-1-maks.mishinFZ@gmail.com>
On Sun, 7 Jan 2024 00:14:22 +0300
Maks Mishin <maks.mishinfz@gmail.com> wrote:
> If variable `limit` == 1, then `n` == 1 and then second for-loop will
> not do because of variable `sigma2` maybe ZERO.
> Added check for ZERO for `sigma2` before it is used as denominator.
>
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
> netem/maketable.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/netem/maketable.c b/netem/maketable.c
> index ad8620a4..56b1d0bb 100644
> --- a/netem/maketable.c
> +++ b/netem/maketable.c
> @@ -68,6 +68,10 @@ arraystats(double *x, int limit, double *mu, double *sigma, double *rho)
> sigma2 += ((double)x[i-1] - *mu)*((double)x[i-1] - *mu);
>
> }
> + if (sigma2 == 0) {
> + perror("Division by zero in top/sigma2");
> + exit(3);
> + }
> *rho = top/sigma2;
> }
>
This looks like a purely theoretical not practical problem.
Just tried the tool with input files likely to create the problem (no data, one sample, etc)
and could not reproduce any problem.
What input could make this happen?
prev parent reply other threads:[~2024-01-08 17:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-06 21:14 [PATCH] maketable: Add check for ZERO for variable sigma2 Maks Mishin
2024-01-08 17:27 ` Stephen Hemminger [this message]
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=20240108092733.5bc8d980@hermes.local \
--to=stephen@networkplumber.org \
--cc=maks.mishinfz@gmail.com \
--cc=netdev@vger.kernel.org \
/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.