avoptions: Check the return value from av_get_number

Message ID 1306089549-97040-1-git-send-email-martin@martin.st
State Committed
Commit 8089b7fa8c5b5a48cc7101daa4be891d0ead5a5e
Headers show

Commit Message

Martin Storsjö May 22, 2011, 6:39 p.m.
This avoids doing a division by zero if the option wasn't found,
or wasn't an option of an appropriate type.
---
 libavutil/opt.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

Comments

Justin Ruggles May 22, 2011, 6:50 p.m. | #1
On 05/22/2011 02:39 PM, Martin Storsjö wrote:

> This avoids doing a division by zero if the option wasn't found,
> or wasn't an option of an appropriate type.
> ---
>  libavutil/opt.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 57e3248..9e06b01 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -290,7 +290,8 @@ double av_get_double(void *obj, const char *name, const AVOption **o_out)
>      double num=1;
>      int den=1;
>  
> -    av_get_number(obj, name, o_out, &num, &den, &intnum);
> +    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
> +        return -1;
>      return num*intnum/den;
>  }
>  
> @@ -300,7 +301,8 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
>      double num=1;
>      int den=1;
>  
> -    av_get_number(obj, name, o_out, &num, &den, &intnum);
> +    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
> +        return (AVRational){-1, 0};
>      if (num == 1.0 && (int)intnum == intnum)
>          return (AVRational){intnum, den};
>      else
> @@ -313,7 +315,8 @@ int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
>      double num=1;
>      int den=1;
>  
> -    av_get_number(obj, name, o_out, &num, &den, &intnum);
> +    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
> +        return -1;
>      return num*intnum/den;
>  }
>  


looks OK.

-Justin

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 57e3248..9e06b01 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -290,7 +290,8 @@  double av_get_double(void *obj, const char *name, const AVOption **o_out)
     double num=1;
     int den=1;
 
-    av_get_number(obj, name, o_out, &num, &den, &intnum);
+    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+        return -1;
     return num*intnum/den;
 }
 
@@ -300,7 +301,8 @@  AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
     double num=1;
     int den=1;
 
-    av_get_number(obj, name, o_out, &num, &den, &intnum);
+    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+        return (AVRational){-1, 0};
     if (num == 1.0 && (int)intnum == intnum)
         return (AVRational){intnum, den};
     else
@@ -313,7 +315,8 @@  int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
     double num=1;
     int den=1;
 
-    av_get_number(obj, name, o_out, &num, &den, &intnum);
+    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
+        return -1;
     return num*intnum/den;
 }