[FFmpeg-devel] [PATCH] ffprobe: Eliminate pointless union in unit_value struct

Stefano Sabatini stefasab at gmail.com
Wed Sep 12 19:45:13 CEST 2012


On date Wednesday 2012-09-12 11:18:46 -0400, Derek Buitenhuis encoded:
> There is no point to this union, as even if it is passed an integer,
> it is immediately put into a double anyway, inside the only function
> that uses it.

The idea was to avoid potentially lossy casts (double->int).

> 
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
>  ffprobe.c |   14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/ffprobe.c b/ffprobe.c
> index 06af4c3..8a1e055 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -89,7 +89,7 @@ void av_noreturn exit_program(int ret)
>  }
>  
>  struct unit_value {
> -    union { double d; long long int i; } val;
> +    double val;
>      const char *unit;
>  };
>  
> @@ -98,12 +98,10 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv)
>      double vald;
>      int show_float = 0;
>  
> -    if (uv.unit == unit_second_str) {
> -        vald = uv.val.d;
> +    if (uv.unit == unit_second_str)
>          show_float = 1;
> -    } else {
> -        vald = uv.val.i;
> -    }
> +
> +    vald = uv.val;

Do you have a specific reason to apply this patch (e.g. get rid of the
union)?

Otherwise I could rework the code in order to avoid the silly
int->int->double path.
-- 
FFmpeg = Fostering and Freak Mystic Puristic Efficient Guide


More information about the ffmpeg-devel mailing list