[Ffmpeg-cvslog] r8474 - trunk/libavcodec/resample2.c

Uoti Urpala uoti.urpala
Fri Mar 23 00:59:22 CET 2007


On Thu, 2007-03-22 at 23:39 +0100, Michael Niedermayer wrote:
> just tried:
> -----
> int test(int a){
>     a*=3;
>     a+=1;
>     a*=-1431655765;
>     a-=-1431655765;
>     return a;
> }
> 
> main(){
>     int i;
> 
>     for(i=0; i<100000000; i++){
>         if(test(i) != i)
>             printf("OPSI %d %d\n", i, test(i));
>     }
> }
> -----
> 
> gcc 4.1.2 missompiles the code causing the printf() to be executed
> 
> every time i test gcc iam more disappointed after the test than before...

I'm not sure whether that's really a miscompilation. At least you're
using implementation-defined behavior; whether it's a bug depends on
whether gcc defines it to work otherwise (I'm not sure whether it does).

The issue is that you're using doing overflowing multiplies with signed
integers. The standard certainly doesn't guarantee anything about such
calculations. If you use unsigned types then the result is guaranteed to
be reduced modulo maximum value of type plus one, and if you change that
to "unsigned int a" then gcc doesn't trigger the printf.





More information about the ffmpeg-cvslog mailing list