* [PATCH] maketable: Add check for ZERO for variable sigma2
@ 2024-01-06 21:14 Maks Mishin
2024-01-08 17:27 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Maks Mishin @ 2024-01-06 21:14 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Maks Mishin, netdev
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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] maketable: Add check for ZERO for variable sigma2
2024-01-06 21:14 [PATCH] maketable: Add check for ZERO for variable sigma2 Maks Mishin
@ 2024-01-08 17:27 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-01-08 17:27 UTC (permalink / raw)
To: Maks Mishin; +Cc: netdev
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?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-08 17:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-06 21:14 [PATCH] maketable: Add check for ZERO for variable sigma2 Maks Mishin
2024-01-08 17:27 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).