Pumpkin, Inc.

Pumpkin User Forums

POSSIBLE mistake in SALVO2.2 !

If you think you've found a bug or other mistake in your Salvo distribution, post it here.

POSSIBLE mistake in SALVO2.2 !

Postby luben » Fri Jul 06, 2001 8:00 am

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).]

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: POSSIBLE mistake in SALVO2.2 !

Postby Salvo Tech Support » Fri Jul 06, 2001 9:41 am

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.

--------
Salvo Technical Support
Please request all tech support through the Forums.
Salvo Tech Support
 
Posts: 173
Joined: Sun Nov 19, 2000 12:00 am

Re: POSSIBLE mistake in SALVO2.2 !

Postby luben » Sat Jul 07, 2001 11:38 am

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

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: POSSIBLE mistake in SALVO2.2 !

Postby luben » Sun Jul 08, 2001 8:33 am

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

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: POSSIBLE mistake in SALVO2.2 !

Postby luben » Sun Jul 08, 2001 11:35 am

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

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria

Re: POSSIBLE mistake in SALVO2.2 !

Postby luben » Mon Jul 09, 2001 6:22 am

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

luben
 
Posts: 324
Joined: Sun Nov 19, 2000 12:00 am
Location: Sofia, Bulgaria


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron