[FFmpeg-devel] & vs. &&

John Cox jc
Mon Oct 12 16:43:36 CEST 2009


On Mon, 12 Oct 2009 16:22:23 +0200, you wrote:

>On Mon, Oct 12, 2009 at 02:36:58PM +0100, John Cox wrote:
>> Hi
>> 
>> >Hi,
>> >
>> >I (well, gcc) have (has) seen some weirdness on the use of & vs. && in
>> >our codebase:
>> >
>> >first one:
>> >libavformat/aviobuf.c:593: warning: suggest parentheses around operand
>> >of ?!? or change ?&? to ?&&? or ?!? to ?~?
>> >=========== ><8 ===========
>> >int url_resetbuf(ByteIOContext *s, int flags)
>> >{
>> >    URLContext *h = s->opaque;
>> >    if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags &
>> >URL_RDWR))
>> >        return AVERROR(EINVAL);
>> >=========== 8>< ===========
>> >
>> >I don't understand what the intent of the test is, but am quite sure it
>> >is wrong, !h->flags & URL_RDWR being always false.
>> >I'd naively think the correct way would be to remove the '!', but am not
>> >sure.
>> 
>> I admit to not having read the surrounding code but I'd have thought the intent
>> was:
>> 
>>     if ((flags & URL_RDWR) || (h && h->flags != flags && !(h->flags &
>> URL_RDWR)))
>
>Yes.
>
>> giving:
>> 
>>     if ((flags & URL_RDWR) || (h && h->flags != flags))
>> 
>> as the replacement code
>
>Huh? That would do something different than intended I think. It should
>be possible to reset/reopen a read-write file both as read-only and as
>write-only, which above code wouldn't allow.

You are right - my mistake - for some reason I lost the h-> in front of the
flags in the original line and so thought the right hand bit was redundant. The
line should (of course) be:

     if ((flags & URL_RDWR) || (h && h->flags != flags && !(h->flags &
URL_RDWR)))

Sorry

John Cox



_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel at mplayerhq.hu
>https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel



More information about the ffmpeg-devel mailing list