[Live-devel] Possible bug

Ross Finlayson finlayson at live555.com
Tue Sep 4 09:56:53 PDT 2012


> In liveMedia/RTSPServer.cpp, on line 1252, there's a multi clause if
> statement that, as formatted, looks like you want it to be evaluated in a
> way that precedence rules say you will get a surprise.
> 
> The line looks like this:
> if (streamingMode == RTP_TCP && rtpChannelId == 0xFF ||
>    streamingMode != RTP_TCP && ourClientConnection->fClientOutputSocket
> != ourClientConnection->fClientInputSocket)  {...}
> 
> It looks like you expect it to be evaluated like this:
> if ((streamingMode == RTP_TCP && rtpChannelId == 0xFF || streamingMode !=
> RTP_TCP) && (ourClientConnection->fClientOutputSocket !=
> ourClientConnection->fClientInputSocket)) {...}
> 
> The compiler will actually give you this:
> if ((streamingMode == RTP_TCP && rtpChannelId == 0xFF) || (streamingMode
> != RTP_TCP && ourClientConnection->fClientOutputSocket !=
> ourClientConnection->fClientInputSocket)) {...}
> 
> because && has slightly higher precedence than ||.

This (the latter interpretation) is actually what I wanted - so the code is not in error.  However, I'll add parentheses to the code, to make the meaning clearer.


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120904/485e806e/attachment.html>


More information about the live-devel mailing list