[FFmpeg-devel] & vs. &&

Benoit Fouet benoit.fouet
Mon Oct 12 17:22:37 CEST 2009


On 2009-10-12 16:22, Reimar D?ffinger 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.
>   

thanks for the explanation.

So, I have a patch now:
Index: libavformat/aviobuf.c
===================================================================
--- libavformat/aviobuf.c       (revision 20209)
+++ libavformat/aviobuf.c       (working copy)
@@ -590,7 +590,7 @@ int url_setbufsize(ByteIOContext *s, int
 int url_resetbuf(ByteIOContext *s, int flags)
 {
     URLContext *h = s->opaque;
-    if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags &
URL_RDWR))
+    if ((flags & URL_RDWR) || (h && h->flags != flags && !(h->flags &
URL_RDWR)))
         return AVERROR(EINVAL);

     if (flags & URL_WRONLY) {


This is crashing the following command line on my machine (triggered by
make test), can anybody reproduce ?

$ gdb --args ./ffmpeg_g -v 0 -y -flags +bitexact -dct fastint -idct
simple -sws_flags +accurate_rnd+bitexact -t 1 -qscale 10 -f image2
-vcodec pgmyuv -i ./tests/vsynth1/%02d.pgm -f s16le -i
././tests/data/asynth1.sw -acodec mp2
././tests/data/b-lavf.nut                                                                                                                                                        

GNU gdb
6.8-debian                                                                                                                                                                                                               

Copyright (C) 2008 Free Software Foundation,
Inc.                                                                                                                                                                                

License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>                                                                                                                                                    

This is free software: you are free to change and redistribute
it.                                                                                                                                                               

There is NO WARRANTY, to the extent permitted by law.  Type "show
copying"                                                                                                                                                       

and "show warranty" for
details.                                                                                                                                                                                                 

This GDB was configured as
"i486-linux-gnu"...                                                                                                                                                                                   

(gdb)
r                                                                                                                                                                                                                          

Starting program: /home/hack/ffmpeg/ffmpeg_x86/ffmpeg_g -v 0 -y -flags
+bitexact -dct fastint -idct simple -sws_flags +accurate_rnd+bitexact -t
1 -qscale 10 -f image2 -vcodec pgmyuv -i ./tests/vsynth1/%02d.pgm -f
s16le -i ././tests/data/asynth1.sw -acodec mp2
././tests/data/b-lavf.nut                                                                                                                                                                      

[Thread debugging using libthread_db
enabled]                                                                                                                                                                                    

FFmpeg version SVN-r20209, Copyright (c) 2000-2009 Fabrice Bellard, et
al.                                                                                                                                                       

  built on Oct 12 2009 10:34:52 with gcc 4.4.0 20090419 (prerelease)
[gcc-4_4-branch revision
146360]                                                                                                                            

  configuration: --cc=gcc-4.4 --enable-gpl --enable-libx264
--enable-libmp3lame
--enable-pthreads                                                                                                                                

  libavutil     50. 3. 0 / 50. 3.
0                                                                                                                                                                                              

  libavcodec    52.36. 0 / 52.36.
0                                                                                                                                                                                              

  libavformat   52.39. 0 / 52.39.
0                                                                                                                                                                                              

  libavdevice   52. 2. 0 / 52. 2.
0                                                                                                                                                                                              

  libswscale     0. 7. 1 /  0. 7.
1                                                                                                                                                                                              

[image2 @ 0xab27a60]MAX_READ_SIZE:5000000
reached                                                                                                                                                                                

Input #0, image2, from
'./tests/vsynth1/%02d.pgm':                                                                                                                                                                               

  Duration: 00:00:02.00, start: 0.000000, bitrate:
N/A                                                                                                                                                                           

    Stream #0.0: Video: pgmyuv, yuv420p, 352x288, 25 tbr, 25 tbn, 25
tbc                                                                                                                                                         

Input #1, s16le, from
'././tests/data/asynth1.sw':                                                                                                                                                                               

  Duration: N/A, start: 0.000000, bitrate:
N/A                                                                                                                                                                                   

    Stream #1.0: Audio: pcm_s16le, 44100 Hz, 1 channels, s16, 705
kb/s                                                                                                                                                           

[New Thread 0xb7c976c0 (LWP
28036)]                                                                                                                                                                                              


Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7c976c0 (LWP 28036)]       
0xb7d1f8b1 in memcpy () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0  0xb7d1f8b1 in memcpy () from /lib/tls/i686/cmov/libc.so.6
#1  0x0806b177 in put_buffer (s=0x8667ffb, buf=0x861631f "",
size=180027392) at /usr/include/bits/string3.h:52
#2  0x080c4f84 in write_headers (nut=0xab6bef0, bc=<value optimized
out>) at libavformat/nutenc.c:389
#3  0x080c743e in write_header (s=0xab62330) at libavformat/nutenc.c:601
#4  0x080627db in av_write_header (s=0xab62330) at libavformat/utils.c:2548
#5  0x080556ea in av_encode (nb_output_files=1, nb_input_files=<value
optimized out>, nb_stream_maps=<value optimized out>) at ffmpeg.c:2105
#6  0x08055994 in main (argc=29, argv=0xbfbd4584) at ffmpeg.c:3988
(gdb) info registers all
eax            0x3      3
ecx            0x3d514000       1028734976
edx            0xab5e740        179693376
ebx            0xf54a1cdc       -179692324
esp            0xbfbd346c       0xbfbd346c
ebp            0x861631f        0x861631f
esi            0x8667ffb        140935163
edi            0xabb0000        180027392
eip            0xb7d1f8b1       0xb7d1f8b1 <memcpy+97>
eflags         0x10202  [ IF RF ]
cs             0x73     115
ss             0x7b     123
ds             0x7b     123
es             0x7b     123
fs             0x0      0
gs             0x33     51
st0            0        (raw 0x00000000000000000000)
st1            0        (raw 0x00000000000000000000)
st2            0        (raw 0x00000000000000000000)
st3            1        (raw 0x3fff8000000000000000)
st4            0.28999999999999998001598555674718227    (raw
0x3ffd947ae147ae147800)
st5            20       (raw 0x4003a000000000000000)
st6            38.28125 (raw 0x40049920000000000000)
st7            38.28125 (raw 0x40049920000000000000)
fctrl          0x37f    895
fstat          0x20     32
ftag           0xffff   65535
fiseg          0x73     115
fioff          0x80c6da2        135032226
foseg          0x7b     123
fooff          0xbfbd35b8       -1078118984
fop            0x35c    860
xmm0           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm1           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm2           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm3           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm4           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm5           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm6           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
xmm7           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0},
v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
  uint128 = 0x00000000000000000000000000000000}
