diff mbox

[FFmpeg-devel,v2] Fix printing integer option defaults

Message ID MN2PR13MB2752DE3F6B888FC0F32870ADBA8F0@MN2PR13MB2752.namprd13.prod.outlook.com
State Accepted
Commit 667df60b14745d5c43e6da09fa2ec64eed4eab5b
Headers show

Commit Message

Soft Works Sept. 17, 2019, 1:36 a.m. UTC
Integer values should not be printed using format specifier '%g' which leads to inexact display in case of higher values.

Before this patch:
  -trans_color       <int>        .D.V..... color value [...] (default 1.67772e+07)

Afterwards:
  -trans_color       <int>        .D.V..... color value [...] (default 16777215)

Update: Use PRId64 format specifier
Signed-off-by: softworkz <softworkz@hotmail.com>
---
 libavutil/opt.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Sept. 18, 2019, 8:28 p.m. UTC | #1
On Tue, Sep 17, 2019 at 01:36:33AM +0000, Soft Works wrote:
> Integer values should not be printed using format specifier '%g' which leads to inexact display in case of higher values.
> 
> Before this patch:
>   -trans_color       <int>        .D.V..... color value [...] (default 1.67772e+07)
> 
> Afterwards:
>   -trans_color       <int>        .D.V..... color value [...] (default 16777215)
> 
> Update: Use PRId64 format specifier
> Signed-off-by: softworkz <softworkz@hotmail.com>

Is it intended that the Author doesnt contain a name ?

thx

[...]
Soft Works Sept. 18, 2019, 9:01 p.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Michael Niedermayer
> Sent: Wednesday, September 18, 2019 10:28 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH v2] Fix printing integer option defaults
> 
> On Tue, Sep 17, 2019 at 01:36:33AM +0000, Soft Works wrote:
> > Integer values should not be printed using format specifier '%g' which leads
> to inexact display in case of higher values.
> >
> > Before this patch:
> >   -trans_color       <int>        .D.V..... color value [...] (default 1.67772e+07)
> >
> > Afterwards:
> >   -trans_color       <int>        .D.V..... color value [...] (default 16777215)
> >
> > Update: Use PRId64 format specifier
> > Signed-off-by: softworkz <softworkz@hotmail.com>
> 
> Is it intended that the Author doesnt contain a name ?

Yes - I don't care about rights or credits for those tiny contributions. ;-)
Michael Niedermayer Sept. 20, 2019, 9:13 p.m. UTC | #3
On Wed, Sep 18, 2019 at 09:01:37PM +0000, Soft Works wrote:
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Michael Niedermayer
> > Sent: Wednesday, September 18, 2019 10:28 PM
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH v2] Fix printing integer option defaults
> > 
> > On Tue, Sep 17, 2019 at 01:36:33AM +0000, Soft Works wrote:
> > > Integer values should not be printed using format specifier '%g' which leads
> > to inexact display in case of higher values.
> > >
> > > Before this patch:
> > >   -trans_color       <int>        .D.V..... color value [...] (default 1.67772e+07)
> > >
> > > Afterwards:
> > >   -trans_color       <int>        .D.V..... color value [...] (default 16777215)
> > >
> > > Update: Use PRId64 format specifier
> > > Signed-off-by: softworkz <softworkz@hotmail.com>
> > 
> > Is it intended that the Author doesnt contain a name ?
> 
> Yes - I don't care about rights or credits for those tiny contributions. ;-)

ok, will apply

thx

[...]
diff mbox

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 93d6c26c11..5a35109f39 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1034,6 +1034,23 @@  int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
     return res & flag->default_val.i64;
 }
 
+static void log_int_value(void *av_log_obj, int level, int64_t i)
+{
+    if (i == INT_MAX) {
+        av_log(av_log_obj, level, "INT_MAX");
+    } else if (i == INT_MIN) {
+        av_log(av_log_obj, level, "INT_MIN");
+    } else if (i == UINT32_MAX) {
+        av_log(av_log_obj, level, "UINT32_MAX");
+    } else if (i == INT64_MAX) {
+        av_log(av_log_obj, level, "I64_MAX");
+    } else if (i == INT64_MIN) {
+        av_log(av_log_obj, level, "I64_MIN");
+    } else {
+        av_log(av_log_obj, level, "%"PRId64, i);
+    }
+}
+
 static void log_value(void *av_log_obj, int level, double d)
 {
     if      (d == INT_MAX) {
@@ -1254,7 +1271,7 @@  static void opt_list(void *obj, void *av_log_obj, const char *unit,
                 if (def_const)
                     av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
                 else
-                    log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
+                    log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
                 break;
             }
             case AV_OPT_TYPE_DOUBLE: