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

Michael Niedermayer michaelni
Mon Oct 5 21:18:13 CEST 2009


On Wed, Sep 23, 2009 at 05:27:16PM +0200, Reimar D?ffinger wrote:
> Hello,
> This adds a VALIDATE_INDEX macro that does the typical index validation
> necessary for vorbis all over the place and makes the checks and
> messages for it consistent.
> Michael suggested making the check and the message an argument, but my
> opinion is that these case are so much alike it does not really improve
> things but adds complexity and bloat.
> I even removed the argument for what to do on error to just alway return
> -1.
> This makes things a bit annoying if someone wants to improve the checks
> to e.g. do something more intelligent than aborting, but I don't really
> see that happen and thus consider this approach appropriate.

>  vorbis_dec.c |   79 +++++++++++++++++++----------------------------------------
>  1 file changed, 26 insertions(+), 53 deletions(-)
> edf277854b801c01f13154496738df6084808a5b  vorbisvalid.diff
> Index: libavcodec/vorbis_dec.c
> ===================================================================
> --- libavcodec/vorbis_dec.c	(revision 20001)
> +++ libavcodec/vorbis_dec.c	(working copy)
> @@ -163,6 +163,15 @@
>  #define BARK(x) \
>      (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x))
>  
> +
> +#define VALIDATE_INDEX(idx, limit) \
> +    if (idx >= limit) {\
> +        av_log(vc->avccontext, AV_LOG_ERROR,\
> +               "Index value %d out of range (0 - %d) for %s at %s:%i\n",\
> +               (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
> +        return -1;\
> +    }

get_bits() can be included in the macro

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091005/a8865b2b/attachment.pgp>



More information about the ffmpeg-devel mailing list