[FFmpeg-devel] & vs. &&

John Cox jc
Mon Oct 12 15:36:58 CEST 2009


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

giving:

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

as the replacement code

>second one:
>libavcodec/vc1dec.c:2318: warning: suggest parentheses around operand of
>?!? or change ?&? to ?&&? or ?!? to ?~?
>=========== ><8 ===========
>if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
>=========== 8>< ===========
>
>although this is the same functionnaly as '!is_intra[i] && is_coded[i]',
>I find the latter more close to what we really want to test.
>
>I'd suspect the second case should be fixed as suggested (i.e. '&' =>
>'&&'), but would like to hear knowledgeable people for the first one.

I'd agree here

John Cox



More information about the ffmpeg-devel mailing list