[FFmpeg-devel] [PATCH] avoid division by zero in libavformat/dv.c

Reinhard Tartler siretart
Sat Apr 3 16:55:49 CEST 2010


On Sat, Apr 03, 2010 at 15:25:13 (CEST), Michael Niedermayer wrote:

> On Sat, Apr 03, 2010 at 02:05:31PM +0200, Reinhard Tartler wrote:
>> Found by report posted at:
>> http://permalink.gmane.org/gmane.comp.video.ffmpeg.devel/107290
>> 
>> Fixes: http://tranquillity.ath.cx/clang/2010-04-02-1/report-Yx4BnH.html#EndPath
>> 
>> Index: libavformat/dv.c
>> ===================================================================
>> --- libavformat/dv.c	(revision 22580)
>> +++ libavformat/dv.c	(working copy)
>> @@ -122,6 +122,9 @@
>>      size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
>>      half_ch = sys->difseg_size / 2;
>>  
>> +    if (half_ch == 0)
>> +	    return -1;
>
> this change looks wrong and i would appreciate if people would check that
> clangs claims are possible before posting patches
>
> sys should point to one of several constant structs none has a difseg_size
> small enough. Clang seems just to assume that because there is some check
> for half_ch in a loop and that in the first iteration checks for ==0
> its possible to be 0



would it be acceptable to add an assert(half_ch != 0) with that comment here?

This would avoid the warnings of static analyzers and aid developers to
understand the code, I think.

-- 
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4




More information about the ffmpeg-devel mailing list