top: try avoiding the edge of a 'divide by zero' cliff

Darn, after testing on some older, out of date distros
I was embarrassed to find some awful code I created in
the commit shown below. I was rewarded with some 'nan'
floating point values and 'inf' computational results.

Reference(s);
. a missed opportunity to repent
commit 5c5bff392b
. true source of my original sin
commit 2d5b51d1a2

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-09-18 00:00:00 -05:00 committed by Craig Small
parent 124f26a423
commit 5f9185e087

View File

@ -6198,8 +6198,9 @@ static struct rx_st *sum_rx (struct graph_parms *these) {
static __thread struct rx_st rx; static __thread struct rx_st rx;
char buf1[SMLBUFSIZ], buf2[SMLBUFSIZ], buf3[MEDBUFSIZ]; char buf1[SMLBUFSIZ], buf2[SMLBUFSIZ], buf3[MEDBUFSIZ];
int ix, num1, num2, width; int ix, num1, num2, width;
float scale; float scale = 0.0;
if (these->total > 0)
scale = 100.0 / these->total; scale = 100.0 / these->total;
rx.pcnt_one = scale * these->part1; rx.pcnt_one = scale * these->part1;
rx.pcnt_two = scale * these->part2; rx.pcnt_two = scale * these->part2;
@ -6207,10 +6208,12 @@ static struct rx_st *sum_rx (struct graph_parms *these) {
rx.pcnt_two = 0; rx.pcnt_two = 0;
rx.pcnt_tot = rx.pcnt_one + rx.pcnt_two; rx.pcnt_tot = rx.pcnt_one + rx.pcnt_two;
num1 = (int)((rx.pcnt_one * these->adjust) + .5), num1 = (int)((rx.pcnt_one * these->adjust) + .5);
num2 = (int)((rx.pcnt_two * these->adjust) + .5); num2 = (int)((rx.pcnt_two * these->adjust) + .5);
if (num1 + num2 > these->length) if (num1 + num2 > these->length) {
if (num1 > these->length) num1 = these->length;
num2 = these->length - num1; num2 = these->length - num1;
}
width = these->length; width = these->length;
buf1[0] = buf2[0] = buf3[0] = '\0'; buf1[0] = buf2[0] = buf3[0] = '\0';