[Nut-upsdev] [PATCH] Fix logic error in rhino driver
Regid Ichira
regid23 at yahoo.com
Fri Oct 14 22:10:56 UTC 2011
--- On Fri, 10/14/11, Stuart D. Gathman <stuart at bmsi.com>
> range checks are more readable when coded this way:
>
> if( ( 129 < BattVoltage ) && ( BattVoltage < 144 ) )
> result = (int) auton;
> else
> result = 133;
I second this one, but read further.
--- On Fri, 10/14/11, Thomas Jarosch <thomas.jarosch at intra2net.com> wrote:
> The if() statement always evaluated to true.
> Detected by "cppcheck", not tested on real hardware.
>
> - if( ( BattVoltage > 129 ) || ( BattVoltage < 144 ) )
> + if( ( BattVoltage > 129 ) && ( BattVoltage < 144 ) )
I think the current, ||, logic is fine. I can't see in what
circumstances it would yield the wrong decision. Can anyone point a
scenario where I am wrong?
I don't know the cppcheck tool. I wonder weather the modified, &&, case
should not always evaluated to true, just like the original || case.
Assuming the tool is correct, my C is not good enough to say what is the exact
problem. It could be that there is a problem with the types involved.
Leaving aside Stuart, and mine, preferred presentation, can Thomas try
statements like:
if( ( BattVoltage > 129.0 ) || ( BattVoltage < 144.0 ) )
and
if( ( (int)BattVoltage > 129 ) || ( (int)BattVoltage < 144 ) )
More information about the Nut-upsdev
mailing list