[FFmpeg-devel] & vs. &&

Reimar Döffinger Reimar.Doeffinger
Mon Oct 12 16:22:23 CEST 2009


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.



More information about the ffmpeg-devel mailing list