Commit b972e777 authored by Adriaan de Groot's avatar Adriaan de Groot 💬
Browse files

Avoid (double) divide-by-zero.

On startup, maxValue may be 0 (e.g. for auto-adjusting sensors)
and then we get a divide-by-zero. In practice this hammers the
resulting integer to negative-biggity, but it's still undefined behavior.

Just use 0 instead.

While here, massage the C-style cast as well. Make the whole
ternary expression a double, then cast.
parent 14a7a4bc
......@@ -131,8 +131,8 @@ void BarGraph::paintEvent( QPaintEvent* )
barHeight = h - 2;
for ( uint b = 0; b < bars; b++ ) {
int topVal = (int) ( (float)barHeight / maxValue *
( samples[ b ] - minValue ) );
int topVal = int( (maxValue == 0.0) ? 0.0 :
( (float)barHeight / maxValue * ( samples[ b ] - minValue ) ) );
/* TODO: This widget does not handle negative values properly. */
if ( topVal < 0 )
topVal = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment