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

Uoti Urpala uoti.urpala
Fri Mar 23 01:50:50 CET 2007


On Fri, 2007-03-23 at 01:14 +0100, Michael Niedermayer wrote:
> On Fri, Mar 23, 2007 at 01:59:22AM +0200, Uoti Urpala wrote:
> > 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.
> 
> multiplication of signed numbers behaves the same on every 
> twos complement architecture which is identical to unsigned multiplication
> 
> its highly unintuitive if it breaks, though iam not arguing against that
> it may be undefined strictly speaking, shift right of signed numbers is
> too and i too would say gcc is broken if (-1)>>1 != -1 on a twos complement
> architecture because it is from a practical POV

Right shift of positive signed numbers is defined by the standard. Right
shift of negative numbers is implementation-defined and gcc defines it
to work by sign extension in
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Integers-implementation.html

Overflow of signed number operations appears to be undefined rather than
implementation-defined. At least I didn't notice anything which would
cover it more specifically than this text from 6.5:
"If an exceptional condition occurs during the evaluation of an
expression (that is, if the result is not mathematically defined or not
in the range of representable values for its type), the behavior is
undefined."






More information about the ffmpeg-cvslog mailing list