[vlc-devel] [PATCH] do not check unsigned values for negative

Steve Lhomme robux4 at videolabs.io
Tue Apr 4 15:12:49 CEST 2017


vout_intf:
It seems the == should be a && test otherwise we may set a num/den that's 0:0
which is an invalid aspect ratio and won't be used.
---
 modules/access/imem.c           |  2 +-
 src/input/es_out.c              |  8 ++++----
 src/video_output/display.c      | 16 ++++++++--------
 src/video_output/video_output.c |  4 ++--
 src/video_output/vout_intf.c    |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/modules/access/imem.c b/modules/access/imem.c
index 73b0c34ef2..9999c46cb6 100644
--- a/modules/access/imem.c
+++ b/modules/access/imem.c
@@ -432,7 +432,7 @@ static int OpenDemux(vlc_object_t *object)
         fmt.video.i_height = var_InheritInteger(object, "imem-height");
         unsigned num, den;
         if (!var_InheritURational(object, &num, &den, "imem-dar") && num > 0 && den > 0) {
-            if (fmt.video.i_width > 0 && fmt.video.i_height > 0) {
+            if (fmt.video.i_width != 0 && fmt.video.i_height != 0) {
                 fmt.video.i_sar_num = num * fmt.video.i_height;
                 fmt.video.i_sar_den = den * fmt.video.i_width;
             }
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 384c09ae04..39d7beac4e 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -3019,7 +3019,7 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
             info_category_AddInfo( p_cat, _("Channels"), "%s",
                                    _( aout_FormatPrintChannels( &fmt->audio ) ) );
 
-        if( fmt->audio.i_rate > 0 )
+        if( fmt->audio.i_rate != 0 )
         {
             info_category_AddInfo( p_cat, _("Sample rate"), _("%u Hz"),
                                    fmt->audio.i_rate );
@@ -3028,13 +3028,13 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
         }
 
         unsigned int i_bitspersample = fmt->audio.i_bitspersample;
-        if( i_bitspersample <= 0 )
+        if( i_bitspersample == 0 )
             i_bitspersample = aout_BitsPerSample( p_fmt_es->i_codec );
-        if( i_bitspersample > 0 )
+        if( i_bitspersample != 0 )
             info_category_AddInfo( p_cat, _("Bits per sample"), "%u",
                                    i_bitspersample );
 
-        if( fmt->i_bitrate > 0 )
+        if( fmt->i_bitrate != 0 )
         {
             info_category_AddInfo( p_cat, _("Bitrate"), _("%u kb/s"),
                                    fmt->i_bitrate / 1000 );
diff --git a/src/video_output/display.c b/src/video_output/display.c
index 310f208b4c..3a962b524b 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -159,14 +159,14 @@ void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height,
                                         const video_format_t *source,
                                         const vout_display_cfg_t *cfg)
 {
-    if (cfg->display.width > 0 && cfg->display.height > 0) {
+    if (cfg->display.width != 0 && cfg->display.height != 0) {
         *width  = cfg->display.width;
         *height = cfg->display.height;
-    } else if (cfg->display.width > 0) {
+    } else if (cfg->display.width != 0) {
         *width  = cfg->display.width;
         *height = (int64_t)source->i_visible_height * source->i_sar_den * cfg->display.width * cfg->display.sar.num /
             source->i_visible_width / source->i_sar_num / cfg->display.sar.den;
-    } else if (cfg->display.height > 0) {
+    } else if (cfg->display.height != 0) {
         *width  = (int64_t)source->i_visible_width * source->i_sar_num * cfg->display.height * cfg->display.sar.den /
             source->i_visible_height / source->i_sar_den / cfg->display.sar.num;
         *height = cfg->display.height;
@@ -197,7 +197,7 @@ void vout_display_PlacePicture(vout_display_place_t *place,
 {
     /* */
     memset(place, 0, sizeof(*place));
-    if (cfg->display.width <= 0 || cfg->display.height <= 0)
+    if (cfg->display.width == 0 || cfg->display.height == 0)
         return;
 
     /* */
@@ -981,7 +981,7 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             osys->ch_sar  = false;
 
             /* If a crop ratio is requested, recompute the parameters */
-            if (osys->crop.num > 0 && osys->crop.den > 0)
+            if (osys->crop.num != 0 && osys->crop.den != 0)
                 osys->ch_crop = true;
         }
         /* */
@@ -990,7 +990,7 @@ bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 
             unsigned crop_num = osys->crop.num;
             unsigned crop_den = osys->crop.den;
-            if (crop_num > 0 && crop_den > 0) {
+            if (crop_num != 0 && crop_den != 0) {
                 video_format_t fmt = osys->source;
                 fmt.i_sar_num = source.i_sar_num;
                 fmt.i_sar_den = source.i_sar_den;
@@ -1148,7 +1148,7 @@ void vout_SetDisplayZoom(vout_display_t *vd, unsigned num, unsigned den)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
-    if (num > 0 && den > 0) {
+    if (num != 0 && den != 0) {
         vlc_ureduce(&num, &den, num, den, 0);
     } else {
         num = 1;
@@ -1191,7 +1191,7 @@ void vout_SetDisplayCrop(vout_display_t *vd,
 
     if (osys->crop.left  != (int)left  || osys->crop.top != (int)top ||
         osys->crop.right != right || osys->crop.bottom != bottom ||
-        (crop_num > 0 && crop_den > 0 &&
+        (crop_num != 0 && crop_den != 0 &&
          (crop_num != osys->crop.num || crop_den != osys->crop.den))) {
 
         osys->crop.left   = left;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 155d6a9e30..11387d151c 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -76,8 +76,8 @@ static void VoutDestructor(vlc_object_t *);
 static int VoutValidateFormat(video_format_t *dst,
                               const video_format_t *src)
 {
-    if (src->i_width <= 0  || src->i_width  > 8192 ||
-        src->i_height <= 0 || src->i_height > 8192)
+    if (src->i_width == 0  || src->i_width  > 8192 ||
+        src->i_height == 0 || src->i_height > 8192)
         return VLC_EGENERIC;
     if (src->i_sar_num <= 0 || src->i_sar_den <= 0)
         return VLC_EGENERIC;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 247c104196..a5ab96240d 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -489,7 +489,7 @@ static int AspectCallback( vlc_object_t *object, char const *cmd,
     unsigned num, den;
 
     if (sscanf(newval.psz_string, "%u:%u", &num, &den) == 2 &&
-        (num > 0) == (den > 0))
+        (num != 0) == (den != 0))
         vout_ControlChangeSampleAspectRatio(vout, num, den);
     else if (*newval.psz_string == '\0')
         vout_ControlChangeSampleAspectRatio(vout, 0, 0);
-- 
2.11.1



More information about the vlc-devel mailing list