[FFmpeg-devel] [RFC] consistify/simplify/whatever index validation in vorbis_dec

Reimar Döffinger Reimar.Doeffinger
Tue Oct 27 17:32:33 CET 2009


On Tue, Oct 27, 2009 at 05:10:33PM +0100, Michael Niedermayer wrote:
> On Tue, Oct 27, 2009 at 03:49:40PM +0100, Reimar D?ffinger wrote:
> > +static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n";
> > +#define VALIDATE_INDEX(idx, limit) \
> > +    if (idx >= limit) {\
> > +        av_log(vc->avccontext, AV_LOG_ERROR,\
> > +               idx_err_str,\
> > +               (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
> > +        return -1;\
> > +    }
> > +#define GET_VALIDATED_INDEX(idx, bits, limit) \
> > +    {\
> > +        idx = get_bits(gb, bits);\
> > +        VALIDATE_INDEX(idx, limit)\
> > +    }
> 
> > +#define GET_CODEBOOK_INDEX(idx) \
> > +    GET_VALIDATED_INDEX(idx, 8, vc->codebook_count)
> > +
> 
> i think this one just makes the code harder to read (what was 
> GET_CODEBOOK_INDEX, where is that ...)
> 
> except that, iam ok with it

I agree it is at least border-line, though I am not too happy with
GET_VALIDATED_INDEX either.
If there are no better suggestions I'll manually expand the GET_CODEBOOK_INDEX
macro to GET_VALIDATED_INDEX again and apply the result.



More information about the ffmpeg-devel mailing list