Page 1 of 1

POSSIBLE mistake in SALVO2.2 !

PostPosted: Fri Jul 06, 2001 8:00 am
by luben
Hello,


Looking into your SALVO.H files I accidentally felt on a place that I think is a mistake, or maybe I wrong.

code:


// line 983
#define OSTA_TIMEDOUT 6 /* 110b */


.................


// line 1829

#define OSTimedOut() OScTcbP->u.runStatus.state && OSTA_TIMEDOUT



It's not hard to see that using the OSTimedOut() will return always u.runStatus.state , just because one of the arguments of the function (&&) is always TRUE.

I looked at the old SALVO2.1 SALVO.H and I saw that there is used (==) instead of (&&) - I think this is more meaningful. In fact you're looking for OSTA_TIMEDOUT == 6 (timed out). Using && has different meaning and because one argument in macro is always TRUE, there is no sense to add it into macro at all. I mean, if && is the right logical operation then why in the macro you put argument that is always TRUE.

Or I wrong somewhere?

Luben

[This message has been edited by luben (edited July 06, 2001).]

[This message has been edited by luben (edited July 06, 2001).]


Re: POSSIBLE mistake in SALVO2.2 !

PostPosted: Fri Jul 06, 2001 9:41 am
by Salvo Tech Support
Hi Luben.

You are correct -- it should be "&" instead of "&&". We've added Service Bulletion SB-6 to cover this.

Thanks for pointing this out!

------------------
-----------------------
Salvo Technical Support
Please request all tech support through the Forums.


Re: POSSIBLE mistake in SALVO2.2 !

PostPosted: Sat Jul 07, 2001 11:38 am
by luben
Hello,

I think that second possible error is in the same row - you skip in SALVO2.2 the braces.

code:

#define OSTimedOut() (OScTcbP->u.runStatus.state & OSTA_TIMEDOUT)



should be the correct macro.

Without braces is possible to receive wrong result if operation with higher priority is staying right after the OSTimedOut(). So the "&" operation will be executed after the higher priority operator and the result could be wrong.

I think that in SALVO2.1 everything is OK - there are braces.

Or maybe I wrong somewhere?

Have you a nice weekend

Luben


Re: POSSIBLE mistake in SALVO2.2 !

PostPosted: Sun Jul 08, 2001 8:33 am
by luben
Because after returning from OS_WaitXYZ () are possible only 2 states it is really possible to use & operator, but like:

code:

#define OSTimedOut() (!(OScTcbP->u.runStatus.state & 1))

Note that the result will be with negative value if not used "!". In old SALVO2.1 SALVO.H definitions it don't need "!".

I think that OSTimedOut() has still hidden problems - you know the law of Murphy - the problems are alwayes more then you expect and encountered :-)

Luben


Re: POSSIBLE mistake in SALVO2.2 !

PostPosted: Sun Jul 08, 2001 11:35 am
by luben
Hello,

For sure you have to add curly braces for OSTimedOut() macro.

I'm bringing you an example where the "no braces" variant will fail -

if (!OSTimedOut())..

the ! has higher priority then & and first logical operation NOT will executed. So the macro can return unpredictable result

Regards
Luben


Re: POSSIBLE mistake in SALVO2.2 !

PostPosted: Mon Jul 09, 2001 6:22 am
by luben
Hello,

Other example, when "non curly braces| varian will fail

if (OSTimedOut() ^ 1).....

it's an example when I invert the logical value. Because power has higher priority then other ones - the result will be again wrong.

Take this example like "vote against non curly braces variant"... :-)

Luben