mxcsr          0x1f80   [ IM DM ZM OM UM PM ]
mm0            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0,
0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}
mm1            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0,
0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}
mm2            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0,
0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}
mm3            {uint64 = 0x8000000000000000, v2_int32 = {0x0,
0x80000000}, v4_int16 = {0x0, 0x0, 0x0, 0x8000}, v8_int8 = {0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x80}}
mm4            {uint64 = 0x947ae147ae147800, v2_int32 = {0xae147800,
0x947ae147}, v4_int16 = {0x7800, 0xae14, 0xe147, 0x947a}, v8_int8 =
{0x0, 0x78, 0x14, 0xae, 0x47, 0xe1, 0x7a, 0x94}}
mm5            {uint64 = 0xa000000000000000, v2_int32 = {0x0,
0xa0000000}, v4_int16 = {0x0, 0x0, 0x0, 0xa000}, v8_int8 = {0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0xa0}}
mm6            {uint64 = 0x9920000000000000, v2_int32 = {0x0,
0x99200000}, v4_int16 = {0x0, 0x0, 0x0, 0x9920}, v8_int8 = {0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x20, 0x99}}
mm7            {uint64 = 0x9920000000000000, v2_int32 = {0x0,
0x99200000}, v4_int16 = {0x0, 0x0, 0x0, 0x9920}, v8_int8 = {0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x20, 0x99}}


Ben



More information about the ffmpeg-devel mailing list