[FFmpeg-cvslog] r12253 - trunk/libavformat/matroskaenc.c

Aurelien Jacobs aurel
Wed Feb 27 00:11:01 CET 2008


Uoti Urpala wrote:

> On Tue, 2008-02-26 at 23:35 +0100, aurel wrote:
> > Avoid infinite loop.
> > uint64_t >> 64 is an undefined operation
> 
> > -    while (val >> bytes*8) bytes++;
> > +    while (val >> bytes*8 && bytes < 8) bytes++;
> 
> Wouldn't it make more sense to write the tests in the opposite order,
> to avoid invoking undefined behavior?

It's not exactly undefined behavior. It's undefined result for the >>
operation. So either the result is 0 and thus it's what's expected,
either it's non-zero and the bytes<8 will still end the loop.
There is no overall undefined behavior here.

Now, most of the time, the condition which will end the loop is
val >> bytes*8, so better check it first.

Aurel




More information about the ffmpeg-cvslog mailing list